:root {
  --ink: #18251d;
  --muted: #68736b;
  --forest: #1f5b3a;
  --forest-deep: #123c28;
  --leaf: #71a36f;
  --amber: #d18b32;
  --danger: #b84a3a;
  --paper: #f7f4ec;
  --surface: rgba(255, 255, 255, 0.9);
  --line: rgba(31, 69, 46, 0.14);
  --shadow: 0 18px 50px rgba(33, 56, 40, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background:
    radial-gradient(circle at 86% 4%, rgba(216, 177, 91, 0.18), transparent 26rem),
    linear-gradient(135deg, #f8f5ed 0%, #eef3e9 100%);
}

button, input { font: inherit; }
button { cursor: pointer; }

.login-wrap {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(17, 61, 39, 0.96), rgba(31, 91, 58, 0.86)),
    repeating-linear-gradient(90deg, transparent 0 72px, rgba(255,255,255,.04) 72px 73px);
}

.login-card {
  width: min(100%, 420px);
  padding: 36px;
  display: grid;
  gap: 12px;
  background: #fffdf8;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 24px 6px 24px 6px;
  box-shadow: 0 28px 80px rgba(4, 25, 14, 0.3);
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: #fff;
  font-family: Georgia, serif;
  font-weight: 700;
  letter-spacing: -2px;
  background: var(--forest);
  border-radius: 14px 4px 14px 4px;
}

.eyebrow, .section-kicker {
  margin: 0;
  color: var(--amber);
  font-family: Georgia, serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
}

.login-card h1 { margin: 0; font-size: 28px; }
.login-intro { margin: 0 0 8px; color: var(--muted); line-height: 1.7; }
.login-card label { font-size: 13px; font-weight: 700; }
.login-card input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  outline: none;
}
.login-card input:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(31,91,58,.12); }
.error { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }

.app-shell {
  min-height: calc(100vh - 48px);
  flex: 1;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: calc(100vh - 48px);
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  color: #eef7ef;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 30%),
    var(--forest-deep);
}

.brand-block { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-block strong { display: block; font-family: Georgia, serif; font-size: 20px; }
.brand-block span { display: block; margin-top: 3px; color: rgba(238,247,239,.58); font-size: 12px; }

.tabs { display: grid; gap: 8px; }
.tab-btn {
  width: 100%;
  padding: 12px 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: rgba(238,247,239,.72);
  background: transparent;
  text-align: left;
}
.tab-btn span { color: rgba(238,247,239,.36); font-family: Georgia, serif; font-size: 11px; }
.tab-btn:hover, .tab-btn.active { color: #fff; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.1); }
.tab-btn.active::after { width: 5px; height: 5px; margin-left: auto; content: ""; border-radius: 50%; background: #e5b85b; }

.device-mini { margin-top: auto; padding: 14px; display: flex; align-items: center; gap: 10px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; background: rgba(255,255,255,.05); }
.device-mini strong, .device-mini small { display: block; }
.device-mini strong { font-size: 13px; }
.device-mini small { margin-top: 3px; color: rgba(238,247,239,.5); font-size: 10px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa29c; box-shadow: 0 0 0 4px rgba(255,255,255,.06); }
.status-dot.online { background: #83c98a; box-shadow: 0 0 0 4px rgba(131,201,138,.12); }

.workspace { min-width: 0; }
.topbar { min-height: 104px; padding: 22px clamp(20px, 3vw, 46px); display: flex; justify-content: space-between; align-items: center; gap: 20px; border-bottom: 1px solid var(--line); background: rgba(250,248,242,.72); backdrop-filter: blur(12px); }
.topbar h1 { margin: 5px 0 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.04em; }
.top-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.connection-pill { padding: 8px 12px; border-radius: 999px; color: var(--forest); background: rgba(57,122,78,.1); font-weight: 700; }

.layout { width: min(1500px, 100%); margin: 0 auto; padding: 26px clamp(18px, 3vw, 44px) 48px; }
.page { display: none; }
.page.active { display: grid; gap: 18px; animation: reveal .35s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(6px); } }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.metric-card { min-height: 92px; padding: 18px 20px; position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 4px 18px 4px 18px; background: var(--surface); box-shadow: 0 8px 24px rgba(33,56,40,.05); }
.metric-card::after { position: absolute; right: -18px; bottom: -24px; width: 80px; height: 80px; content: ""; border: 12px solid rgba(113,163,111,.08); border-radius: 50%; }
.metric-card span { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.metric-card strong { font-size: 21px; }

.operation-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(320px, .75fr); gap: 18px; align-items: start; }
.card { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 5px 20px 5px 20px; background: var(--surface); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.card h2 { margin: 4px 0 0; font-size: 22px; }
.sub { margin: 7px 0 14px; color: var(--muted); font-size: 13px; line-height: 1.6; }

.player-wrap { position: relative; overflow: hidden; aspect-ratio: 16 / 9; border: 1px solid rgba(9,28,17,.24); border-radius: 3px 14px 3px 14px; background: #07130d; }
.webrtc-frame { width: 100%; height: 100%; display: block; border: 0; background: #07130d; }
.player-placeholder { height: 100%; display: grid; place-items: center; color: rgba(255,255,255,.72); font-size: 13px; background: radial-gradient(circle at center, #153b28, #07130d 70%); }

.camera-switches { margin-top: 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.camera-button { padding: 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; text-align: left; }
.camera-button small { display: block; margin-top: 4px; color: var(--muted); }
.camera-button.active { color: #fff; border-color: var(--forest); background: var(--forest); }

.capture-grid { display: grid; gap: 12px; }
.capture-item { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(245,248,241,.75); }
.capture-title { display: flex; justify-content: space-between; gap: 8px; }
.capture-title h3 { margin: 0; font-size: 16px; }
.mode-tag { padding: 4px 7px; border-radius: 999px; color: var(--forest); background: rgba(31,91,58,.1); font-size: 10px; }
.field-row { margin: 14px 0; display: grid; grid-template-columns: 1fr 88px; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.field-row input { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.button-stack { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

button { min-height: 38px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
button:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(31,91,58,.35); }
button:disabled { opacity: .48; cursor: not-allowed; }
button.primary { color: #fff; border-color: var(--forest); background: var(--forest); }
a.primary-link { min-height: 38px; padding: 9px 16px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; color: #fff; background: var(--forest); text-decoration: none; }
button.danger-soft { color: var(--danger); border-color: rgba(184,74,58,.25); background: rgba(184,74,58,.06); }
button.quiet { min-height: 32px; padding: 6px 10px; background: transparent; }
button.wide { width: 100%; margin-top: 5px; }

.gallery-head { margin-bottom: 18px; }
.gallery-actions { display: flex; align-items: center; gap: 10px; }
.segmented { display: flex; padding: 3px; border-radius: 9px; background: #eef1e9; }
.segmented button { min-height: 32px; border: 0; background: transparent; }
.segmented button.active { color: #fff; background: var(--forest); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.photo-card { overflow: hidden; border: 1px solid var(--line); border-radius: 3px 14px 3px 14px; background: #fff; }
.photo-preview-trigger { width: 100%; min-height: 0; padding: 0; display: block; overflow: hidden; border: 0; border-radius: 0; background: #e7ebe5; cursor: zoom-in; }
.photo-preview-trigger:hover:not(:disabled) { transform: none; border-color: transparent; }
.photo-preview-trigger:focus-visible { outline: 3px solid rgba(31,91,58,.35); outline-offset: -3px; }
.photo-preview-trigger img { width: 100%; height: 180px; display: block; object-fit: cover; transition: transform .25s ease; }
.photo-preview-trigger:hover img { transform: scale(1.025); }
.photo-meta { padding: 13px; }
.photo-meta-head { display: flex; justify-content: space-between; gap: 8px; }
.photo-meta strong { font-size: 14px; }
.photo-time { color: var(--muted); font-size: 11px; }
.inference { min-height: 36px; margin: 10px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.empty-state { grid-column: 1 / -1; min-height: 320px; display: grid; place-items: center; text-align: center; border: 1px dashed rgba(31,91,58,.25); border-radius: 14px; background: rgba(244,247,239,.65); }
.empty-state strong { display: block; margin-bottom: 7px; font-size: 18px; }
.empty-state p { max-width: 420px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

.photo-dialog { width: min(1080px, calc(100vw - 32px)); max-width: none; padding: 0; border: 0; border-radius: 4px 18px 4px 18px; color: var(--ink); background: transparent; box-shadow: var(--shadow); }
.photo-dialog::backdrop { background: rgba(10, 29, 19, .78); backdrop-filter: blur(5px); }
.photo-dialog-shell { overflow: hidden; background: var(--paper); }
.photo-dialog-head { padding: 18px 20px; display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.photo-dialog-head h2 { margin: 2px 0 5px; font-size: 20px; }
.photo-dialog-head .sub { margin: 0; }
.photo-dialog-head .quiet { flex: 0 0 auto; white-space: nowrap; }
.photo-dialog-image { width: 100%; max-height: 72vh; display: block; object-fit: contain; background: #101712; }
.photo-dialog-actions { padding: 14px 20px; display: flex; justify-content: flex-end; border-top: 1px solid var(--line); }

.telemetry-list { display: grid; gap: 8px; margin-top: 16px; }
.telemetry-row { padding: 13px 15px; display: grid; grid-template-columns: 150px minmax(120px, 1fr) 110px 110px; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: rgba(249,250,246,.8); font-size: 12px; }
.telemetry-row time { color: var(--muted); }
.telemetry-row strong { font-size: 13px; }
.telemetry-value { color: var(--forest); font-weight: 700; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(380px, calc(100vw - 32px)); padding: 12px 16px; color: #fff; border-radius: 10px; background: var(--forest-deep); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #7d2e25; }

.site-footer {
  min-height: 48px;
  padding: 13px 20px;
  display: grid;
  place-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(247, 244, 236, .94);
  font-size: 12px;
  text-align: center;
}
.site-footer a { color: inherit; text-decoration: none; }
.site-footer a:hover, .site-footer a:focus-visible { color: var(--forest); text-decoration: underline; }

@media (max-width: 1050px) {
  .operation-grid { grid-template-columns: 1fr; }
  .capture-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 10; width: 100%; height: auto; padding: 10px 14px; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; }
  .brand-block { padding: 0; }
  .brand-block > div:last-child, .device-mini { display: none; }
  .brand-mark { width: 38px; height: 38px; }
  .tabs { display: flex; justify-content: flex-end; gap: 4px; }
  .tab-btn { width: auto; padding: 9px 10px; justify-content: center; font-size: 12px; }
  .tab-btn span, .tab-btn.active::after { display: none; }
  .topbar { min-height: 86px; padding: 16px; align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  #user-info { display: none; }
  .layout { padding: 16px 12px 32px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-card:first-child { grid-column: 1 / -1; }
  .capture-grid { grid-template-columns: 1fr; }
  .camera-switches { grid-template-columns: 1fr; }
  .gallery-head, .gallery-actions { display: grid; }
  .gallery-actions { width: 100%; }
  .segmented { overflow-x: auto; }
  .photo-dialog { width: calc(100vw - 20px); }
  .photo-dialog-head { padding: 14px; }
  .photo-dialog-image { max-height: 68vh; }
  .photo-dialog-actions { padding: 12px 14px; }
  .photo-dialog-actions .primary-link { width: 100%; }
  .telemetry-row { grid-template-columns: 1fr 1fr; }
}

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