/* Dark-first UI — electric blue accents, restrained palette */
:root {
  color-scheme: dark;
  --bg-deep: #080b10;
  --bg: #0c1017;
  --surface: #121922;
  --surface-2: #181f2a;
  --border: #1e2836;
  --border-glow: rgba(56, 189, 248, 0.12);
  --text: #e6edf5;
  --muted: #8b9cb3;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.14);
  --accent-strong: #7dd3fc;
  --danger: #f87171;
  --ok: #4ade80;
  --sidebar-w: 15.5rem;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html {
  -webkit-font-smoothing: antialiased;
}

body.app-body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -40%, rgba(56, 189, 248, 0.08), transparent),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 45%);
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}
a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

.app-shell:has(.sidebar) {
  grid-template-columns: var(--sidebar-w) 1fr;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  box-shadow: inset -1px 0 0 var(--border-glow);
}

.sidebar__brand {
  margin-bottom: 1.75rem;
}

.sidebar__logo {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text);
  display: block;
}
.sidebar__logo:hover {
  color: var(--accent-strong);
  text-decoration: none;
}

.sidebar__tag {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.sidebar__link {
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar__link:hover {
  color: var(--text);
  background: var(--accent-dim);
  text-decoration: none;
  border-color: rgba(56, 189, 248, 0.15);
}
.sidebar__link.is-active {
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-color: rgba(56, 189, 248, 0.22);
}

.sidebar__footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar__email {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 0.65rem;
  word-break: break-all;
}

.sidebar__logout .btn-block {
  width: 100%;
}

.app-main {
  min-width: 0;
}

.main-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}

.flash {
  margin: 1rem 1.5rem 0;
  max-width: 1080px;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.flash--ok {
  border-color: color-mix(in srgb, var(--ok) 35%, var(--border));
}
.flash--err {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-head h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.page-sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.row--tight {
  gap: 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 0 var(--border-glow);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}

.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pad-card {
  padding: 1rem 1.15rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 0 0 transparent;
}
.stat-card:hover {
  border-color: rgba(56, 189, 248, 0.28);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.06);
  text-decoration: none;
}

.stat-card--alert {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.layout-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.15rem;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child {
  border-bottom: none;
}

.list-row--link {
  color: inherit;
  transition: background 0.12s;
}
.list-row--link:hover {
  background: var(--accent-dim);
  text-decoration: none;
}

.list-row__title {
  font-weight: 500;
}

.list-row__meta {
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.link-quiet {
  font-size: 0.82rem;
  color: var(--muted);
}
.link-quiet:hover {
  color: var(--accent-strong);
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.48rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn:hover:not(:disabled) {
  border-color: rgba(56, 189, 248, 0.25);
  background: color-mix(in srgb, var(--surface-2) 92%, var(--accent-dim));
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(165deg, #4fc3f7 0%, #0ea5e9 55%, #0284c7 100%);
  border-color: transparent;
  color: #041018;
  font-weight: 600;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.18);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 0 28px rgba(56, 189, 248, 0.28);
  filter: brightness(1.04);
  border-color: transparent;
  color: #041018;
}

.btn-danger {
  border-color: transparent;
  background: color-mix(in srgb, var(--danger) 88%, #000);
  color: #fff;
}

.btn-ghost {
  background: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--accent-dim);
}

.btn-sm {
  padding: 0.28rem 0.55rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.45rem;
  text-align: left;
  vertical-align: top;
}

.pill {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  margin-right: 0.25rem;
}

.pill--quiet {
  border-color: transparent;
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.stack > * + * {
  margin-top: 0.85rem;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.45rem;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* Chat */
.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: min(72vh, 720px);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: color-mix(in srgb, var(--bg) 65%, var(--surface));
}

.chat-bubble {
  max-width: min(92%, 44rem);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.chat-bubble--user {
  align-self: flex-end;
  border-color: rgba(56, 189, 248, 0.22);
  background: color-mix(in srgb, var(--surface) 80%, var(--accent-dim));
}

.chat-bubble--assistant {
  align-self: flex-start;
}

.chat-bubble__meta {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-family: var(--font-mono);
}

.chat-bubble__body {
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-composer {
  border-top: 1px solid var(--border);
  padding: 0.85rem 1rem 1rem;
  background: var(--surface);
}

.chat-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
}

.chat-form textarea {
  flex: 1 1 220px;
  min-height: 72px;
  margin: 0;
  font-family: inherit;
}

.chat-hint {
  margin: 0.55rem 0 0;
  font-size: 0.78rem;
}

.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;
}

.chat-composer--cursor {
  padding: 0;
}

.chat-form--stack {
  flex-direction: column;
  align-items: stretch;
  padding: 0.75rem 1rem 0;
  gap: 0;
}

.chat-form--stack textarea {
  width: 100%;
  min-height: 88px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  resize: vertical;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem 0.65rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.composer-toolbar__left,
.composer-toolbar__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.composer-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem 0.28rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}

.composer-pill__icon {
  font-size: 0.95rem;
  color: var(--accent-strong);
  line-height: 1;
}

.composer-model-wrap {
  margin: 0;
}

.composer-model {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 1.75rem 0.35rem 0.65rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b9cb3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  max-width: 14rem;
}

.composer-model:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.45;
  padding: 0;
}

.composer-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, var(--accent), #0ea5e9);
  color: var(--bg-deep);
  cursor: pointer;
  padding: 0;
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.25);
}

.composer-send:hover:not(:disabled) {
  filter: brightness(1.06);
}

.composer-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: composer-spin 0.7s linear infinite;
}

@keyframes composer-spin {
  to {
    transform: rotate(360deg);
  }
}

.command-shell .command-composer {
  padding: 0.85rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}

.command-composer textarea {
  width: 100%;
  min-height: 88px;
  margin: 0.35rem 0 0.75rem;
  font-family: inherit;
}

.command-hint {
  margin: 0.55rem 0 0;
  font-size: 0.78rem;
}

.command-plan {
  border-top: 1px solid var(--border);
}

.command-json {
  margin: 0 1rem 0.5rem;
  max-height: 280px;
  overflow: auto;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.command-result {
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* Auth */
.auth-wrap {
  max-width: 420px;
  margin: 4rem auto;
}

.auth-wrap .card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--border-glow);
}

.auth-wrap h1 {
  font-size: 1.45rem;
}

/* Pagination */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}
.pagination a,
.pagination span {
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.pagination a:hover {
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--accent-strong);
  text-decoration: none;
}

@media (max-width: 860px) {
  .app-shell:has(.sidebar) {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
  }
  .sidebar__nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1 1 auto;
  }
  .sidebar__footer {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
  }
  .sidebar__logout {
    margin-left: auto;
  }
  .sidebar__logout .btn-block {
    width: auto;
  }
}
