:root {
  --ink: #182026;
  --muted: #60707c;
  --line: #d8e0e5;
  --surface: #ffffff;
  --soft: #f4f7f8;
  --sidebar: #edf2f3;
  --primary: #006d77;
  --primary-hover: #005962;
  --danger: #b42318;
  --user-message: #dff2f0;
  --assistant-message: #f3f5f6;
  --shadow: 0 12px 30px rgba(23, 38, 46, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.65; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e8f0f1;
}

.login-panel {
  width: min(100%, 400px);
  padding: 36px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.wordmark { color: var(--primary); font-weight: 750; letter-spacing: 0; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 24px; margin: 28px 0 20px; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 16px; margin-bottom: 14px; }

.form-stack, .create-user-form { display: grid; gap: 14px; }
label, .models-fieldset { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, textarea, select {
  width: 100%;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #b9c6cc;
  border-radius: 5px;
}
textarea { resize: vertical; min-height: 76px; max-height: 260px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid #5daab0; outline-offset: 1px; border-color: var(--primary); }

.button {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
}
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.quiet { color: #31434d; background: transparent; border-color: #bdcbd0; }
.button.quiet:hover { background: #e1e9ea; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #26434a;
  background: transparent;
  border: 1px solid #b8c7cc;
  border-radius: 5px;
  font-size: 22px;
  line-height: 1;
}
.icon-button:hover { background: #dfe9eb; }
.form-error { min-height: 18px; margin: -3px 0 0; color: var(--danger); font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; min-height: 0; padding: 16px; background: var(--sidebar); border-right: 1px solid var(--line); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 2px 16px; }
.conversation-list { flex: 1; min-height: 80px; overflow-y: auto; }
.conversation-item {
  display: block;
  width: 100%;
  padding: 10px;
  color: #2a3940;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-item:hover { background: #e0e9ea; }
.conversation-item.active { color: #043c43; background: #d1e7e5; border-color: #a4d1ce; font-weight: 650; }
.account-panel { display: grid; gap: 9px; padding: 14px 2px 2px; border-top: 1px solid #cbd7da; }
.account-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.quota-summary { color: var(--muted); font-size: 12px; line-height: 1.5; }
.account-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.account-actions .button { padding: 6px 8px; min-height: 31px; font-size: 12px; }

.chat-pane { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-width: 0; min-height: 100vh; background: var(--surface); }
.chat-header { display: flex; align-items: center; gap: 16px; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.conversation-title { flex: 1; min-width: 0; padding: 5px 0; border: 0; border-radius: 0; font-weight: 700; font-size: 17px; }
.conversation-title:focus { border-bottom: 2px solid var(--primary); outline: 0; }
.model-control { width: min(44vw, 260px); }
.model-control span { font-size: 11px; }
.model-control select { padding: 6px 8px; }
.chat-error { margin: 12px 22px 0; padding: 10px; color: #7a1c14; background: #fdecea; border: 1px solid #f5c5c1; border-radius: 5px; font-size: 14px; }
.messages { min-height: 0; overflow-y: auto; padding: 28px clamp(18px, 5vw, 72px); }
.message { display: grid; gap: 5px; max-width: min(760px, 92%); margin-bottom: 20px; }
.message.user { margin-left: auto; }
.message-role { color: var(--muted); font-size: 12px; font-weight: 650; }
.message.user .message-role { text-align: right; }
.message-body { padding: 12px 14px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.62; }
.message.user .message-body { background: var(--user-message); }
.message.assistant .message-body { background: var(--assistant-message); }
.empty-state { display: grid; height: 100%; place-items: center; color: var(--muted); font-size: 14px; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; padding: 14px 22px 20px; border-top: 1px solid var(--line); }
.composer .button { min-width: 76px; }

.dialog { width: min(1100px, calc(100vw - 28px)); max-height: min(780px, calc(100vh - 28px)); padding: 0; color: var(--ink); border: 1px solid #bbc8cd; border-radius: 8px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20, 33, 40, 0.42); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.admin-content { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 0; }
.create-user-form { padding: 20px; overflow-y: auto; background: #f6f8f8; border-right: 1px solid var(--line); }
.models-fieldset { padding: 8px; border: 1px solid #bdc9ce; border-radius: 5px; }
.models-fieldset label { display: flex; align-items: center; gap: 7px; color: var(--ink); }
.models-fieldset input { width: auto; }
.user-table-wrap { overflow: auto; padding: 20px; }
.user-table { width: 100%; min-width: 700px; border-collapse: collapse; font-size: 13px; }
.user-table th, .user-table td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.user-table th { color: var(--muted); font-weight: 650; white-space: nowrap; }
.user-table input, .user-table select { min-width: 70px; padding: 5px; font-size: 12px; }
.user-table .button { min-height: 29px; padding: 5px 7px; font-size: 12px; }
.row-actions { display: flex; gap: 5px; }
.password-dialog { width: min(420px, calc(100vw - 28px)); }
.password-dialog .form-stack { padding: 20px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { min-height: auto; max-height: 180px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-header { padding-bottom: 8px; }
  .conversation-list { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; }
  .conversation-item { width: auto; min-width: 125px; max-width: 190px; }
  .account-panel { display: none; }
  .chat-pane { min-height: 0; }
  .chat-header { padding: 10px 12px; gap: 10px; }
  .model-control { width: 135px; }
  .messages { padding: 18px 12px; }
  .composer { padding: 10px 12px 14px; }
  .admin-content { grid-template-columns: 1fr; }
  .create-user-form { border-right: 0; border-bottom: 1px solid var(--line); }
}
