/* dockie SPA - native CSS. Tokens and components are specified in docs/ui-style-guide.md;
   change that guide first when adding a pattern. No hard-coded colours outside :root. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --hover: #f1f5fa;
  --border: #dfe3e8;
  --text: #1f2933;
  --muted: #66707c;
  --link: #1f5fbf;
  --accent: #1e3f75;
  --accent-hover: #17335f;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --focus: #ffd54a;
  --m-get: #1f5fbf;
  --m-post: #1a7f4b;
  --m-put: #9a5b00;
  --m-patch: #7a4bb5;
  --m-delete: #b42318;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-base: 13px;
  --fs-small: 12px;
  --fs-title: 20px;
  --fs-section: 15px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --radius: 4px;
  --topbar-h: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #16222e;
    --surface-alt: #1a2734;
    --hover: #1d2d3d;
    --border: #2a3a4a;
    --text: #e6eef6;
    --muted: #9db0c2;
    --link: #7fb2f0;
    --accent: #3b6bb5;
    --accent-hover: #4a7ac4;
    --danger: #ff8a80;
    --danger-bg: #3a1c1c;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: var(--fs-title); font-weight: 600; margin: 0; }
h2 { font-size: var(--fs-section); font-weight: 600; margin: var(--space-4) 0 var(--space-2); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: var(--fs-small); }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.6; cursor: default; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.loading { padding: var(--space-5); color: var(--muted); }

/* ---- Top bar and tabs ---- */
.topbar {
  background: var(--surface);
  color: var(--text);
  height: var(--topbar-h);
  padding: 0 var(--space-4);
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { display: flex; align-items: center; font-weight: 600; font-size: var(--fs-section); color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); }
.topbar nav { display: flex; }
.tabs { display: flex; align-items: stretch; margin: 0; padding: 0; list-style: none; overflow-x: auto; }
.tabs li { display: flex; }
.tabs a {
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  color: var(--text);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { background: var(--hover); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--surface-alt); border-bottom-color: var(--accent); font-weight: 600; }

/* ---- Layout ---- */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-3) var(--space-2);
  width: 220px;
  flex-shrink: 0;
}
.sidebar .client-name { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-2) var(--space-3); font-weight: 600; }
.sidebar .back { display: block; padding: var(--space-1) var(--space-2) var(--space-3); font-size: var(--fs-small); }
.nav-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-list a { display: block; padding: var(--space-2) var(--space-3); border-radius: var(--radius); color: var(--text); }
.nav-list a:hover { background: var(--hover); text-decoration: none; }
.nav-list a[aria-current="page"] { background: var(--hover); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }

.content { flex: 1; padding: var(--space-4); max-width: 1100px; width: 100%; margin: 0 auto; min-width: 0; }
.content.wide { max-width: none; margin: 0; }
.content.narrow { max-width: 420px; }
.stack { margin-top: var(--space-3); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.pre { font-size: var(--fs-small); white-space: pre-wrap; }
.card > h2:first-child { margin-top: 0; }

.page-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.page-actions { display: flex; gap: var(--space-2); align-items: center; }

/* ---- Cards, lists, notices ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  border: 1px solid var(--border);
}
.cluster { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.list { display: flex; flex-direction: column; gap: var(--space-1); padding: 0; margin: 0; list-style: none; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: inherit;
}
.list-item:hover { background: var(--hover); }
.meta { font-size: var(--fs-small); color: var(--muted); }
.notice { color: var(--muted); font-size: var(--fs-small); }
.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}
.badge { display: inline-block; padding: 1px var(--space-2); border: 1px solid var(--border); border-radius: 999px; font-size: var(--fs-small); background: var(--surface-alt); }
.badge-muted { color: var(--muted); }

/* ---- Buttons ---- */
button, .btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-3);
  min-height: 28px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
button:hover:not(:disabled), .btn:hover { background: var(--hover); text-decoration: none; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.primary, .btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); color: var(--on-accent); border-color: var(--danger); }
.topbar button { min-height: 28px; }

/* ---- Forms ---- */
.form-row { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); }
.form-row label { font-weight: 600; }
.form-row input, .form-row textarea, .form-row select, .search input, .pager select {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.form-row textarea { min-height: 140px; resize: vertical; }
.input-group { display: flex; gap: var(--space-2); align-items: center; }
.input-group input { flex: 1; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ---- Clients list / data tables ---- */
.subtabs { display: flex; gap: var(--space-4); border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); }
.subtabs button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: var(--space-2) var(--space-1); min-height: 0; }
.subtabs button[aria-selected="true"] { border-bottom-color: var(--accent); font-weight: 600; }
.toolbar { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-2); }
.search { flex: 1; }
.search input { width: 100%; }
.az-bar { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: var(--space-2); }
.az-bar button { background: none; border: none; padding: 0 var(--space-1); min-height: 22px; min-width: 18px; justify-content: center; color: var(--link); font-size: var(--fs-small); }
.az-bar button[aria-pressed="true"] { font-weight: 700; color: var(--text); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
.data-table th, .data-table td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table th { background: var(--surface-alt); font-weight: 600; white-space: nowrap; }
.data-table tbody tr:hover { background: var(--hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table button.sort { background: none; border: none; padding: 0; min-height: 0; font-weight: 600; }
.data-table .name-cell { display: flex; align-items: center; gap: var(--space-2); }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; font-size: var(--fs-small); color: var(--muted); }
.pager button { min-width: 26px; justify-content: center; }
.pager button[aria-current="page"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.avatar {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff;
}
.avatar img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.avatar.has-logo { background: var(--surface) !important; border: 1px solid var(--border); }
.avatar-lg { width: 56px; height: 56px; border-radius: var(--radius); font-size: 20px; }
.recents { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-4); }
.recents-section summary { font-size: var(--fs-section); font-weight: 600; cursor: pointer; margin-bottom: var(--space-3); }
.recent-tile { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); width: 84px; color: var(--text); font-size: var(--fs-small); }
.recent-tile span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Admin hub and sidebar ---- */
.nav-group { margin-bottom: var(--space-2); }
.nav-group summary { cursor: pointer; padding: var(--space-1) var(--space-2); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.nav-list .icon { margin-right: var(--space-2); vertical-align: -3px; color: var(--muted); }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.tile { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.tile:hover { background: var(--hover); text-decoration: none; }
.tile .meta { display: block; }
.tile-icon { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; }

.section { max-width: 640px; margin-bottom: var(--space-5); }
.section > h2:first-child { margin-top: 0; }

/* ---- Tables in admin pages ---- */
.nowrap { white-space: nowrap; }
.row-actions { width: 1%; text-align: center; }
.icon-btn { background: none; border: none; color: var(--danger); padding: var(--space-1); min-height: 0; border-radius: var(--radius); }
.icon-btn:hover:not(:disabled) { background: var(--danger-bg); }
fieldset.form-row { border: none; padding: 0; margin: 0 0 var(--space-3); }
fieldset.form-row legend { font-weight: 600; padding: 0; margin-bottom: var(--space-1); }
.code-block { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); overflow-x: auto; margin: var(--space-2) 0; }

/* ---- API documentation ---- */
.section.wide { max-width: 900px; }
.api-tag { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--space-2); }
.api-tag > summary { cursor: pointer; padding: var(--space-3) var(--space-4); font-size: var(--fs-section); font-weight: 600; text-transform: capitalize; }
.api-tag > summary .meta { font-weight: 400; margin-left: var(--space-2); text-transform: none; }
.api-op { border-top: 1px solid var(--border); }
.api-op > summary { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); cursor: pointer; }
.api-op > summary:hover { background: var(--hover); }
.api-path { font-weight: 600; }
.api-summary { color: var(--muted); flex: 1; min-width: 0; }
.api-body { padding: var(--space-2) var(--space-4) var(--space-4); background: var(--surface-alt); border-top: 1px solid var(--border); }
.api-body h3 { font-size: var(--fs-base); margin: var(--space-4) 0 var(--space-2); }
.api-response { margin-bottom: var(--space-2); }
.method { display: inline-block; min-width: 64px; text-align: center; padding: 2px var(--space-2); border-radius: var(--radius); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 0.03em; }
.m-get { background: var(--m-get); } .m-post { background: var(--m-post); } .m-put { background: var(--m-put); }
.m-patch { background: var(--m-patch); } .m-delete { background: var(--m-delete); }
.status { display: inline-block; min-width: 36px; text-align: center; font-weight: 700; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.s-2 { color: var(--m-post); } .s-3 { color: var(--m-get); } .s-4 { color: var(--m-put); } .s-5 { color: var(--m-delete); }
.schema-table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); background: var(--surface); margin: var(--space-2) 0; }
.schema-table th, .schema-table td { text-align: left; padding: var(--space-1) var(--space-2); border: 1px solid var(--border); vertical-align: top; }
.schema-table th { background: var(--surface-alt); }
.schema-table .schema-table { margin: var(--space-1) 0 0; }
.req { color: var(--danger); font-weight: 700; }
fieldset.authorize { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
fieldset.authorize legend { font-weight: 600; padding: 0 var(--space-1); }
.try-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); }
.try-form .form-row label { font-weight: 400; }
.try-form textarea, .try-form input { width: 100%; }
.try-result { margin-top: var(--space-3); }

/* ---- Client pages ---- */
.breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-small); margin-bottom: var(--space-3); color: var(--muted); }
.breadcrumb [aria-current="page"] { color: var(--text); }
.form-page { max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
.form-row .inline { font-weight: 400; display: flex; gap: var(--space-2); align-items: center; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

/* ---- Dialog ---- */
.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: var(--space-4); width: min(420px, 92vw); }
.dialog h2 { margin-top: 0; }
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog .dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-3); }

/* ---- Editor ---- */
.editor-title { width: 100%; font-size: var(--fs-section); font-weight: 600; padding: var(--space-2) var(--space-3); }
.editor-area { width: 100%; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: var(--fs-base); }
.editor-status { font-size: var(--fs-small); color: var(--muted); margin-top: var(--space-1); }
.presence { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: var(--space-1) 0 var(--space-3); }
.presence .pill { background: var(--hover); color: var(--text); border-radius: 999px; padding: 2px var(--space-2); font-size: var(--fs-small); font-weight: 600; }

canvas { display: block; margin: var(--space-2) 0; border: 1px solid var(--border); border-radius: var(--radius); max-width: 100%; height: auto; }

/* ---- Accessibility ---- */
.visually-hidden {
  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: fixed; top: -200px; left: 0;
  background: var(--accent); color: var(--on-accent); padding: var(--space-2) var(--space-3);
  z-index: 200; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { top: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }

@media (max-width: 820px) {
  .form-grid { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .nav-list { flex-direction: row; }
  .nav-list a { white-space: nowrap; }
  .content { padding: var(--space-3); }
  .topbar .user span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
