/* Shared console shell. Page-specific layouts are scoped to their entry point. */
:is(#appView, #clientAppView) {
  --console-gutter: clamp(16px, 3.5vw, 60px);
  --console-inset: max(var(--console-gutter), calc((100% - 1560px) / 2));
  --console-ink: #19372e;
  --console-accent: #c3ec83;
  --console-overview-fill: repeating-radial-gradient(ellipse at 110% -20%, transparent 0 29px, #c7f59c0d 30px 31px), #1c4234;
  --bg: #f3f5f2;
  --surface-sunken: #f3f6f2;
  --line: #dce4dd;
  --line-strong: #bccbc0;
  --line-faint: #e9eeea;
  display: block;
  min-height: 100dvh;
  padding: 0;
  background: var(--bg);
  font-family: Inter, "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
}
[data-theme="dark"] :is(#appView, #clientAppView) {
  --bg: #151e1a;
  --surface: #202c26;
  --surface-sunken: #26342d;
  --surface-hover: #2b3c32;
  --line: #37483d;
  --line-strong: #536857;
  --line-faint: #304035;
}
:is(#appView, #clientAppView) > .console-masthead {
  position: sticky;
  inset: 0 auto auto;
  z-index: 32;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  gap: clamp(12px, 2.3vw, 38px);
  width: 100%;
  height: auto;
  min-height: 68px;
  max-height: none;
  padding: 10px var(--console-inset);
  overflow: visible;
  transform: none;
  border: 0;
  background: var(--console-ink);
  color: #f2f6f1;
}
.console-masthead .brand {
  flex: none;
  order: 0;
  margin: 0;
  padding: 0;
  gap: 10px;
  border: 0;
}
:is(#appView, #clientAppView) .console-masthead .brand strong { font-size: 22px; color: white; }
.console-masthead .brand-mark { width: 39px; height: 39px; min-width: 39px; border-radius: 12px; box-shadow: none; }
.console-masthead .brand-mark::after { content: none; }
#consoleNav {
  display: flex;
  flex: 0 1 auto;
  flex-direction: row;
  gap: 4px;
  order: 0;
  margin: 0;
  padding: 0;
  overflow: visible;
}
#consoleNav .nav-group { position: relative; display: block; margin: 0; padding: 0; border: 0; }
#consoleNav > .nav-button, #consoleNav summary, .console-masthead .console-actions > :is(a, button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 8px;
  width: auto;
  min-height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  box-shadow: none;
  color: #e0eae2;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
#consoleNav > .nav-button::before, #consoleNav summary::-webkit-details-marker { display: none; }
#consoleNav summary { list-style: none; }
#consoleNav summary::after {
  content: ""; width: 6px; height: 6px; border: solid currentColor; border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg);
}
#consoleNav details[open] > summary::after { transform: translateY(2px) rotate(225deg); }
#consoleNav details:has(.nav-button:not(.hidden):not([hidden]) .nav-count:not(.hidden)) > summary::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #ffca78;
}
#consoleNav > .nav-button.active, #consoleNav details:has(.nav-button.active) > summary { color: #192e20; background: var(--console-accent); }
#consoleNav > .nav-button:hover, #consoleNav summary:hover, #consoleNav details[open] > summary,
.console-masthead .console-actions > :is(a, button):hover { background: #345749; color: white; }
#consoleNav > .nav-button .nav-icon { color: inherit; opacity: 1; }
.console-actions { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.console-masthead .console-actions > :is(a, button) { margin: 0; border: 1px solid #607b70; }
.console-masthead .console-actions > .ghost-button { border-color: transparent; }
.console-masthead .console-actions > .theme-toggle { width: 38px; min-width: 38px; padding: 0; }
.console-masthead :is(summary, button, a):focus-visible { outline: 2px solid #9cd54e; outline-offset: 2px; }
.console-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 1;
  width: 220px; padding: 7px; max-height: min(65dvh, 420px); overflow-y: auto;
  border: 1px solid var(--line); border-radius: 13px; background: var(--surface);
  box-shadow: 0 12px 30px #122c2229;
}
#consoleNav .console-menu .nav-button {
  display: flex; width: 100%; min-height: 40px; align-items: center;
  padding: 8px 12px; gap: 11px; border: 0; border-radius: 7px; box-shadow: none;
  background: transparent; color: var(--text); text-align: start; font-size: 14px;
}
#consoleNav .console-menu .nav-button:is(:hover, :focus-visible) { background: var(--surface-hover); }
#consoleNav .console-menu .nav-button.active { background: var(--primary-soft); color: var(--primary); }
#consoleNav .console-menu .nav-button::before { display: none; }
#consoleNav .console-menu .nav-icon { color: var(--primary); }

:is(#appView, #clientAppView) > :is(.content, .user-content) { width: 100%; min-width: 0; max-width: none; margin: 0; padding: 0 var(--console-inset) 44px; }
:is(#appView, #clientAppView) :is(.agent-topbar, .client-topbar) {
  position: relative; top: auto; z-index: auto; min-height: 90px; gap: 16px;
  margin: 0; padding: 20px 0; border: 0; background: transparent;
}
#appView #pageTitle { font-size: clamp(23px, 2vw, 32px); line-height: 1.25; letter-spacing: -.03em; scroll-margin-top: 90px; }
#appView #pageTitle:focus { outline: none; }
#appView .agent-topbar > .topbar-actions:not(:has(> :not(.hidden, .tab-context-hidden))) { display: none; }
#appView .topbar-actions :is(button, .link-button) { border-radius: 9px; }
:is(#appView, #clientAppView) .system-announcement-bar {
  margin: 0 0 18px; padding: 11px 16px; align-items: center;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
:is(#appView, #clientAppView) .system-announcement-bar strong { color: var(--primary); }
.console-overview { display: grid; grid-template-columns: minmax(340px, .82fr) minmax(0, 1.28fr); gap: 20px; align-items: stretch; }
#appView #dashboard .stat-section, #appView .dashboard-trend {
  min-width: 0; width: 100%; margin: 0; border: 1px solid var(--line); border-radius: 20px; box-shadow: none;
}
#appView #dashboard .stat-section {
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; gap: 0; padding: 0; overflow: hidden;
  background: var(--console-overview-fill);
}
#overviewTitle { margin: 0; padding: 24px 25px 0; color: #f4f9ee; font-size: 19px; }
#appView #dashboard .dashboard-stat-row { display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; align-items: stretch; gap: 0; }
#appView #dashboard .stat-item {
  min-width: 0; min-height: 0; padding: 20px 8px; gap: 9px; align-items: center; justify-content: center;
  border: 0; border-radius: 0; background: transparent; box-shadow: none; transform: none;
}
#appView .stat-item strong { font-variant-numeric: tabular-nums; line-height: 1.12; letter-spacing: -.04em; overflow-wrap: anywhere; }
#appView .dashboard-stat-row:first-of-type .stat-item > span { color: #d4e4d8; font-size: 14px; }
#appView .dashboard-stat-row:first-of-type .stat-item strong { color: #e6ffbb; font-size: clamp(34px, 3vw, 54px); }
#appView .dashboard-stat-row:last-child { padding: 12px 4px; background: var(--surface); }
#appView .dashboard-stat-row:last-child .stat-item { padding: 10px 4px; }
#appView .dashboard-stat-row:last-child .stat-item + .stat-item { border-left: 1px solid var(--line); }
#appView .dashboard-stat-row:last-child .stat-item span { color: var(--muted); font-size: 13px; }
#appView .dashboard-stat-row:last-child .stat-item strong { color: var(--text); font-size: clamp(21px, 2vw, 31px); }
#appView .dashboard-trend { padding: 22px 24px 14px; }
#appView .dashboard-trend-head h3 { font-size: 20px; }
#appView .dashboard-trend-head > span { padding: 4px 10px; border-radius: 20px; background: var(--surface-sunken); }
#appView .dashboard-trend-summary time { margin-right: auto; }
#appView .dashboard-trend-plot { height: clamp(180px, 24vh, 255px); }
#openFilterSettings {
  width: fit-content;
  margin: 0 0 12px;
  padding-inline: 22px;
  font-size: 16px;
  font-weight: 700;
}
#appView .tab-page:not(#dashboard) {
  min-width: 0; padding: clamp(12px, 1.5vw, 24px); border: 1px solid var(--line);
  border-radius: 18px; background: var(--surface);
}
#appView .tab-page > .panel.table-card, #appView #users > .panel, #appView #projects > .panel.table-card {
  margin: 0; padding: 0; border: 0; box-shadow: none; background: transparent;
}
#appView .tab-page .filter-bar { padding: 12px; border: 0; border-radius: 10px; background: var(--surface-sunken); }
#appView .tab-page .table-wrap { border: 1px solid var(--line); border-radius: 10px; }
#appView .tab-page thead th { padding-block: 12px; background: var(--surface-sunken); color: var(--text-secondary); }
#appView .tab-page tbody td { padding-block: 10px; font-variant-numeric: tabular-nums; }
#appView .tab-page .pagination { padding: 13px 9px 5px; }
#appView .tab-page > .grid-form, #appView #userForm, #appView #templateEditor { border-radius: 12px; }
#appView .report-summary-grid { gap: 0; padding: 12px; border-radius: 14px; background: var(--surface-sunken); }
#appView .report-summary-item { border: 0; border-radius: 0; background: transparent; box-shadow: none; }
#appView .agent-topbar:has(#categoryTopActions:not(.tab-context-hidden):not(.hidden)) {
  position: sticky; top: 68px; z-index: 20; background: var(--bg);
}
#appView .user-status-filter { flex-wrap: wrap; overflow: visible; background: transparent; border-bottom: 1px solid var(--line); border-radius: 0; padding: 0 0 12px; }
#appView .user-status-filter .status-filter {
  border: 0; border-radius: 6px; background: transparent; color: var(--muted); box-shadow: none;
}
#appView .user-status-filter .status-filter.active { background: var(--primary-soft); color: var(--primary); }
#appView #userListSearch { width: min(290px, 100%); }
.console-date { display: grid; gap: 4px; min-width: 0; }
.console-date > span { color: var(--muted); font-size: 12px; }
#appView .console-date > input { width: 100%; min-width: 0; }

@media (min-width: 1140px) {
  :is(#appView, #clientAppView) .console-query-page {
    display: grid; grid-template-columns: 200px minmax(0, 1fr); align-items: start; gap: 0 20px;
  }
  #appView :is(#report, #records, #userbill) { grid-template-columns: 250px minmax(0, 1fr); }
  :is(#appView, #clientAppView) .console-query-page > :is(.report-hero, .page-header) { grid-column: 1 / -1; }
  :is(#appView, #clientAppView) .console-query-page > .filter-bar {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-column: 1;
    align-content: start; gap: 9px; margin: 0; padding: 13px;
  }
  :is(#appView, #clientAppView) .console-query-page > .filter-bar > :is(input, select, div, .console-date, #billExportBtn, #recordExportBtn) {
    grid-column: 1 / -1; width: 100%; min-width: 0; margin: 0;
  }
  :is(#appView, #clientAppView) .console-query-page > .filter-bar > .filter-inline-actions { justify-content: center; }
  :is(#appView, #clientAppView) .console-query-page > .table-card { min-width: 0; grid-column: 2; }
}

@media (max-width: 940px) {
  .console-overview { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  #appView .dashboard-stat-row:first-of-type { min-height: 108px; }
}
@media (max-width: 1120px) {
  :is(#appView, #clientAppView) > .console-masthead { flex-wrap: wrap; gap: 6px 12px; min-height: 58px; padding-block: 8px; }
  :is(#appView, #clientAppView) .console-masthead .brand { order: 0; flex: none; }
  :is(#appView, #clientAppView) .console-masthead .brand-mark { width: 34px; height: 34px; min-width: 34px; }
  #consoleNav { flex: 1 1 100%; order: 3; flex-wrap: wrap; gap: 2px; }
  .console-masthead .console-actions > :is(a, button) { padding-inline: 8px; }
  .console-masthead .console-actions > .theme-toggle { padding: 0; }
  #appView .agent-topbar:has(#categoryTopActions:not(.tab-context-hidden):not(.hidden)) { position: static; }
}
@media (max-width: 760px) {
  #consoleNav > .nav-button, #consoleNav summary { min-height: 42px; padding-inline: 8px; font-size: 13px; }
  #consoleNav > .nav-button .nav-icon { display: none; }
  #consoleNav .nav-group { position: static; }
  .console-menu { top: 100%; inset-inline: var(--console-gutter); width: auto; }
  :is(#appView, #clientAppView) :is(.agent-topbar, .client-topbar) { flex-wrap: wrap; min-height: 70px; gap: 8px; padding-block: 14px; }
  #appView .agent-topbar .topbar-actions { gap: 6px; flex-wrap: wrap; }
  #overviewTitle { padding: 18px 18px 0; }
  #appView .dashboard-trend { padding: 16px 12px 8px; }
  #appView .tab-page .filter-bar { gap: 7px; padding: 9px; }
  #appView .tab-page .filter-bar :is(input, select) { min-width: 0; max-width: 100%; }
  :is(#appView, #clientAppView) .console-query-page > .filter-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  :is(#appView, #clientAppView) .console-query-page > .filter-bar > :is(input, select, button) { width: 100%; margin: 0; }
  :is(#appView, #clientAppView) .console-query-page > .filter-bar > :is(input:first-child, div, #billExportBtn, #recordExportBtn) { grid-column: 1 / -1; }
  #appView .console-date:has(input[type="datetime-local"]) { grid-column: 1 / -1; }
  #appView .tab-page .table-wrap { max-width: 100%; overflow-x: auto; }
}

@media (max-width: 420px) {
  :is(#appView, #clientAppView) .console-masthead .brand strong { display: none; }
  .console-actions { gap: 3px; }
  .console-masthead .console-actions > :is(a, button) { padding-inline: 6px; font-size: 13px; }
}

#dataCleanup .cleanup-form { display: grid; justify-items: start; gap: 16px; padding: clamp(16px, 3vw, 28px); margin-bottom: 14px; }
#dataCleanup .cleanup-form.hidden, #dataCleanup label.hidden { display: none; }
#dataCleanup fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
#dataCleanup legend { font-weight: 700; margin-bottom: 10px; }
#dataCleanup .cleanup-options { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 20px; }
#dataCleanup .cleanup-options label:has(input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 6px; }
#dataCleanup input[type="checkbox"] { width: 16px; height: 16px; }
#dataCleanup :is(p, label) { margin: 0; }
#cleanupResult:empty { display: none; }

#usersTable .user-project-preview,
#usersTable .user-project-count {
  font: inherit;
  color: inherit;
}
