/* ==========================================================================
   Hermes Web — styles
   Clean, premium chat aesthetic. Light + dark (system). WCAG 2.2 AA.
   © 2026 Tactuum Ltd
   ========================================================================== */

:root {
  --accent: #005eb8;            /* NHS blue */
  --accent-hover: #004e9a;
  --accent-contrast: #ffffff;   /* white on accent = 5.9:1, passes AA */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #14171c;             /* ~16:1 on surface */
  --text-muted: #565d6b;       /* 5.6:1 on surface — passes AA */
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --user-bubble: #e7f0fb;
  --user-bubble-text: #14171c;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --code-bg: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.10);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 280px;
  --maxw: 760px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #4f9bea;
    --accent-hover: #6fb0f2;
    --accent-contrast: #08111c;
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1c222b;
    --text: #e8ebef;
    --text-muted: #9aa3b0;       /* 5.1:1 on surface */
    --border: #262d37;
    --border-strong: #38414d;
    --user-bubble: #1f3a57;
    --user-bubble-text: #eaf2fb;
    --danger: #f2887f;
    --danger-bg: #2a1614;
    --code-bg: #0b0f15;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over class-level `display`
   rules (e.g. .modal-overlay/.current-user/.empty-state set display, which
   would otherwise override [hidden] and keep the element visible). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* Focus visibility — required (WCAG operable) */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button { font-family: inherit; cursor: pointer; }

/* ============================= Brand mark ============================= */
.brand-mark {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: var(--accent-contrast);
  font-weight: 800; font-size: 22px; letter-spacing: -0.5px;
  box-shadow: var(--shadow-sm);
}
.brand.small .brand-mark { width: 32px; height: 32px; font-size: 16px; border-radius: 9px; }
.brand.large .brand-mark { width: 60px; height: 60px; font-size: 30px; border-radius: 16px; }

/* ================================ LOGIN ============================== */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  grid-template-rows: 1fr auto;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  text-align: center;
  align-self: center;
}
.login-card .brand { display: flex; justify-content: center; margin-bottom: 18px; }
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -0.5px; }
.login-sub { color: var(--text-muted); margin: 4px 0 26px; }

#login-form { text-align: left; }
#login-form label {
  display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px;
}
#login-form .stacked-label { margin-top: 16px; }
#login-form input[type="text"] { padding-right: 14px; }
.password-row { position: relative; display: flex; }
input[type="password"], input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 13px 72px 13px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
input:focus { border-color: var(--accent); }
.ghost-btn {
  background: transparent; border: none; color: var(--accent);
  font-weight: 600; font-size: 14px; padding: 8px 10px; border-radius: 8px;
}
.ghost-btn.full { width: 100%; padding: 11px; border: 1px solid var(--border); color: var(--text); }
.ghost-btn.full:hover { background: var(--surface-2); }
#toggle-password {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 36px;
}
.error {
  color: var(--danger); background: var(--danger-bg);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 14px; margin: 14px 0 0;
}
.primary-btn {
  width: 100%; margin-top: 18px;
  background: var(--accent); color: var(--accent-contrast);
  border: none; border-radius: var(--radius-sm);
  padding: 13px 16px; font-size: 16px; font-weight: 600;
  min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: background 0.18s ease, transform 0.05s ease;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn[disabled] { opacity: 0.7; cursor: not-allowed; }
.login-footer { color: var(--text-muted); font-size: 13px; padding: 16px; }

/* ================================ APP =============================== */
.app { display: flex; height: 100%; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100%;
}
.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 12px;
}
.sidebar-title { font-weight: 700; font-size: 17px; }
.new-chat-btn {
  margin: 4px 14px 12px;
  background: var(--accent); color: var(--accent-contrast);
  border: none; border-radius: var(--radius-sm);
  padding: 11px 14px; font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  min-height: 44px;
  transition: background 0.18s ease;
}
.new-chat-btn:hover { background: var(--accent-hover); }

.skills-btn {
  margin: 0 14px 12px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 14px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  min-height: 42px;
}
.skills-btn:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }

.convo-list-wrap { flex: 1; overflow-y: auto; padding: 6px 10px; }
.convo-heading {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin: 8px 6px; font-weight: 700;
}
.convo-list { list-style: none; margin: 0; padding: 0; }
.convo-list li { margin-bottom: 2px; }

.convo-row {
  position: relative; display: flex; align-items: center;
  border-radius: var(--radius-sm);
}
.convo-row:hover { background: var(--surface-2); }
.convo-item {
  flex: 1; min-width: 0;
  text-align: left; background: transparent; border: none;
  color: var(--text); padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 14px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-height: 40px;
}
.convo-item[aria-current="true"] {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent); font-weight: 600;
}
.convo-row:has(.convo-item[aria-current="true"]) { background: transparent; }

.convo-actions {
  display: flex; gap: 2px; padding-right: 6px;
  opacity: 0; transition: opacity 0.15s ease;
}
/* Reveal actions on hover or when any control inside has focus (keyboard). */
.convo-row:hover .convo-actions,
.convo-row:focus-within .convo-actions { opacity: 1; }
.convo-action {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-muted);
}
.convo-action:hover { background: var(--border); color: var(--text); }
.convo-action.danger:hover { color: var(--danger); background: var(--danger-bg); }

.convo-rename {
  flex: 1; min-width: 0; margin: 4px 6px;
  font: inherit; font-size: 14px; padding: 7px 10px;
  border: 1px solid var(--accent); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.convo-rename:focus { outline: none; }

.convo-confirm {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 10px; font-size: 13px; color: var(--text-muted);
}
.convo-confirm span { flex: 1; }
.confirm-yes, .confirm-no {
  border: none; border-radius: 7px; padding: 5px 10px;
  font-size: 13px; font-weight: 600; min-height: 30px;
}
.confirm-yes { background: var(--danger); color: #fff; }
.confirm-no { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); }
.convo-empty { color: var(--text-muted); font-size: 14px; padding: 6px 10px; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); }
.current-user {
  display: flex; align-items: center; gap: 10px; padding: 4px 4px 12px;
}
.user-avatar {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: var(--accent-contrast); text-transform: uppercase;
}
.user-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icon-btn {
  background: transparent; border: none; color: var(--text);
  font-size: 20px; line-height: 1; padding: 10px; border-radius: 10px;
  min-width: 44px; min-height: 44px;
}
.icon-btn:hover { background: var(--surface-2); }
.mobile-only { display: none; }

/* Chat column */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(8px);
}
.chat-title {
  font-size: 16px; font-weight: 600; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.model-badge {
  font-size: 12px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; font-weight: 600;
}

.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages:focus-visible { outline-offset: -3px; }

.empty-state {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  color: var(--text-muted); gap: 6px; padding: 40px;
}
.empty-state .brand { margin-bottom: 10px; }
.empty-state h2 { color: var(--text); margin: 0; font-size: 24px; }

/* Message rows */
.msg {
  max-width: var(--maxw);
  margin: 0 auto; padding: 18px 24px;
  display: flex; gap: 14px; align-items: flex-start;
}
.msg .avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  margin-top: 2px;
}
.msg.user .avatar { background: var(--surface-2); color: var(--text-muted); }
.msg.assistant .avatar {
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: var(--accent-contrast);
}
.msg .body { min-width: 0; flex: 1; }
.msg .role { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.msg.user .body .bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  padding: 10px 14px; border-radius: 12px; display: inline-block;
  white-space: pre-wrap; word-wrap: break-word;
}
.content { word-wrap: break-word; overflow-wrap: anywhere; }
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }
.content p { margin: 0 0 12px; }
.content h1, .content h2, .content h3 { margin: 18px 0 8px; line-height: 1.3; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 24px; }
.content li { margin: 3px 0; }
.content a { color: var(--accent); text-underline-offset: 2px; }
.content code {
  font-family: var(--mono); font-size: 0.9em;
  background: var(--code-bg); padding: 2px 5px; border-radius: 5px;
}
.content pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; overflow-x: auto;
  margin: 0 0 12px;
}
.content pre code { background: none; padding: 0; font-size: 0.86em; }
.content blockquote {
  border-left: 3px solid var(--border-strong); margin: 0 0 12px;
  padding-left: 14px; color: var(--text-muted);
}

/* Tool activity chip */
.tool-activity {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; margin: 4px 0 10px;
}
.tool-activity .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

/* Typing caret while streaming */
.caret {
  display: inline-block; width: 8px; height: 1.05em; vertical-align: -2px;
  background: var(--accent); margin-left: 2px; border-radius: 1px;
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent-contrast) 40%, transparent);
  border-top-color: var(--accent-contrast);
  animation: spin 0.7s linear infinite;
}

/* Quick actions */
.quick-actions {
  max-width: var(--maxw); margin: 0 auto 8px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.quick-actions:empty { display: none; }
.quick-action-chip {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; font-weight: 600;
  min-height: 36px; display: inline-flex; align-items: center; gap: 6px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.quick-action-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }

/* Composer */
.composer { padding: 8px 16px 18px; }
.composer-inner {
  max-width: var(--maxw); margin: 0 auto;
  position: relative; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 18px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease;
}
.composer-inner:focus-within { border-color: var(--accent); }
#prompt {
  flex: 1; border: none; background: transparent; color: var(--text);
  font: inherit; resize: none; max-height: 200px; padding: 9px 0; line-height: 1.5;
}
#prompt:focus { outline: none; }
.send-btn, .stop-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px;
  border: none; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast);
  transition: background 0.18s ease, opacity 0.18s ease;
}
.send-btn:hover:not([disabled]) { background: var(--accent-hover); }
.send-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.stop-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); }
.stop-square { width: 12px; height: 12px; background: currentColor; border-radius: 3px; }
.composer-hint {
  max-width: var(--maxw); margin: 8px auto 0; text-align: center;
  font-size: 12px; color: var(--text-muted);
}

.scrim {
  position: fixed; inset: 0; background: rgba(8, 12, 18, 0.5);
  z-index: 40; border: none;
}

/* Modal (Skills & tools) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 12, 18, 0.55);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 620px; max-height: 82vh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-tabs { display: flex; gap: 4px; padding: 10px 14px 0; }
.modal-tab {
  background: transparent; border: none; color: var(--text-muted);
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-radius: 8px 8px 0 0; min-height: 40px;
  border-bottom: 2px solid transparent;
}
.modal-tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.modal-tab:hover { background: var(--surface-2); }
.modal-body { overflow-y: auto; padding: 14px 18px 18px; }
.modal-muted { color: var(--text-muted); font-size: 14px; }
.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card-list li {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--surface);
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 14px; margin: 0 0 3px;
}
.card-desc { color: var(--text-muted); font-size: 13px; margin: 0; }
.card-tools { color: var(--text-muted); font-size: 12px; margin: 6px 0 0; font-family: var(--mono); }
.badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge.off { background: var(--surface-2); color: var(--text-muted); }

/* ============================= Responsive ============================ */
@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform 0.25s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .msg { padding: 16px; }
  :root { --maxw: 100%; }
}

/* ========================= Reduced motion =========================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .caret { animation: none; opacity: 1; }
}
