/* Kallvara console. One stylesheet, built only on /static/kallvara/tokens.css (a byte-identical copy of
   design/kallvara/tokens.css) — no raw colours here. No inline styles or scripts anywhere (CSP default-src 'self').
   Rules: docs UX guideline (PR #10) — one primary action per screen, body text >= 16px, every text pair >= 4.5:1,
   coral only for that one action or accent (coral buttons take ink text), errors in words + an icon. */

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--lh-body);
  color: var(--text-body);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: var(--fw-bold); color: var(--text-strong);
             line-height: var(--lh-snug); letter-spacing: var(--ls-heading); }
p { margin: 0; }
a { color: var(--text-link); }
img { display: block; max-width: 100%; height: auto; }
strong { color: var(--text-strong); font-weight: var(--fw-semibold); }
ul, ol { margin: 0; }
.muted { color: var(--text-muted); }
.icon { flex: none; width: 20px; height: 20px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }

/* ---- Buttons (site pattern) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 48px; padding: 0 var(--space-5);
  font-family: var(--font-body); font-size: var(--text-base); font-weight: var(--fw-semibold); line-height: 1;
  border-radius: var(--radius-pill); border: 1.5px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), border-color var(--dur);
}
.btn-primary { background: var(--signal); color: var(--ink); }
.btn-primary:hover { background: var(--signal-hover); box-shadow: var(--shadow-signal); }
.btn-secondary { background: var(--surface-card); color: var(--text-strong); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--ink); }
.btn-block { width: 100%; }

/* ---- Messages: words + icon, never colour alone ---- */
.msg {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-5);
  border-radius: var(--radius-sm); border-left: 4px solid; color: var(--text-strong);
}
.msg .icon { margin-top: 2px; }
.msg-error { background: var(--surface-subtle); border-color: var(--error); }
.msg-error .icon { color: var(--error); }
.msg-success { background: var(--good-10); border-color: var(--good); }
.msg-success .icon { color: var(--good); }
.msg-info { background: var(--surface-subtle); border-color: var(--border-strong); }
.msg-info .icon { color: var(--text-muted); }
/* A notice with its own Dismiss button (KD-021): the text wraps, the button drops below it on a narrow screen. */
.msg-dismissible { flex-wrap: wrap; align-items: center; }
.msg-dismissible p { flex: 1 1 16rem; min-width: 0; overflow-wrap: anywhere; }
.msg-dismissible form { margin: 0 0 0 auto; }
.btn-small { min-height: 44px; padding: 0 var(--space-4); }

/* ---- Forms ---- */
.form { display: grid; gap: var(--space-4); }
.field { display: grid; gap: var(--space-2); }
.field label { font-weight: var(--fw-semibold); color: var(--text-strong); }
.field input {
  width: 100%; min-height: 48px; padding: var(--space-3) var(--space-4);
  font: inherit; color: var(--text-strong); background: var(--white);
  border: 1px solid var(--text-muted); border-radius: var(--radius-md);
}
.field input:focus { outline: none; border-color: var(--ink); box-shadow: var(--ring); }

/* ---- Sign-in pages ---- */
.auth { margin: 0 auto; padding: var(--space-9) var(--space-4) var(--space-8); }
.auth-logo { height: 28px; width: auto; margin: 0 auto var(--space-7); }
.auth-card {
  background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  max-width: 440px; margin: 0 auto; padding: var(--space-5);
}
.auth-card h1 { font-size: var(--text-h3); margin-bottom: var(--space-2); }
.auth-card .lead { color: var(--text-muted); margin-bottom: var(--space-6); }
.auth-card h1 + .msg { margin-top: var(--space-4); }
.auth-card > p:not(.lead) { margin-bottom: var(--space-4); }
.auth-card > .btn { margin-top: var(--space-2); }
/* Sign-in (KD-026): the invite line sits with the lead (8px), then 24px to the provider buttons. */
.auth-card .lead-with-note { margin-bottom: var(--space-2); }
.auth-card > p.invite-note { margin-bottom: var(--space-5); }
.auth-card .steps { padding-left: var(--space-5); margin-bottom: var(--space-4); }
.auth-card .steps li + li { margin-top: var(--space-1); }
.disclosure { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--border-subtle); }
.disclosure summary {
  display: flex; justify-content: center; align-items: center; min-height: 44px;
  color: var(--text-link); font-weight: var(--fw-semibold);
}
.disclosure summary:hover { text-decoration: underline; }
.disclosure[open] summary { margin-bottom: var(--space-4); }

/* ---- Signed-in shell: left nav + content ---- */
.app { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-6);
  padding: var(--space-6) var(--space-4) var(--space-5);
  background: var(--surface-card); border-right: 1px solid var(--border-subtle);
}
.sidebar-logo { padding: 0 var(--space-3); }
.sidebar-logo img { height: 24px; width: auto; }
.nav-list { list-style: none; padding: 0; display: grid; gap: var(--space-1); }
.nav-link {
  display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 0 var(--space-3);
  border-radius: var(--radius-sm); color: var(--text-body); text-decoration: none;
}
.nav-link .icon { color: var(--text-muted); }
.nav-link:hover { background: var(--surface-page); color: var(--text-strong); }
.nav-link[aria-current="page"] { background: var(--surface-subtle); color: var(--text-strong); font-weight: var(--fw-semibold); }
.nav-link[aria-current="page"] .icon { color: var(--text-strong); }

/* user area: the small footer of the nav (account, organisation, sign out) */
.user { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); display: grid; gap: var(--space-1); }
.user-id { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-3); min-width: 0; }
.avatar {
  flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--ink); color: var(--white); font-weight: var(--fw-semibold);
}
.user-text { display: grid; min-width: 0; line-height: var(--lh-snug); }
.user-text { font-size: var(--text-sm); }
.user-name { color: var(--text-strong); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta { color: var(--text-muted); }
.user form { margin: 0; }
.user-link, .org-switch summary {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 44px; padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: none;
  font: inherit; color: var(--text-body); text-align: left; text-decoration: none; cursor: pointer;
}
.user-link .icon { color: var(--text-muted); }
.user-link:hover, .org-switch summary:hover { background: var(--surface-page); color: var(--text-strong); }
.user-link[aria-current="page"] { background: var(--surface-subtle); color: var(--text-strong); font-weight: var(--fw-semibold); }
.org-switch summary { justify-content: space-between; }
.org-switch[open] summary .icon { transform: rotate(180deg); }
.org-list { display: grid; gap: var(--space-1); padding: var(--space-1) 0 var(--space-2) var(--space-3); }
.org-option {
  min-height: 44px; padding: 0 var(--space-3); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  background: var(--surface-card); font: inherit; color: var(--text-body); text-align: left; cursor: pointer;
}
.org-option:hover { border-color: var(--border-strong); }
.org-option[aria-current="true"] { border-color: var(--ink); color: var(--text-strong); font-weight: var(--fw-semibold); }

.main { padding: var(--space-8) var(--space-9) var(--space-10); max-width: 1040px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-5); margin-bottom: var(--space-7); }
.page-head h1 { font-size: var(--text-h3); }
.eyebrow { color: var(--text-muted); font-size: var(--text-sm); font-weight: var(--fw-semibold); margin-bottom: var(--space-1); }

/* ---- Content blocks ---- */
.panel { background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); }
.panel-pad { padding: var(--space-5) var(--space-6); }
.panel-pad > * + * { margin-top: var(--space-4); }

.empty {
  display: grid; justify-items: center; gap: var(--space-3); text-align: center;
  padding: var(--space-9) var(--space-6);
  background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
}
.empty-icon {
  display: inline-grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--space-2);
  border-radius: 50%; background: var(--surface-subtle); color: var(--text-muted);
}
.empty-icon .icon { width: 26px; height: 26px; }
.empty h2 { font-size: var(--text-h4); }
.empty p { max-width: 46ch; color: var(--text-muted); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle); }
.table th { color: var(--text-muted); font-size: var(--text-sm); font-weight: var(--fw-semibold); padding-block: var(--space-3); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .strong { color: var(--text-strong); font-weight: var(--fw-semibold); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: var(--fw-semibold); white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-good { background: var(--good-10); color: var(--good); }
.badge-amber { background: var(--amber-10); color: var(--amber); }

.note { display: flex; gap: var(--space-3); align-items: flex-start; margin-top: var(--space-5); color: var(--text-muted); }
.note .icon { margin-top: 2px; }

/* Account: Polaris-style settings — what it is on the left, the controls on the right */
.setting { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: var(--space-7); padding-block: var(--space-6); }
.setting + .setting { border-top: 1px solid var(--border-subtle); }
.setting:first-of-type { padding-top: 0; }
.setting-intro h2 { font-size: var(--text-h4); margin-bottom: var(--space-1); }
.setting-intro p { color: var(--text-muted); }
.details { margin: 0; display: grid; gap: var(--space-4); }
.details > div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--space-4); }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; color: var(--text-strong); overflow-wrap: anywhere; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
/* Account > Connections: each row is one link (label + hint + chevron), at least 44px tall (KD-022) */
.link-rows { list-style: none; padding: 0; overflow: hidden; }
.link-rows li + li { border-top: 1px solid var(--border-subtle); }
.link-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  min-height: 44px; padding: var(--space-3) var(--space-5); color: var(--text-strong); text-decoration: none;
}
.link-row:hover { background: var(--surface-page); }
.link-row-text { display: grid; min-width: 0; }
.link-row-label { font-weight: var(--fw-semibold); }
.link-row-hint { color: var(--text-muted); }
.link-row .icon { color: var(--text-muted); }
/* Account > How you sign in: one row per provider (KD-024) */
.methods-current { margin-bottom: var(--space-3); }
.method-rows { list-style: none; padding: 0; }
.method-row { display: grid; gap: var(--space-3); padding: var(--space-4) var(--space-5); }
.method-rows li + li { border-top: 1px solid var(--border-subtle); }
.method-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); }
.method-row form { margin: 0; }

/* ---- Mobile: the nav collapses into a top bar + Menu (no JS: <details>) ---- */
.mobilebar { display: none; }
@media (max-width: 479px) {
  .app { display: block; }
  .sidebar { display: none; }
  .mobilebar {
    position: sticky; top: 0; z-index: 10;
    display: flex; justify-content: space-between; align-items: center; gap: var(--space-4);
    min-height: 64px; padding: 0 var(--container-pad);
    background: var(--surface-card); border-bottom: 1px solid var(--border-subtle);
  }
  .mobilebar-logo img { height: 22px; width: auto; }
  .mobile-menu summary {
    display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-4);
    border: 1.5px solid var(--border-strong); border-radius: var(--radius-pill);
    color: var(--text-strong); font-weight: var(--fw-semibold);
  }
  .mobile-menu-panel {
    position: absolute; left: 0; right: 0; top: 100%;
    display: grid; gap: var(--space-4); padding: var(--space-4) var(--container-pad) var(--space-5);
    background: var(--surface-card); border-bottom: 1px solid var(--border-subtle); box-shadow: var(--shadow-md);
    max-height: calc(100vh - 64px); overflow-y: auto;
  }
  .mobile-menu-panel .user { margin-top: 0; padding-top: 0; border-top: 0; }   /* KD-027: no empty band, one divider */
  .mobile-menu .when-open, .mobile-menu[open] .when-closed { display: none; }
  .mobile-menu[open] .when-open { display: inline; }
  .main { padding: var(--space-6) var(--container-pad) var(--space-9); }
  .page-head { margin-bottom: var(--space-5); }
  .empty { padding: var(--space-8) var(--space-5); }
  .panel-pad { padding: var(--space-5); }
  .setting { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
  .details > div { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .table th, .table td { padding-inline: var(--space-4); }
}
@media (max-width: 479px) {
  .auth { padding-top: var(--space-8); }
  .auth-card { padding: var(--space-4); }
}

/* Provider brand colours (KD-025): the ONE allowed raw-hex exception in this file, as each provider publishes them
   for its light-theme button. Google: https://developers.google.com/identity/branding-guidelines (fill #FFFFFF,
   1px stroke #747775, text #1F1F1F). Microsoft: https://learn.microsoft.com/en-us/entra/identity-platform/
   howto-add-branding-in-apps (background #FFFFFF, 1px border #8C8C8C, text #5E5E5E). Never use them elsewhere. */
:root {
  --provider-google-border: #747775;
  --provider-google-text: #1F1F1F;
  --provider-microsoft-border: #8C8C8C;
  --provider-microsoft-text: #5E5E5E;
}
/* Provider identity assets stay byte-identical to the supplied official files. */
.btn-provider { width: 100%; background: var(--white); color: var(--ink); border: 1px solid var(--text-muted); padding-inline: var(--space-3); white-space: normal; }
.btn-provider:hover { background: var(--surface-page); }
.btn-provider img { flex: none; }
.btn-microsoft { gap: var(--space-3); border-radius: 0; font-family: "Segoe UI", system-ui, sans-serif; font-size: 15px;
                 border-color: var(--provider-microsoft-border); color: var(--provider-microsoft-text); }
.btn-microsoft img { width: 21px; height: 21px; }
.btn-google { gap: 10px; border-radius: var(--space-1); font-family: Roboto, Arial, sans-serif; font-size: 14px; line-height: 20px; font-weight: var(--fw-medium);
              border-color: var(--provider-google-border); color: var(--provider-google-text); }
/* The supplied icon SVG is a 40px button with a 20px G at (10,10).
   View its G at the original size without altering the file or drawing a second border. */
.google-logo { display: block; position: relative; flex: none; width: 20px; height: 20px; overflow: hidden; }
.google-logo img { position: absolute; width: 40px; height: 40px; max-width: none; left: -10px; top: -10px; }
.provider-buttons { gap: var(--space-3); }
.sidebar-logo, .mobilebar-logo { display: flex; align-items: center; min-height: 44px; }
.page-tabs { display: flex; gap: var(--space-5); margin-bottom: var(--space-5); }
/* Page tabs (Agents | Campaigns, KD-023): ink text, no link underline; only the current tab has a 2px ink rule. */
.page-tabs a {
  display: inline-flex; align-items: center; min-height: 44px; color: var(--text-body); text-decoration: none;
  border-bottom: 2px solid transparent;
}
.page-tabs a:hover { color: var(--text-strong); }
.page-tabs a[aria-current="page"] { color: var(--text-strong); font-weight: var(--fw-semibold); border-bottom-color: var(--ink); }
.bottom-tabs, .menu-scrim { display: none; }
@media (min-width: 480px) and (max-width: 899px) {
  .app { grid-template-columns: 200px minmax(0, 1fr); }
  .main { padding: var(--space-5) var(--space-4); }
  .setting { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
}
@media (max-width: 479px) {
  .mobile-menu[open] .menu-scrim { display: block; position: fixed; inset: 64px 0 0; border: 0; background: var(--ink); opacity: .45; width: 100%; cursor: pointer; }
  .mobile-menu-panel { z-index: 1; }
  .bottom-tabs { display: block; position: fixed; inset: auto 0 0; z-index: 9; background: var(--surface-card); border-top: 1px solid var(--border-subtle); padding: var(--space-1) var(--space-1) calc(var(--space-1) + env(safe-area-inset-bottom)); }
  .bottom-tabs .nav-list { display: flex; gap: 0; }
  .bottom-tabs li { flex: 1; min-width: 0; }
  .bottom-tabs .nav-link { display: flex; flex-direction: column; justify-content: center; gap: var(--space-1); padding: var(--space-1); min-height: 48px; font-size: var(--text-sm); }
  .main { padding-bottom: calc(var(--space-10) + env(safe-area-inset-bottom)); }
}
