/* HRAYE 业务系统
   Layout: fixed left rail of modules + working area (filter bar, dense ledger tables); records open in a side drawer.
   Phones: the rail becomes a top tab strip, tables become cards, the drawer becomes a full sheet. */
:root {
  --bg: #F3F4F7;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --line: #E1E4EB;
  --line-strong: #C9CED9;
  --ink: #181C27;
  --muted: #5D6474;
  --faint: #8A90A0;
  --accent: #2C3C8F;        /* indigo dye */
  --accent-soft: #E7EAF7;
  --accent-ink: #FFFFFF;
  --greige: #B9AF9D;        /* raw greige cloth */
  --ok: #1D7349;  --ok-soft: #E2F2E9;
  --warn: #9A5B00; --warn-soft: #FBEFD9;
  --bad: #B1261D; --bad-soft: #FBE4E1;
  --info: #1E5E8C; --info-soft: #E1EEF7;
  --neutral-soft: #ECEDF1;
  --shadow: 0 12px 32px rgba(20, 26, 48, .16);
  --f-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --f-mono: "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, "Roboto Mono", "Noto Sans Mono", monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1117; --surface: #171A23; --surface-2: #1C2030; --line: #2A2F3E; --line-strong: #3A4053;
    --ink: #E6E8EF; --muted: #A0A7B8; --faint: #767D8F;
    --accent: #93A2F2; --accent-soft: #232A48; --accent-ink: #0F1117; --greige: #8F8676;
    --ok: #5CCB91; --ok-soft: #173326; --warn: #F0B556; --warn-soft: #3A2C12;
    --bad: #FF8E84; --bad-soft: #3D1C1A; --info: #7CC0F0; --info-soft: #15293A; --neutral-soft: #252A38;
    --shadow: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--f-mono); font-size: .93em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.boot { padding: 40px; color: var(--muted); }

/* brand mark: a plain weave of indigo warp and greige weft */
.weave { width: 26px; height: 26px; border-radius: 5px; flex: none;
  background: repeating-linear-gradient(90deg, var(--accent) 0 3px, transparent 3px 6px), repeating-linear-gradient(0deg, var(--greige) 0 3px, var(--surface) 3px 6px); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px 26px; display: grid; gap: 16px; }
.login-card .brand { padding: 0; }
.login-card h1 { font-size: 20px; margin: 4px 0 0; font-weight: 600; }
.login-card p { margin: 0; color: var(--muted); }
.login-card .err { color: var(--bad); min-height: 1.5em; font-size: 13px; }

/* shell */
.app { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100%; }
.rail { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 20px;
  padding-block: 18px; padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: 14px; position: sticky; top: 0; height: 100vh; height: 100dvh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand b { font-family: var(--f-mono); font-weight: 600; letter-spacing: .22em; font-size: 15px; display: block; }
.brand small { color: var(--muted); font-size: 11.5px; letter-spacing: .06em; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { font-family: var(--f-mono); font-size: 12px; color: var(--faint); }
.rail-foot { margin-top: auto; display: grid; gap: 8px; font-size: 12.5px; color: var(--muted); }
.who { display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; flex: none; }
.who b { color: var(--ink); font-weight: 500; display: block; line-height: 1.2; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover { color: var(--accent); }

.main { min-width: 0; padding-block: 22px 48px; padding-left: 28px; padding-right: max(28px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 16px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head h1 { font-weight: 600; font-size: 24px; margin: 0; letter-spacing: .02em; text-wrap: balance; }
.head p { margin: 2px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; padding: 7px 14px; line-height: 1.3; white-space: nowrap; text-decoration: none; color: var(--ink); display: inline-block; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn.danger.armed { background: var(--bad); color: var(--surface); border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.banner { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 11px 14px; color: var(--muted); }
.banner.warn { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search { flex: 1 1 240px; min-width: 0; position: relative; }
.search input { width: 100%; padding: 8px 12px 8px 32px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; stroke: var(--faint); fill: none; }
.filters select { padding: 7px 26px 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background-color: var(--surface); max-width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 11px; color: var(--muted); border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); white-space: nowrap; }

.totals { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 13px; color: var(--muted); padding: 0 2px; }
.totals b { color: var(--ink); font-family: var(--f-mono); font-weight: 600; font-variant-numeric: tabular-nums; }

/* tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 11px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { font-weight: 600; font-size: 12px; color: var(--muted); letter-spacing: .03em; background: var(--surface-2); user-select: none; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:focus-visible { outline: 2px solid var(--accent); }
th .arrow { color: var(--accent); font-size: 10px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tbody tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
td.wide { white-space: normal; min-width: 220px; max-width: 420px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.pager .actions { gap: 6px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.typ { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 5px; font-family: var(--f-mono); font-weight: 600; font-size: 12px; background: var(--neutral-soft); color: var(--muted); }
.typ.O { background: var(--accent); color: var(--accent-ink); }
.typ.S { background: var(--info-soft); color: var(--info); }
.typ.L { background: var(--warn-soft); color: var(--warn); }
.typ-m { display: none; }
.due { display: block; font-size: 11.5px; }
.due.bad { color: var(--bad); font-weight: 600; }
.due.warn { color: var(--warn); }
.tag { display: inline-block; padding: 0 7px; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 12px; color: var(--muted); }
.status-ok { color: var(--ok); }
.steps { display: inline-grid; grid-auto-flow: column; gap: 3px; vertical-align: middle; }
.steps i { width: 13px; height: 6px; border-radius: 2px; background: var(--line-strong); }
.steps i.done { background: var(--ok); }
.steps i.on { background: var(--accent); }
.steps-label { margin-left: 8px; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty strong { color: var(--ink); font-weight: 600; font-size: 15px; }
.loading { padding: 40px 20px; text-align: center; color: var(--faint); }

/* dashboard */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 3px; text-align: left; text-decoration: none; color: inherit; }
a.tile:hover { border-color: var(--accent); }
.tile .k { color: var(--muted); font-size: 12.5px; }
.tile .v { font-family: var(--f-mono); font-size: 26px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.tile.bad .v { color: var(--bad); }
.tile.warn .v { color: var(--warn); }
.tile .s { color: var(--faint); font-size: 12px; }
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; display: flex; flex-direction: column; }
.panel.span { grid-column: 1 / -1; }
.panel h2 { font-size: 14px; font-weight: 600; margin: 0; padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.panel h2 span { color: var(--faint); font-family: var(--f-mono); font-weight: 400; font-size: 12.5px; }
.panel h2 a { font-weight: 400; font-size: 12.5px; color: var(--accent); text-decoration: none; }
.rows { list-style: none; margin: 0; padding: 4px 0; }
.rows li > button, .rows li > a { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 12px; padding: 8px 16px; cursor: pointer; }
.rows li > button:hover, .rows li > a:hover { background: var(--surface-2); }
.rows li > button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rows .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .m { grid-column: 1; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .x { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; font-size: 13px; }
.panel .none { padding: 18px 16px; color: var(--faint); }
.chart { padding: 14px 16px 10px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--accent); }
.chart .bar.cur { fill: var(--greige); }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--f-mono); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .val { fill: var(--ink); font-size: 10.5px; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 20, .38); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(600px, 100%); background: var(--surface); z-index: 21; box-shadow: var(--shadow);
  display: flex; flex-direction: column; border-left: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px); }
.drawer-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer-head h3 { margin: 0; font-size: 18px; font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drawer-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.x-btn { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: 4px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; display: flex; flex-direction: column; gap: 20px; }
.drawer-foot { border-top: 1px solid var(--line); padding: 12px 20px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drawer-foot .spacer { flex: 1; }
.sec-title { font-size: 12px; color: var(--muted); letter-spacing: .08em; margin: 0 0 10px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); }
.field label .req { color: var(--bad); }
.field .row { display: flex; gap: 6px; }
.field .row > input { flex: 1; min-width: 0; }
.field input, .field select, .field textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); min-width: 0; }
.field textarea { min-height: 64px; resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled { background: var(--surface-2); color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }
.field .hint { font-size: 12px; color: var(--warn); }
.field .help { font-size: 12px; color: var(--faint); }
.spec { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px; color: var(--muted); font-size: 13px; }
.spec b { color: var(--ink); font-weight: 600; }
.stage-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-picker button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.stage-picker button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.quick { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.quick input { flex: 1 1 160px; min-width: 0; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.quick input.qty { flex: 0 1 120px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.log li { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; font-size: 13px; }
.log time { color: var(--faint); font-family: var(--f-mono); font-size: 12px; }
.related { display: grid; gap: 6px; }
.related button { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.related button:hover { border-color: var(--accent); }
.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini th, .mini td { padding: 6px 8px; }
.mini tbody tr { cursor: default; }
.mini-wrap { border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(10, 12, 20, .45); }
.modal-card { width: min(440px, 100%); background: var(--surface); border-radius: 10px; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 20px 22px; display: grid; gap: 14px; }
.modal-card h3 { margin: 0; font-size: 17px; }
.secret { font-family: var(--f-mono); font-size: 18px; letter-spacing: .06em; padding: 10px 12px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 6px; user-select: all; text-align: center; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 6px; z-index: 40; font-size: 13.5px; max-width: calc(100% - 32px); }

@media (max-width: 1180px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panels { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; gap: 12px;
    padding-block: 9px; padding-top: calc(9px + env(safe-area-inset-top, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
    border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand small, .rail-foot .who div, .rail-foot .ver { display: none; }
  .brand b { font-size: 13px; }
  .nav { flex-direction: row; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav .count { display: none; }
  .rail-foot { margin: 0 0 0 auto; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
  .main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px 32px; }
  .head h1 { font-size: 21px; }
  .table-wrap.cards { background: transparent; border: 0; overflow: visible; }
  .cards table, .cards tbody { display: block; }
  .cards thead { display: none; }
  .cards tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 11px 13px; margin-bottom: 8px; }
  .cards td { display: block; padding: 0; border: 0; white-space: normal; min-width: 0; max-width: none; text-align: left !important; overflow-wrap: anywhere; }
  .cards td::before { content: attr(data-l); display: block; font-size: 11px; color: var(--faint); }
  .cards td.lead { grid-column: 1 / -1; font-size: 15px; font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .cards td.lead::before { display: none; }
  .cards td.lead { order: -1; }
  .cards td.lead .typ-m { display: inline-flex; }
  .cards td.tcol { display: none; }
  .cards td.full { grid-column: 1 / -1; }
  .cards td:empty { display: none; }
  .cards tbody tr:hover td { background: transparent; }
  .form, .form.three { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .seg { overflow-x: auto; max-width: 100%; }
}
@media (max-width: 520px) {
  .tiles { gap: 8px; }
  .tile .v { font-size: 21px; }
  .drawer { width: 100%; border-left: 0; }
  .form, .form.three { grid-template-columns: minmax(0, 1fr); }
  .log li { grid-template-columns: 1fr; gap: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slide .18s ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
