/* Shonin — single stylesheet, light + dark via prefers-color-scheme. */

:root {
  /* Shonin palette (knowledge/naming/brand.md): #111827 dark, #66E0BE mint, #F9FAFB light.
     Mint on white is too light for text: links and focus use a darker mint (#0E7C66, 5:1). */
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #4b5563;
  --primary: #111827;
  --primary-hover: #1f2937;
  --primary-contrast: #f9fafb;
  --accent: #0e7c66;
  --accent-hover: #0a5f4e;
  --accent-contrast: #ffffff;
  --accent-soft: #e7f8f2;
  --mint: #66e0be;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --danger-border: #f4c7c3;
  --success: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --info-soft: #f3f4f6;
  --info-border: #d1d5db;
  --focus: #0e7c66;
  --user-bubble: #111827;
  --user-bubble-text: #f9fafb;
  --code-bg: #f3f4f6;
  --logo-ring: transparent;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 1px 3px rgba(17, 24, 39, .08);
  --radius: 10px;
  --radius-sm: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1f2937;
    --border: #273244;
    --border-strong: #3b4a60;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --primary: #66e0be;
    --primary-hover: #8ae9ce;
    --primary-contrast: #111827;
    --accent: #66e0be;
    --accent-hover: #8ae9ce;
    --accent-contrast: #111827;
    --accent-soft: #10302a;
    --danger: #ff8a80;
    --danger-soft: #2d1714;
    --danger-border: #5c2b26;
    --success: #6ce9a6;
    --success-soft: #0f2a1d;
    --success-border: #1f5a3b;
    --info-soft: #1f2937;
    --info-border: #3b4a60;
    --focus: #66e0be;
    --user-bubble: #243044;
    --user-bubble-text: #f9fafb;
    --code-bg: #0b1120;
    --logo-ring: #3b4a60;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 1rem; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  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: 1rem; top: -3rem; z-index: 10;
  background: var(--surface); color: var(--text);
  padding: .5rem .75rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.skip-link:focus { top: .75rem; }

/* Header */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: .7rem 1rem;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}

.brand {
  display: inline-flex; align-items: center; gap: .55rem;
  color: var(--text); text-decoration: none; font-weight: 650;
}
.brand:hover { color: var(--text); }
.brand-logo { width: 30px; height: 30px; flex: none; border-radius: 7px; box-shadow: 0 0 0 1px var(--logo-ring); }
/* Wordmark of the horizontal logo: lowercase, bold */
.brand-name { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; text-transform: lowercase; }

.tenant-pill {
  font-size: .8rem; font-weight: 600;
  padding: .15rem .6rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.header-user { margin-left: auto; display: flex; align-items: center; gap: .6rem; min-width: 0; }
.header-user form { margin: 0; }
.header-user-name {
  color: var(--text-muted); font-size: .9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem;
}

/* Main */

.site-main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.site-main:focus { outline: none; }

.centered { display: flex; justify-content: center; align-items: flex-start; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.auth-card { width: 100%; max-width: 420px; margin-top: 2rem; }
.auth-card h1 { font-size: 1.4rem; }
.lead { color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }

/* Forms */

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-weight: 600; font-size: .9rem; }
.field-hint { font-size: .8rem; color: var(--text-muted); }

input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
}
input:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--focus); }
input:disabled, textarea:disabled { opacity: .65; cursor: not-allowed; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; line-height: 1.2;
  padding: .6rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--primary-contrast); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

/* Inline busy indicator for htmx requests (htmx adds .htmx-request on the form). */
.spinner {
  width: 1em; height: 1em; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: none;
}
.htmx-request .spinner, .htmx-request.spinner, .is-busy .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Alerts */

.alert {
  border: 1px solid var(--info-border);
  background: var(--info-soft);
  border-radius: var(--radius-sm);
  padding: .65rem .85rem;
  margin: 1rem 0 0;
  font-size: .9rem;
}
.alert p { margin: 0; }
.alert-error { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.alert-success { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }
.alert a { color: inherit; font-weight: 600; }
.alert:empty { display: none; }

/* Dashboard */

.page-head { margin-bottom: 1.5rem; }
.page-head p { margin: 0; }

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 960px) { .dashboard { grid-template-columns: minmax(0, 1fr); } }

.stack { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.mono { font-family: var(--mono); font-size: .9em; }
.setup-steps { margin: .75rem 0 0; padding-left: 1.2rem; }
.setup-steps > li { margin-bottom: 1rem; }
.setup-steps > li:last-child { margin-bottom: 0; }
.setup-steps p { margin: .25rem 0 .5rem; }
.command { margin: .4rem 0 0; padding: .6rem .75rem; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; font-size: .8rem; }
.command code { font-family: var(--mono); white-space: pre; }
.inline-form { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.inline-form .field { flex: 1 1 12rem; margin: 0; }

.panel { padding: 0; overflow: hidden; }
.panel-head {
  display: flex; align-items: center; gap: .75rem; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; }
.panel-body { padding: 1rem 1.25rem; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th:first-child, table.data td:first-child { padding-left: 1.25rem; }
table.data th:last-child, table.data td:last-child { padding-right: 1.25rem; }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-2); white-space: nowrap; }
/* The account name is the column that wraps; permission set and action stay on one line */
table.data .ps-name { white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
.account-name { font-weight: 600; display: block; }
.account-id { font-family: var(--mono); font-size: .8rem; color: var(--text-muted); }
.ps-name { font-family: var(--mono); font-size: .85rem; }
td.actions { text-align: right; white-space: nowrap; }

.empty-state { padding: 1.5rem 1.25rem; color: var(--text-muted); }
.empty-state p { margin: 0; }

@media (max-width: 560px) {
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { padding: .6rem 0; border-bottom: 1px solid var(--border); }
  table.data tr:last-child { border-bottom: 0; }
  table.data td { border: 0; padding: .2rem 1rem; }
  td.actions { text-align: left; padding-top: .5rem !important; }
}

/* Chat */

.chat { display: flex; flex-direction: column; height: min(78vh, 760px); min-height: 420px; }
.chat-log {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: .9rem;
  overscroll-behavior: contain;
}

.chat-intro { color: var(--text-muted); font-size: .9rem; }
.chat-intro ul { margin: .4rem 0 .75rem; padding-left: 1.2rem; }
.chat-intro li { margin: .15rem 0; }
.suggestions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.suggestion {
  font: inherit; font-size: .82rem; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px; padding: .3rem .75rem;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg-user { align-items: flex-end; }
.msg-assistant { align-items: flex-start; }
.msg-label { font-size: .72rem; font-weight: 600; color: var(--text-muted); margin: 0 .25rem .2rem; }

.bubble {
  padding: .65rem .9rem; border-radius: 14px;
  max-width: min(100%, 46rem);
  /* break-word, not anywhere: long IDs in tables must not be split (tables scroll instead) */
  overflow-wrap: break-word;
}
.msg-user .bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  border-bottom-right-radius: 4px; white-space: pre-wrap;
}
.msg-assistant .bubble {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
  width: 100%;
}
.msg-error .bubble { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }

.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p, .bubble ul, .bubble ol, .bubble pre, .bubble table, .bubble blockquote { margin: 0 0 .7rem; }
.bubble ul, .bubble ol { padding-left: 1.3rem; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-size: 1rem; margin: .8rem 0 .4rem; }
.bubble code { font-family: var(--mono); font-size: .85em; background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }
.bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem .8rem; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; font-size: .82rem; }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: .85rem; }
.bubble th, .bubble td { border: 1px solid var(--border-strong); padding: .35rem .6rem; text-align: left; }
.bubble th { background: var(--surface); }
.bubble blockquote { border-left: 3px solid var(--border-strong); padding-left: .75rem; color: var(--text-muted); }
.bubble a { color: var(--accent); }
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: .8rem 0; }
/* Cells wrap between words; IDs are never split (break-word on .bubble). Long ARNs may break. */
.bubble td code { overflow-wrap: anywhere; }

/* Intermediate steps of the assistant, shown muted above the final answer */
.bubble .steps {
  font-size: .82rem; color: var(--text-muted);
  border-left: 2px solid var(--border-strong);
  padding-left: .7rem; margin-bottom: .8rem;
}
.bubble .steps p { margin: 0 0 .3rem; }

.chat-status {
  display: flex; align-items: center; gap: .5rem;
  min-height: 2rem; padding: .3rem 1.25rem;
  font-size: .85rem; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.chat-status[hidden] { display: none; }
.chat-status .spinner { display: inline-block; color: var(--accent); }

.chat-form { border-top: 1px solid var(--border); padding: .85rem 1.25rem 1rem; }
.chat-form textarea { resize: none; min-height: 2.75rem; max-height: 12rem; line-height: 1.45; }
.chat-form-row { display: flex; gap: .6rem; align-items: flex-end; }
.chat-form-row .field { flex: 1; margin: 0; }
.chat-hint { font-size: .75rem; color: var(--text-muted); margin-top: .35rem; }

.notice { font-size: .8rem; color: var(--text-muted); margin: 0; }

/* Status pages */

.status-code { font-size: .85rem; font-weight: 700; color: var(--accent); letter-spacing: .08em; text-transform: uppercase; margin-bottom: .25rem; }
.account-list { list-style: none; padding: 0; margin: 0 0 1.25rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.account-list li { padding: .55rem .8rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.account-list li:last-child { border-bottom: 0; }

@media (max-width: 560px) {
  .site-main { padding: 1.25rem 1rem 2rem; }
  .card { padding: 1.15rem; }
  .auth-card { margin-top: .5rem; }
  .panel { padding: 0; }
  .header-user-name { display: none; }
  .chat { height: 75vh; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  * { scroll-behavior: auto !important; }
}

/* Stacked cards on the landing page */
.auth-card > .card { margin-top: 1rem; }
.auth-card > .card + .card { margin-top: 1rem; }
.auth-card > p.small { margin-top: 1rem; margin-bottom: 0; }
.alert pre, pre.alert { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); }
