:root {
  color-scheme: light;
  --bg: #eff3f3;
  --surface: #fff;
  --text: #142522;
  --muted: #536761;
  --border: #dce6e2;
  --sidebar: #102924;
  --green: #006b52;
  --green-dark: #00523e;
  --green-soft: #e0f5eb;
  --error: #a42530;
  --amber: #895b12;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--text); background: var(--bg); min-width: 300px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.55rem, 3vw, 2.15rem); line-height: 1.2; letter-spacing: -.04em; }
h2 { font-size: 1.17rem; line-height: 1.4; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { opacity: .56; cursor: default; }
:focus-visible { outline: 3px solid #3cab8c; outline-offset: 3px; }
.skip-link { position: fixed; z-index: 9; top: .5rem; left: .5rem; transform: translateY(-150%); background: white; padding: .5rem; }
.skip-link:focus { transform: translateY(0); }
.boot { padding: 12vh 1rem; text-align: center; color: var(--muted); }

.brand { display: flex; align-items: center; gap: .7rem; font-size: 1.12rem; font-weight: 700; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; flex: 0 0 2.15rem; height: 2.15rem;
  border-radius: .62rem; background: #9ae8c6; color: #123429;
  font-family: "Segoe UI", sans-serif; font-size: 1.15rem;
}
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1rem; background: radial-gradient(ellipse at 50% 0%, #24443a, #102622 55%, #0b211d); }
.login-shell { width: min(100%, 29rem); }
.brand-login { color: #e5f8ef; margin-bottom: 1.1rem; }
.login-card { padding: clamp(1.35rem, 5vw, 2.35rem); border: 1px solid var(--border); border-radius: .9rem; background: var(--surface); box-shadow: 0 1.5rem 5rem #061a14a8; }
.login-card > p { color: var(--muted); margin-top: .6rem; margin-bottom: 1.5rem; }
.login-card .primary { width: 100%; }

.app { min-height: 100vh; display: grid; grid-template-columns: 14.25rem minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; gap: 2rem; color: #d0e6de; background: var(--sidebar); padding: 1.55rem 1rem; }
.sidebar .brand { color: #f7fffc; padding-inline: .35rem; }
.nav { display: grid; gap: .35rem; }
.nav a { padding: .64rem .84rem; border-radius: .52rem; font-weight: 600; }
.nav a:hover { background: #223c34; }
.nav a[aria-current=page] { color: #e6fff3; background: #255043; box-shadow: inset 3px 0 #9ae8c6; }
.sidebar-foot { margin-top: auto; color: #b2cbc1; display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.connection-dot { width: .5rem; height: .5rem; background: #9ae8c6; border-radius: 50%; }
.main { padding: 1.8rem clamp(1.15rem,3vw,2.7rem) 3rem; max-width: 87rem; width: 100%; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin: .25rem 0 1.35rem; }
.eyebrow { font-weight: 700; font-size: .81rem; letter-spacing: .065em; color: var(--green); margin-bottom: .38rem; }
.top-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.user-chip { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: .9rem; }
.page { display: grid; gap: 1.2rem; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem; }
.stat, .panel { border: 1px solid var(--border); border-radius: .72rem; background: var(--surface); }
.stat { display: grid; gap: .1rem; padding: 1.1rem 1.25rem; color: var(--muted); transition: border-color .15s; }
.stat:hover { border-color: #82bba8; }
.stat span:first-child { color: var(--text); font-weight: 600; }
.stat strong { color: var(--green-dark); font-size: clamp(1.65rem, 4vw, 2.25rem); font-variant-numeric: tabular-nums; line-height: 1.3; overflow-wrap: anywhere; }
.stat span:last-child { font-size: .87rem; }
.panel-header { padding: 1.15rem 1.3rem; display: flex; justify-content: space-between; align-items: center; gap: .85rem; }
.panel-header p { color: var(--muted); margin-top: .24rem; font-size: .94rem; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: .68rem .7rem; border-top: 1px solid var(--border); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 1.3rem; }
th:last-child, td:last-child { padding-right: 1.3rem; }
th { background: #f5f8f7; font-size: .85rem; font-weight: 700; color: #405750; white-space: nowrap; }
td { font-size: .94rem; overflow-wrap: anywhere; }
td:first-child { min-width: 8rem; }
td.cell-actions { white-space: nowrap; }
td code { white-space: nowrap; }
.cell-actions .text-button + .text-button { margin-left: .45rem; }
.table-sub { display: block; margin-top: .15rem; color: var(--muted); font-size: .83rem; white-space: nowrap; }
.delivery-detail { margin-top: .3rem; }
.delivery-detail summary { width: fit-content; cursor: pointer; color: var(--green-dark); font-size: .87rem; }
.delivery-detail ul { margin: .15rem 0 .15rem; padding-left: 1.12rem; color: var(--muted); font-size: .87rem; }
.delivery-body { margin: .35rem 0 .2rem; max-width: 30rem; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: .87rem; }
.history-filter { display: flex; align-items: center; gap: .45rem; flex: 0 0 auto; font-size: .9rem; color: var(--muted); }
.history-filter select { max-width: 9rem; border: 1px solid var(--border); border-radius: .4rem; padding: .37rem .55rem; background: var(--surface); color: var(--text); }
.history-note { padding: .5rem 1.3rem .7rem; font-size: .88rem; color: var(--muted); }
.history-note.error { color: var(--error); }
.history-footer { padding: .75rem 1.3rem; border-top: 1px solid var(--border); text-align: center; }
#market, #history { scroll-margin-top: .75rem; }
.empty { text-align: center; color: var(--muted); padding: 1.65rem 1rem; border-top: 1px solid var(--border); }
.tag { display: inline-flex; align-items: center; padding: .12rem .48rem; border-radius: .35rem; background: #edf1ef; color: #3e554e; font-size: .85rem; white-space: nowrap; }
.tag.good { background: var(--green-soft); color: var(--green-dark); }
.tag.bad { background: #fcebed; color: var(--error); }
.tag.warn { background: #fff2d8; color: var(--amber); }
.device-switch {
  display: inline-flex; align-items: center; min-height: 2.5rem; padding: .2rem;
  border: 0; border-radius: .4rem; background: transparent; color: var(--muted);
  font-size: .88rem; font-weight: 600; white-space: nowrap;
}
.device-switch:hover:not([aria-disabled=true]) { background: #eef5f2; }
.device-switch[aria-disabled=true] { cursor: wait; opacity: .72; }
.device-switch[aria-checked=true] { color: var(--green-dark); }
.device-switch-contents { display: inline-flex; align-items: center; gap: .36rem; }
.device-switch-track {
  position: relative; width: 2.2rem; height: 1.22rem; border-radius: 1rem;
  background: #73847f; transition: background .14s;
}
.device-switch-track::after {
  content: ''; position: absolute; top: .15rem; left: .15rem; width: .92rem; height: .92rem;
  border-radius: 50%; background: #fff; transition: transform .14s;
}
.device-switch[aria-checked=true] .device-switch-track { background: var(--green); }
.device-switch[aria-checked=true] .device-switch-track::after { transform: translateX(.98rem); }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.35rem; border: 1px solid transparent; border-radius: .49rem; padding: .42rem .86rem; font-weight: 650; font-size: .91rem; white-space: nowrap; line-height: 1.3; }
.primary { background: var(--green); color: #fff; }
.primary:hover:not(:disabled) { background: var(--green-dark); }
.secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
.secondary:hover:not(:disabled) { background: #eef5f2; }
.text-button { border: 0; background: transparent; color: var(--green-dark); font-size: .87rem; font-weight: 600; padding: .25rem; }
.text-button:hover { text-decoration: underline; }
.text-button.danger { color: var(--error); }
.notice { border: 1px solid #b2d9cb; color: var(--green-dark); background: var(--green-soft); border-radius: .55rem; padding: .58rem .85rem; margin-bottom: 1rem; overflow-wrap: anywhere; }
.notice.error { border-color: #edc1c4; color: var(--error); background: #fff2f3; }

.stack { display: grid; gap: .88rem; }
.stack label { display: grid; gap: .29rem; color: #243934; font-size: .94rem; font-weight: 600; }
.stack small { color: var(--muted); font-size: .84rem; font-weight: 400; }
.stack input:not([type=checkbox]), .stack select, .stack textarea {
  width: 100%; min-width: 0; border: 1px solid #b9ccc5; border-radius: .44rem;
  min-height: 2.58rem; padding: .52rem .68rem; background: #fff; color: var(--text); font-size: 1rem;
}
.stack select { appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 50%, var(--green) 50%), linear-gradient(135deg, var(--green) 50%, transparent 50%); background-position: calc(100% - 1.05rem) 52%, calc(100% - .74rem) 52%; background-size: .31rem .31rem; background-repeat: no-repeat; }
.stack textarea { resize: vertical; }
.stack .choice { display: flex; align-items: center; gap: .47rem; width: fit-content; font-weight: 500; }
.choice input { margin: 0; width: 1rem; height: 1rem; accent-color: var(--green); }
.form-panel { max-width: 42rem; }
.settings-form { padding: 0 1.3rem 1.3rem; }
.form-footer { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.form-message { font-size: .91rem; color: var(--error); overflow-wrap: anywhere; }
.form-message:empty { display: none; }
.form-message.okay { color: var(--green-dark); }
.dialog { width: min(calc(100% - 1.5rem), 34rem); max-height: calc(100% - 1.5rem); overflow: auto; border: 1px solid var(--border); border-radius: .8rem; padding: 1.25rem; color: var(--text); box-shadow: 0 1.5rem 5rem #0a1e1960; }
.dialog::backdrop { background: #0f211c91; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: .65rem; }
.dialog .form-footer { justify-content: flex-end; }
.target-field { min-width: 0; margin: 0; border: 1px solid var(--border); border-radius: .45rem; padding: .5rem .7rem .65rem; }
.target-field legend { padding: 0 .24rem; font-size: .94rem; font-weight: 600; }
.choice-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .44rem .55rem; max-height: 8.6rem; overflow: auto; margin-top: .45rem; padding: .1rem .22rem .14rem; }
.choice-list span { overflow-wrap: anywhere; }

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; padding: .8rem 1rem; }
  .nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .nav a { padding: .42rem .53rem; font-size: .91rem; }
  .sidebar-foot { display: none; }
}

@media (max-width: 520px) {
  .main { padding: .85rem .78rem 2rem; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .stats { grid-template-columns: 1fr; gap: .5rem; }
  .stat { grid-template-columns: 1fr auto; align-items: center; gap: 0 .5rem; padding: .65rem .76rem; }
  .stat strong { grid-column: 2; grid-row: 1 / span 2; }
  .stat span:last-child { grid-column: 1; }
  .panel-header { align-items: flex-start; padding: .85rem .82rem; }
  .panel-header p { font-size: .88rem; }
  .history-filter { flex-wrap: wrap; justify-content: end; }
  .history-note, .history-footer { padding-inline: .82rem; }
  th:first-child, td:first-child { padding-left: .82rem; }
  th:last-child, td:last-child { padding-right: .82rem; }
  .settings-form { padding: 0 .82rem .85rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
