/* Alunga console shell — design tokens shared with registration_page/register.css */
:root {
  color-scheme: dark;
  --ground: #191d20;
  --paper: #f3f2ec;
  --muted: #c3cccb;
  --accent: #c4e2f7;
  --surface: #1d2327;
  --field: #22292e;
  --line: #374148;
  --control: #566069;
  --error: #e8a0a0;
  --success: #a9d6b4;
  --sidebar-width: 204px;
  --topbar-height: 60px;
  --edge: clamp(16px, 3vw, 44px);
  background: var(--ground);
  color: var(--paper);
  font: 1rem / 1.55 "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: #13212a; }

:is(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-height);
  padding-inline: var(--edge);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: inline-flex; align-items: center; min-height: 40px; }
.brand img { display: block; width: 124px; height: auto; }
.workspace-link {
  border-inline-start: 1px solid var(--line);
  padding-inline-start: 14px;
  color: var(--muted);
  font-size: .875rem;
  text-decoration: none;
}
.workspace-link:hover, .quiet-link:hover { color: var(--accent); }

.topbar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  min-width: 0;
}

.topbar-identity { display: grid; gap: 2px; min-width: 0; }

.topbar-user, .topbar-plan {
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--paper);
  font-size: .875rem;
}
.topbar-plan { color: var(--muted); font-size: .75rem; }
.topbar-plan:empty { display: none; }

.role-chip {
  padding: 2px 10px;
  border: 1px solid var(--control);
  border-radius: 999px;
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 8px;
  border: 1px solid var(--control);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.menu-toggle-bar {
  display: block;
  height: 2px;
  background: var(--paper);
  border-radius: 2px;
}

/* ---- layout ---- */
.app-body {
  display: flex;
  min-height: calc(100svh - var(--topbar-height));
}

.sidebar {
  position: sticky;
  top: var(--topbar-height);
  align-self: flex-start;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: calc(100svh - var(--topbar-height));
  padding: 20px 12px 28px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}

.sidebar-overlay {
  position: fixed;
  inset: var(--topbar-height) 0 0 0;
  z-index: 20;
  background: rgba(0, 0, 0, .45);
}

.content {
  flex: 1;
  width: 100%;
  min-width: 0;
  max-width: 1480px;
  padding: 28px var(--edge) 56px;
  margin-inline: auto;
}

/* ---- navigation ---- */
.nav-group { margin-bottom: 18px; }

.nav-group-title {
  margin: 0 10px 6px;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
}

.nav-item {
  display: block;
  padding: 7px 12px;
  border-radius: 7px;
  color: var(--paper);
  font-size: .925rem;
  text-decoration: none;
}

.nav-item:hover { background: var(--field); color: var(--accent); }
.nav-item.active { background: #2b3942; color: var(--accent); font-weight: 650; }

/* ---- headings & cards ---- */
.view-title {
  margin: 0 0 16px;
  font-size: 1.75rem;
  letter-spacing: -.025em;
  line-height: 1.25;
  font-weight: 650;
}

.view-desc {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: .9rem;
}

.card {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.content > .card + .card { margin-top: 16px; }

.card-title {
  margin: 0 0 12px;
  font-size: 1.02rem;
  font-weight: 600;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 14px;
}

.metric-label { color: var(--muted); font-size: .8rem; margin-bottom: 4px; }
.metric-value { margin: 0; font-size: 1.3rem; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-note { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.metric-note:empty { display: none; }

.overview-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 0 16px;
  padding: 12px 0;
  border-block: 1px solid var(--line);
}
.overview-metric { flex: 1 1 145px; min-width: 0; padding: 7px 16px; }
.overview-metric:first-child { padding-inline-start: 0; }
.overview-metric + .overview-metric { border-inline-start: 1px solid var(--line); }
.overview-metric .metric-note { margin-inline-start: 0; }
.overview-metric.emphasis .metric-value { color: var(--accent); }
.overview-budget {
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.overview-budget h2 { margin: 0 0 9px; font-size: .9rem; }
.overview-budget dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 0;
}
.overview-budget dt, .recent-tasks .inline-note { font-size: .8125rem; color: var(--muted); }
.overview-budget dd { margin: 2px 0 0; font-size: .875rem; font-variant-numeric: tabular-nums; }
.overview-work {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, .85fr);
  align-items: start;
  gap: 16px;
}
.overview-work .card { min-width: 0; }
.overview-work .card-title, .section-row .view-title { margin-bottom: 0; }
.compact-select {
  max-width: 100%;
  min-height: 36px;
  padding: 5px 8px;
  background: var(--field);
  border: 1px solid var(--control);
  border-radius: 7px;
  color: var(--paper);
  font: inherit;
  font-size: .8125rem;
}
.quiet-link { color: var(--muted); font-size: .8125rem; text-underline-offset: .25em; }
.recent-tasks { list-style: none; margin: 0; padding: 0; }
.recent-tasks li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-block: 10px;
  border-top: 1px solid var(--line);
}
.recent-tasks strong { display: block; font-size: .9rem; font-weight: 600; }
.recent-tasks .status-badge { flex: none; }
.dashboard-chart { margin-bottom: 14px; }

.section-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.section-row .grow { flex: 1 1 160px; min-width: 120px; }

/* ---- buttons ---- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 18px;
  border: 1px solid var(--control);
  border-radius: 999px;
  background: transparent;
  color: var(--paper);
  font-size: .875rem;
  text-decoration: none;
  cursor: pointer;
}

.button:hover { border-color: var(--accent); color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--ground); }
.button.primary:hover { filter: brightness(1.06); }
.button.danger { border-color: var(--error); color: var(--error); }
.button.danger:hover { border-color: var(--error); color: var(--error); filter: brightness(1.1); }
.button.ghost { min-height: 34px; padding-inline: 12px; }
.button.small { min-height: 30px; padding-inline: 12px; font-size: .8rem; }
.button[disabled] { opacity: .55; cursor: not-allowed; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---- forms ---- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}

.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field label { color: var(--muted); font-size: .82rem; }
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--control);
  border-radius: 7px;
  background: var(--field);
  color: var(--paper);
  font: inherit;
}

.form-field textarea { min-height: 92px; resize: vertical; }
.form-field .hint { color: var(--muted); font-size: .75rem; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.filter-bar .form-field { min-width: 150px; flex: 0 1 210px; }

/* ---- notice ---- */
.message {
  margin: 10px 0 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: .85rem;
}

.message[data-tone="error"] { color: var(--error); }
.message[data-tone="success"] { color: var(--success); }

/* ---- tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
}

.table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  word-break: break-word;
}

.table tr:last-child td { border-bottom: none; }
.table .cell-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.table .cell-mono { font-family: Consolas, "Courier New", monospace; font-size: .8rem; }

.row-detail td {
  background: var(--field);
  color: var(--muted);
  font-size: .82rem;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.pagination .page-info { color: var(--muted); font-size: .82rem; }

.empty-row {
  padding: 26px 12px !important;
  color: var(--muted);
  text-align: center;
}

/* ---- status badges ---- */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border: 1px solid var(--control);
  border-radius: 999px;
  font-size: .76rem;
  white-space: nowrap;
}

.status-badge[data-tone="ok"] { border-color: var(--success); color: var(--success); }
.status-badge[data-tone="warn"] { border-color: var(--accent); color: var(--accent); }
.status-badge[data-tone="error"] { border-color: var(--error); color: var(--error); }
.status-badge[data-tone="neutral"] { color: var(--muted); }

/* ---- tabs ---- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-button {
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--control);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
}

.tab-button[aria-selected="true"] {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ---- dialog ---- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .55);
}

.dialog {
  width: min(560px, 100%);
  max-height: 86svh;
  overflow-y: auto;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.dialog.wide { width: min(820px, 100%); }
.dialog.task-detail { width: min(600px, calc(100% - 32px)); color: var(--paper); }
.task-detail::backdrop { background: rgba(0, 0, 0, .64); }
.task-results:empty { display: none; }
.task-results { margin-top: 20px; }
.task-result-item { display: grid; justify-items: start; gap: 10px; }
.task-result-item img { display: block; max-width: 100%; max-height: 34svh; border-radius: 8px; }

.dialog-title {
  margin: 0 0 16px;
  font-size: 1.12rem;
  font-weight: 650;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---- charts (pure CSS) ---- */
.bar-chart {
  display: grid;
  gap: 10px;
}

.bar-col {
  display: grid;
  grid-template-columns: minmax(56px, 1fr) minmax(64px, 2fr) minmax(44px, auto);
  align-items: center;
  gap: 8px 12px;
}

.bar-fill {
  width: 100%;
  height: 9px;
  appearance: none;
}
.bar-fill::-webkit-meter-bar { background: #2b363e; border: none; height: 9px; }
.bar-fill::-webkit-meter-optimum-value { background: var(--accent); border-radius: 4px; }
.bar-fill::-moz-meter-bar { background: var(--accent); border-radius: 4px; }

.bar-label {
  color: var(--muted);
  font-size: .8125rem;
  overflow-wrap: anywhere;
}

.bar-value { color: var(--paper); font-size: .8125rem; font-variant-numeric: tabular-nums; text-align: right; }
.overview-work .bar-col { grid-template-columns: 3.25rem minmax(0, 1fr) minmax(44px, auto); }

.setup-details { margin-bottom: 20px; }
.setup-details summary { margin-top: 12px; cursor: pointer; }
.setup-details ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0; list-style: none; }
.setup-secret { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.issued-token { margin-block: 14px; }
.issued-token input { display: block; width: 100%; margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--paper); }

/* ---- misc ---- */
.kv-list { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 6px 14px; margin: 0; }
.kv-list dt { color: var(--muted); font-size: .82rem; }
.kv-list dd { margin: 0; font-size: .88rem; word-break: break-all; }

.inline-note { color: var(--muted); font-size: .82rem; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---- responsive: 5 widths per fact N34 ---- */
@media (max-width: 1024px) {
  .overview-work { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .menu-toggle { display: flex; }
  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    z-index: 25;
    width: min(260px, 78vw);
    transform: translateX(-104%);
    transition: transform .18s ease;
    visibility: hidden;
    border-right: 1px solid var(--line);
  }
  .sidebar.open { transform: translateX(0); visibility: visible; }
  .content { padding: 18px 16px 48px; }
  .topbar-user { max-width: 20vw; }
}

@media (max-width: 440px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .brand img { width: 104px; }
  .role-chip { display: none; }
  .workspace-link { display: none; }
  .overview-summary { padding: 0; }
  .overview-metric { flex-basis: 100%; padding: 8px 0; }
  .overview-metric + .overview-metric { border-inline-start: 0; border-top: 1px solid var(--line); }
  .overview-budget dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 14px; }
  .dialog { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

@media (max-width: 320px) {
  .button { padding-inline: 12px; }
  .metric-value { font-size: 1.12rem; }
}
