:root {
  --admin-accent: #0f766e;
  --admin-accent-hover: #0b625d;
  --admin-accent-soft: #e8f2f0;
  --admin-accent-soft-strong: #dcebe8;
  --admin-accent-border: #b8cbc9;
  --admin-accent-text: #0f4f4a;
  --admin-secondary-bg: #ffffff;
  --admin-secondary-hover: #f4f8f7;
  --admin-secondary-border: #cbd7d5;
  --admin-secondary-text: #23413d;
  --admin-control-border: #c8d0d4;
  --admin-control-muted: #424b50;
  --admin-button-height: 40px;
  --admin-font-size: 15px;
  --admin-table-font-size: 14px;
  --admin-page-padding: 28px;
  --admin-content-width: 1800px;
  --frame: #f3f6f6;
  --frame-soft: #f6f9f8;
  --sheet-border: #e4ebe9;
  --row-rule: #edf1f0;
  --ink: #1b2927;
  --secondary-ink: #596864;
  --muted-ink: #606c69;
  --positive-ink: #1e6848;
  --negative-ink: #9b2830;
  --warning-ink: #805611;
  --surface: #fff;
  --nav-hover: #e6efed;
  --nav-active: #e9f1ef;
  --nav-ink: #46524f;
  --nav-active-ink: #173c36;
  --focus-ring: #1b6c80;
  --font-ui: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  --font-id: Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--frame); font-size: var(--admin-font-size); }
html[data-ui-size="compact"] {
  --admin-button-height: 36px;
  --admin-font-size: 14px;
  --admin-table-font-size: 13px;
  --admin-page-padding: 22px;
}
html[data-ui-size="comfortable"] {
  --admin-button-height: 44px;
  --admin-font-size: 16px;
  --admin-table-font-size: 15px;
  --admin-page-padding: 32px;
}
body {
  min-height: 100vh;
  background: var(--frame);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; }
a { color: var(--admin-accent-text); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.admin-layout { min-height: 100vh; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  min-height: 80px;
  align-items: center;
  gap: 28px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--sheet-border);
  background: var(--surface);
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 8px;
  color: inherit;
  text-decoration: none;
}
.app-brand-mark {
  display: grid;
  width: 30px;
  height: 34px;
  place-items: center;
  flex: none;
  color: var(--admin-accent);
  font-size: 25px;
  font-weight: 600;
  line-height: 1;
}
.app-brand-copy { display: grid; gap: 0; min-width: 0; }
.app-brand-copy strong { font-size: 17px; font-weight: 600; line-height: 24px; }
.app-brand-copy small { color: var(--muted-ink); font-size: 13px; line-height: 19px; }
.primary-nav { display: flex; min-width: 0; align-items: center; gap: 4px; flex: 1 1 auto; }
.nav-group { position: relative; }
.nav-group > summary {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 5px;
  color: var(--secondary-ink);
  cursor: pointer;
  font-size: 1.067rem;
  font-weight: 500;
  list-style: none;
  white-space: nowrap;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after { width: 6px; height: 6px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; content: ""; transform: translateY(-2px) rotate(45deg); }
.nav-group[open] > summary, .nav-group > summary:hover { background: var(--nav-hover); color: var(--ink); }
.nav-menu {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: 60;
  display: grid;
  min-width: 208px;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--sheet-border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 12px 26px rgba(20, 38, 34, .10);
}
.nav-menu .topbar-link {
  display: flex;
  min-height: 44px;
  align-items: center;
  padding: 0 10px;
  border-radius: 4px;
  color: var(--nav-ink);
  font-size: 1rem;
  text-decoration: none;
  white-space: nowrap;
}
.nav-menu .topbar-link:hover, .nav-menu .topbar-link.is-active { background: var(--nav-active); color: var(--nav-active-ink); }
.header-user { display: flex; align-items: center; gap: 12px; flex: none; }
.header-user .who { color: var(--secondary-ink); font-size: 13px; white-space: nowrap; }
.header-user form { margin: 0; }
.header-user .logout-button, .header-user .theme-toggle { min-height: var(--admin-button-height); padding: 0 10px; border: 1px solid var(--admin-secondary-border); border-radius: 5px; background: var(--surface); color: var(--admin-secondary-text); font-size: .867rem; font-weight: 500; white-space: nowrap; }
.header-user .logout-button:hover, .header-user .theme-toggle:hover { border-color: var(--admin-accent-border); background: var(--admin-secondary-hover); }
.header-user .theme-toggle[aria-pressed="true"] { border-color: var(--admin-accent); background: var(--admin-accent-soft); color: var(--admin-accent-text); }
.header-preferences { display: flex; align-items: center; gap: 10px; }
.app-main { display: flex; min-height: calc(100vh - 80px); min-width: 0; flex-direction: column; padding-top: 24px; }
.app-main-dashboard { --admin-content-width: 1120px; }
.topbar {
  position: static;
  display: flex;
  width: calc(100% - 48px);
  max-width: var(--admin-content-width);
  min-height: 56px;
  align-items: center;
  gap: 12px;
  margin: 0 auto;
  padding: 8px 2px;
  border: 0;
  background: var(--frame);
  box-shadow: none;
  overflow: visible;
}
.topbar .spacer { flex: 1 1 auto; }
.nav-scrim { display: none; }
.ui-size-control { display: flex; align-items: center; gap: 8px; flex: none; }
.ui-size-control label { display: block; font-size: .867rem; white-space: nowrap; }
.admin-layout .ui-size-control select {
  width: 92px;
  min-height: var(--admin-button-height);
  padding: 4px 8px;
  font-size: .867rem;
  border-color: var(--sheet-border);
  background-color: var(--surface);
}

.global-shop-context {
  min-height: 40px;
  align-content: center;
  padding: 8px 24px;
  border: 0;
  background: var(--frame);
  color: var(--secondary-ink);
  font-size: 13px;
}
.global-shop-context-main { color: #24443e; font-weight: 500; }
.global-shop-context-warning { color: #694d1c; background: #fbf7eb; }
.container {
  flex: 0 0 auto;
  width: calc(100% - 48px);
  max-width: var(--admin-content-width);
  min-width: 0;
  margin: 0 auto 24px;
  padding: var(--admin-page-padding);
  border: 1px solid var(--sheet-border);
  border-radius: 12px;
  background: var(--surface);
}
.page-shell { width: 100%; max-width: none; margin: 0; grid-template-columns: minmax(0, 1fr); }
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin: 0 0 22px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.page-header h1, .login-heading h1, .cockpit-hero-title {
  margin: 0;
  color: var(--ink);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
  text-wrap: pretty;
}
.page-header p, .login-heading p { margin: 8px 0 0; max-width: 70ch; color: var(--secondary-ink); font-size: .933rem; line-height: 1.6; }
.page-kicker, .ops-section-kicker, .shops-section-eyebrow { display: none !important; }
.panel, .ops-shop-card, .ops-summary-card, .shop-overview-row, .login-panel {
  border-color: var(--sheet-border);
  border-radius: 8px;
  box-shadow: none;
}
.panel { min-width: 0; padding: 18px; background: var(--surface); }
.panel + .panel { margin-top: 16px; }
.panel-head { gap: 16px; margin-bottom: 14px; padding-bottom: 12px; border-bottom-color: var(--row-rule); }
.panel-head h3, .ops-section-heading h3, .ops-shop-card h3 { color: var(--ink); font-size: 1.067rem; font-weight: 600; line-height: 1.4; }
.panel-head p, .panel-subtitle { color: var(--secondary-ink); font-size: .933rem; line-height: 1.6; }
.quick-grid { gap: 8px; }
.quick-grid > div, .quick-grid > a {
  border-color: var(--sheet-border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--admin-secondary-text);
  font-weight: 500;
}
.quick-grid > a:hover { border-color: var(--admin-accent-border); background: var(--frame-soft); }
.dashboard-page [data-testid="dashboard-quick-links"] { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.dashboard-page [data-testid="dashboard-quick-links"] > a {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 88px;
  gap: 6px;
  padding: 16px;
}
.dashboard-page [data-testid="dashboard-quick-links"] strong { font-size: 1rem; font-weight: 600; }
.dashboard-page [data-testid="dashboard-quick-links"] span { color: var(--secondary-ink); font-size: .867rem; font-weight: 400; }

button {
  min-height: 32px;
  border-radius: 5px;
  font-weight: 500;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}
button:active:not(:disabled) { transform: none; }
.admin-layout input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="color"]):not([type="file"]),
.admin-layout select, .admin-layout textarea {
  min-height: var(--admin-button-height);
  border-color: var(--admin-control-border);
  border-radius: 5px;
  background-color: var(--surface);
  color: var(--ink);
}
label { color: var(--secondary-ink); font-size: .933rem; font-weight: 500; }
input::placeholder, textarea::placeholder { color: var(--muted-ink); opacity: 1; }
table { margin-bottom: 14px; border-color: var(--row-rule); }
th {
  background: var(--surface) !important;
  color: var(--muted-ink) !important;
  font-size: .867rem !important;
  font-weight: 500 !important;
  text-transform: none !important;
}
td, th { border-color: var(--row-rule) !important; }
td { color: var(--ink); font-size: var(--admin-table-font-size); }
td code, code, .shop-id, [data-copy-text] { font-family: var(--font-id); font-variant-numeric: tabular-nums; }
.status-pill, .badge, [class*="-badge"] { white-space: nowrap; }

.ops-summary-grid { gap: 12px; }
.ops-summary-card { min-height: 86px; padding: 14px 16px; background: var(--surface); }
.ops-summary-card > span, .ops-summary-card small { color: var(--secondary-ink); font-size: 12px; }
.ops-summary-card strong { color: var(--ink); font-size: 26px; font-weight: 500; }
.ops-summary-card-primary { border-color: var(--sheet-border); background: var(--surface); }
.ops-shop-card { padding: 16px; background: var(--surface); }
.ops-shop-card-header, .ops-card-section { border-color: var(--row-rule); }
.ops-stat-grid { gap: 10px 16px; }
.ops-stat-item dt { color: var(--muted-ink); font-size: 12px; }
.ops-stat-item dd { color: var(--ink); font-size: 14px; }
.ops-card-links { gap: 8px; }
.cockpit-command-title-row { align-items: center; flex-wrap: wrap; gap: 12px 20px; }
.cockpit-shop-switcher { display: flex; align-items: center; gap: 8px; margin: 0; margin-left: auto; }
.cockpit-shop-switcher label { color: var(--muted-ink); font-size: 12px; white-space: nowrap; }
.cockpit-shop-switcher select { min-width: 180px; max-width: 280px; }
.cockpit-shop-switcher select,
.cockpit-command-actions button { height: var(--admin-button-height); min-height: var(--admin-button-height); }
.cockpit-shop-loading { color: var(--muted-ink); font-size: 12px; white-space: nowrap; }
.cockpit-reprice-history { padding: 10px 12px; border: 1px solid var(--sheet-border); border-radius: 6px; }
.cockpit-reprice-history > summary { cursor: pointer; color: var(--secondary-ink); font-size: .933rem; }
.cockpit-reprice-history .cockpit-status-strip { margin-top: 10px; color: var(--secondary-ink); background: var(--frame-soft); border-color: var(--sheet-border); }
.admin-layout :is(button, input[type="submit"], input[type="button"], .button-link):not(.nav-scrim) {
  display: inline-flex;
  min-height: var(--admin-button-height);
  height: auto;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding-block: 7px;
  font-size: .933rem;
  line-height: 1.4;
  vertical-align: middle;
}
.admin-layout .app-header button.nav-toggle { display: none; }
.analytics-filter button { align-self: start; }
.admin-layout input[type="checkbox"], .admin-layout input[type="radio"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  flex: none;
  accent-color: var(--admin-accent);
}

.login-layout { min-height: 100vh; background: var(--frame); }
.login-layout .topbar { min-height: 56px; padding: 0 28px; }
.login-layout .app-main { min-height: calc(100vh - 56px); padding-top: 0; }
.login-layout .container { display: grid; min-height: calc(100vh - 64px); place-items: center; margin: 8px; border-radius: 16px; background: var(--surface); }
.login-page { display: grid; place-items: center; }
.login-panel { width: min(100%, 430px); padding: 28px; }
.login-heading { margin-bottom: 22px; }
.login-panel .panel-form { width: 100%; max-width: none; gap: 14px; }
.login-panel .panel-form label { gap: 7px; }
.login-panel .panel-form input { width: 100%; min-height: 40px; }
.login-panel .panel-form button { min-height: 38px; }

@media (max-width: 1180px) {
  .app-header { min-height: 58px; flex-wrap: wrap; gap: 10px 12px; padding: 8px 14px; }
  .app-header > .app-brand { flex: 1 1 auto; }
  .admin-layout .app-header button.nav-toggle {
    display: flex;
    width: 38px;
    min-height: 38px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--admin-secondary-border);
    border-radius: 5px;
    background: var(--surface);
    color: var(--ink);
  }
  .nav-toggle span { display: block; width: 17px; height: 1.5px; background: currentColor; }
  .primary-nav { display: none; }
  body.nav-open .primary-nav {
    position: absolute;
    top: 100%;
    right: 8px;
    left: 8px;
    z-index: 55;
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--sheet-border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 12px 26px rgba(20, 38, 34, .12);
  }
  .nav-group > summary { min-height: 46px; justify-content: space-between; padding: 0 12px; }
  .nav-group[open] { padding-bottom: 4px; border-bottom: 1px solid var(--row-rule); }
  .nav-menu { position: static; min-width: 0; gap: 1px; padding: 0 4px 4px 12px; border: 0; border-radius: 0; box-shadow: none; }
  .nav-menu .topbar-link { min-height: 40px; }
  .header-user { width: 100%; justify-content: flex-end; gap: 10px; }
  .header-user .who { max-width: 112px; overflow: hidden; text-overflow: ellipsis; }
  .nav-scrim { position: fixed; inset: 58px 0 0; z-index: 45; border: 0; border-radius: 0; background: rgba(18, 27, 25, .18); opacity: 0; pointer-events: none; }
  body.nav-open .nav-scrim { display: block; opacity: 1; pointer-events: auto; }
  .container { padding: 22px; }
}
@media (max-width: 640px) {
  .app-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 8px; padding: 10px 12px; }
  .app-header .app-brand { gap: 6px; padding: 0; }
  .app-brand-copy strong { font-size: 14px; }
  .app-brand-copy small { font-size: 11px; }
  .app-header .nav-toggle { grid-column: 2; grid-row: 1; }
  .header-user { grid-column: 1 / -1; grid-row: 2; gap: 8px; }
  .header-user .who { display: none; }
  .header-preferences { flex: 1 1 auto; justify-content: flex-end; gap: 8px; }
  .ui-size-control { gap: 6px; }
  .admin-layout .ui-size-control select { width: 80px; }
  .header-user .logout-button { min-height: var(--admin-button-height); padding: 0 8px; }
  .topbar { width: calc(100% - 24px); min-height: 52px; padding: 8px 2px; }
  .app-main { padding-top: 12px; }
  .container { width: calc(100% - 24px); margin: 0 auto 12px; padding: 16px; border-radius: 10px; }
  .global-shop-context { padding: 8px 16px; }
  .page-header { flex-direction: column; gap: 10px; margin-bottom: 16px; }
  .page-header h1, .login-heading h1 { font-size: 1.4rem; }
  .dashboard-page [data-testid="dashboard-quick-links"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-page [data-testid="dashboard-quick-links"] > a { min-height: 80px; padding: 12px; }
  .dashboard-page [data-testid="dashboard-quick-links"] > a:last-child { grid-column: 1 / -1; }
  .panel { padding: 14px; }
  .ops-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ops-summary-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .cockpit-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cockpit-stat { min-width: 0; }
  .cockpit-stat:nth-child(2n) { border-right: 0; }
  .cockpit-stat:nth-child(n + 3) { border-top: 1px solid var(--row-rule); }
  .cockpit-stat:last-child:nth-child(odd) { grid-column: 1 / -1; border-right: 0; }
  .cockpit-stat-value, .cockpit-stat-label { min-width: 0; overflow-wrap: anywhere; }
  .cockpit-stats .cockpit-cell-muted { overflow-wrap: anywhere; }
  .cockpit-filterbar, .cockpit-control-grid, .cockpit-search-row { min-width: 0; }
  .cockpit-filterbar *, .cockpit-control-grid * { min-width: 0; }
  .cockpit-filterbar-actions { flex-wrap: wrap; }
  .cockpit-command-title-row { align-items: stretch; flex-direction: column; }
  .cockpit-shop-switcher { display: grid; grid-template-columns: auto minmax(0, 1fr); width: 100%; margin-left: 0; }
  .cockpit-shop-switcher label { grid-column: 1; }
  .cockpit-shop-switcher select { grid-column: 2; width: 100%; min-width: 0; max-width: none; }
  .cockpit-shop-loading { grid-column: 2; }
  .login-layout .container { margin: 8px; padding: 16px; }
  .login-layout .topbar { padding: 0 16px; }
  .login-panel { padding: 20px; }
  table { display: block; max-width: 100%; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
