:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #1d2939;
  background: #f5f7fa;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: 0 0 220px; padding: 28px 16px; background: #182230; color: #edf3fb; }
.brand { display: block; margin: 0 12px 32px; font-size: 20px; font-weight: 700; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a { padding: 12px; border-radius: 8px; }
.sidebar nav a:hover, .sidebar nav a:focus { background: #2c3b4f; }
.content { width: 100%; min-width: 0; padding: 0 32px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; border-bottom: 1px solid #dde4ed; }
.role-badge { display: inline-block; margin-left: 8px; padding: 4px 8px; border-radius: 999px; background: #e7edf5; color: #40516a; font-size: 13px; }
.text-button { border: 0; background: transparent; color: #315d9c; font: inherit; cursor: pointer; padding: 12px; }
.page-heading { max-width: 920px; padding: 44px 0 28px; }
.eyebrow { margin: 0 0 8px; color: #496988; font-size: 14px; font-weight: 700; letter-spacing: .04em; }
h1 { margin: 0 0 16px; font-size: clamp(28px, 4vw, 38px); }
.page-heading p { line-height: 1.7; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; max-width: 920px; }
.metric-grid article { min-width: 0; padding: 22px; border: 1px solid #dde4ed; border-radius: 12px; background: #fff; }
.metric-grid span { display: block; color: #667085; font-size: 14px; }
.metric-grid strong { display: block; margin-top: 14px; font-size: 28px; }
.notice { max-width: 920px; margin-top: 24px; padding: 14px 16px; border-radius: 8px; background: #eef5ff; color: #2d5b91; }
.button { display: inline-block; min-height: 44px; margin-top: 16px; padding: 11px 18px; border: 1px solid transparent; border-radius: 8px; background: #193b60; color: #fff; font: inherit; cursor: pointer; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); padding: clamp(28px, 7vw, 44px); border: 1px solid #dde4ed; border-radius: 14px; background: #fff; box-shadow: 0 12px 32px rgb(25 39 60 / 8%); }
.login-card form { display: grid; gap: 10px; margin-top: 28px; }
.login-card label { font-size: 14px; font-weight: 600; }
.login-card input[type="text"], .login-card input[type="password"] { min-height: 44px; width: 100%; padding: 10px 12px; border: 1px solid #b9c5d3; border-radius: 8px; font: inherit; }
.login-card .button { width: 100%; margin-top: 12px; }
.page-heading-inline { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.filter-bar, .record-form { display: flex; flex-wrap: wrap; gap: 16px; max-width: 920px; padding: 20px; border: 1px solid #dde4ed; border-radius: 12px; background: #fff; }
.filter-bar label, .form-field { display: grid; gap: 7px; color: #475467; font-size: 14px; font-weight: 600; }
.filter-bar input, .filter-bar select, .record-form input, .record-form select, .record-form textarea { width: min(100%, 380px); min-height: 42px; padding: 9px 11px; border: 1px solid #b9c5d3; border-radius: 8px; background: #fff; color: inherit; font: inherit; }
.record-form { display: grid; max-width: 680px; }
.record-form textarea { width: 100%; min-height: 96px; resize: vertical; }
.brand-search-control { position: relative; }
.brand-options { max-height: 220px; width: min(100%, 380px); overflow-y: auto; border: 1px solid #b9c5d3; border-radius: 8px; background: #fff; box-shadow: 0 8px 20px rgb(25 39 60 / 12%); }
.brand-options button { display: block; width: 100%; padding: 11px 12px; border: 0; border-bottom: 1px solid #edf1f5; background: #fff; color: #1d2939; font: inherit; text-align: left; cursor: pointer; }
.brand-options button:last-child { border-bottom: 0; }
.brand-options button:hover, .brand-options button:focus { background: #eef5ff; }
.selected-brand, .brand-empty { width: min(100%, 380px); margin: 0; color: #667085; font-size: 13px; font-weight: 400; }
.brand-empty a { color: #2869aa; font-weight: 600; }
.button.compact { min-height: 42px; margin-top: 21px; }
.button.secondary { background: #fff; color: #243b53; border: 1px solid #8294a7; }
.button.danger { background: #b42318; }
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid #dde4ed; border-radius: 12px; background: #fff; }
.data-table { width: 100%; min-width: 760px; border-collapse: collapse; }
.data-table th, .data-table td { padding: 14px 16px; border-bottom: 1px solid #e7edf3; text-align: left; vertical-align: top; }
.data-table th { color: #475467; font-size: 13px; white-space: nowrap; }
.data-table td { overflow-wrap: anywhere; }
.table-link { margin-right: 12px; color: #2869aa; }
.status { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
.status-active { background: #e6f6ec; color: #18723b; }
.status-inactive { background: #f2f4f7; color: #667085; }
.empty-cell { color: #667085; text-align: center !important; }
.pagination, .form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }
.pagination a { color: #2869aa; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; max-width: 920px; margin: 0; border: 1px solid #dde4ed; background: #dde4ed; }
.detail-grid div { min-width: 0; padding: 18px; background: #fff; }
.detail-grid dt { margin-bottom: 7px; color: #667085; font-size: 13px; }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; }
.field-error { margin: 0; color: #b42318; font-size: 13px; }
.field-help { margin: 0; color: #667085; font-size: 13px; font-weight: 400; }
.ledger-brand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 14px; max-width: 1100px; margin-top: 20px; }
.ledger-brand-card { display: grid; gap: 8px; min-width: 0; padding: 20px; border: 1px solid #dde4ed; border-radius: 12px; background: #fff; }
.ledger-brand-card strong { font-size: 18px; }
.ledger-brand-card span { color: #667085; overflow-wrap: anywhere; }
.ledger-brand-action { color: #2869aa !important; font-weight: 600; }
.ledger-month-filter { align-items: end; }
.ledger-month-filter input { width: 190px; }
.ledger-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; max-width: 1100px; margin: 20px 0; }
.ledger-summary-grid article { display: grid; gap: 10px; min-width: 0; padding: 18px; border: 1px solid #dde4ed; border-radius: 12px; background: #fff; }
.ledger-summary-grid span, .ledger-summary-grid small, .ledger-brand-readonly span { color: #667085; font-size: 14px; }
.ledger-summary-grid strong { font-size: clamp(20px, 3vw, 28px); overflow-wrap: anywhere; }
.ledger-summary-grid small { font-size: 12px; }
.ledger-summary-grid .ledger-grand-total { border-color: #9bb9da; background: #eef5ff; }
.ledger-detail-section { margin-top: 28px; }
.ledger-detail-section h2 { margin-bottom: 14px; font-size: 20px; }
.ledger-detail-section .data-table { min-width: 700px; }
.ledger-detail-section tfoot th { padding: 14px 16px; background: #f8fafc; text-align: left; }
.ledger-note { color: #667085; font-size: 13px; }
.ledger-brand-readonly { display: grid; gap: 6px; max-width: 680px; margin: 0 0 16px; padding: 14px 18px; border: 1px solid #dde4ed; border-radius: 10px; background: #eef5ff; }
.ledger-brand-readonly strong { font-size: 18px; }
.ledger-entry-form input[type="month"] { width: min(100%, 380px); }
.notice.warning { background: #fff4e5; color: #8a4b08; }

@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 14px 16px; }
  .brand { margin: 0; font-size: 18px; }
  .sidebar nav { display: flex; gap: 4px; }
  .sidebar nav a { padding: 10px 8px; font-size: 14px; }
  .content { padding: 0 18px 32px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-heading-inline { align-items: flex-start; flex-direction: column; }
  .filter-bar { display: grid; }
  .filter-bar input, .filter-bar select { width: 100%; }
  .button.compact { margin-top: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .ledger-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger-month-filter input { width: 100%; }
}

.button:disabled { opacity: .55; cursor: not-allowed; }
.detail-grid dd { overflow-wrap: anywhere; }

/* Manufacturer facts: readable on one column at 390px. */
.manufacturer-actions { display:flex; gap:12px; flex-wrap:wrap; margin:20px 0; }
.manufacturer-form { max-width:760px; }
.manufacturer-form p { display:flex; flex-direction:column; gap:8px; }
.manufacturer-form input:not([type=checkbox]), .manufacturer-form textarea { width:100%; max-width:100%; box-sizing:border-box; }
.manufacturer-form input[type=checkbox] { width:20px; height:20px; }
.manufacturer-record { background:white; padding:18px; border:1px solid #cbd5e1; border-radius:8px; margin:12px 0; overflow-wrap:anywhere; }
.manufacturer-record .button { margin:6px 6px 0 0; }
/* Preview admission does not grant write actions; server checks remain authoritative. */
.preview-read-only { border: 0; padding: 0; margin: 0; min-width: 0; }
