:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --text: #17201e;
  --muted: #65706d;
  --line: #dce2e0;
  --accent: #176b57;
  --accent-soft: #e2f0eb;
  --danger: #b33b43;
  --shadow: 0 14px 36px rgba(24, 42, 37, .08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121716;
  --surface: #1b2220;
  --surface-2: #242c2a;
  --text: #eff4f2;
  --muted: #9ca8a4;
  --line: #303a37;
  --accent: #67bda4;
  --accent-soft: #19382f;
  --danger: #ee858b;
  --shadow: 0 18px 44px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.app-shell { width: min(1180px, calc(100% - 48px)); margin: 0 auto; min-height: 100vh; }

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }
.brand-mark { width: 34px; height: 34px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 5px; background: var(--text); border-radius: 7px; }
.brand-mark i { display: block; background: var(--bg); border-radius: 1px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { opacity: .55; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.health { height: 34px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.health i { width: 7px; height: 7px; background: #2a9c65; border-radius: 50%; box-shadow: 0 0 0 4px rgba(42, 156, 101, .12); }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: 18px; }
.icon-button:hover { border-color: var(--muted); background: var(--surface-2); }

.intro { min-height: 164px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 34px 0 28px; }
.eyebrow { margin: 0 0 9px; color: var(--accent); font: 700 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 1.6px; }
.intro h1 { margin: 0; font-size: clamp(32px, 4vw, 46px); line-height: 1.08; letter-spacing: 0; }
.intro > div > p:last-child { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.clock { display: grid; justify-items: end; margin-bottom: 3px; }
.clock strong { font: 500 30px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.clock span { margin-top: 7px; color: var(--muted); font-size: 12px; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.summary div { min-height: 74px; display: flex; flex-direction: column; justify-content: center; padding: 14px 20px; border-right: 1px solid var(--line); }
.summary div:last-child { border-right: 0; }
.summary span { color: var(--muted); font-size: 11px; }
.summary strong { margin-top: 4px; font: 600 21px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.directory { padding: 28px 0 44px; }
.tools { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
.search { width: min(420px, 100%); height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.search > span { color: var(--muted); font-size: 20px; }
.search input { min-width: 0; flex: 1; color: var(--text); background: transparent; border: 0; outline: 0; font-size: 13px; }
.search input::placeholder { color: var(--muted); }
kbd { padding: 2px 6px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; font: 11px ui-monospace, monospace; }
.filters { display: flex; gap: 4px; padding: 4px; overflow-x: auto; background: var(--surface-2); border-radius: 7px; }
.filter-button { min-width: max-content; height: 32px; padding: 0 12px; color: var(--muted); background: transparent; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px; }
.filter-button:hover { color: var(--text); }
.filter-button.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.section-heading { min-height: 66px; display: flex; align-items: center; justify-content: space-between; }
.section-heading > div { display: flex; align-items: baseline; gap: 9px; }
.section-heading h2 { margin: 0; font-size: 15px; }
.section-heading span { color: var(--muted); font-size: 11px; }
.draft-badge { padding: 5px 8px; color: #8a6410 !important; background: #fff2c6; border-radius: 4px; }

.service-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.service-card { min-height: 188px; display: flex; flex-direction: column; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.service-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--service-color) 45%, var(--line)); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.service-icon { width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center; color: #fff; background: var(--service-color); border-radius: 7px; font: 700 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
.service-status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.service-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #899390; }
.service-status.online::before { background: #2a9c65; }
.service-status.warning::before { background: #d99a2b; }
.service-status.offline::before { background: #cc4e56; }
.card-body { margin-top: 14px; }
.card-meta { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; }
.scope { padding: 2px 5px; background: var(--surface-2); border-radius: 3px; }
.card-body h3 { margin: 6px 0 0; font-size: 17px; }
.card-body p { min-height: 34px; margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 15px; border-top: 1px solid var(--line); }
.address { min-width: 0; flex: 1; overflow: hidden; color: var(--muted); font: 10px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.card-action { width: 30px; height: 30px; display: inline-grid; place-items: center; flex: 0 0 auto; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 5px; text-decoration: none; cursor: pointer; }
.card-action:hover { color: var(--text); background: var(--surface-2); }
.card-action.disabled { opacity: .35; pointer-events: none; }
.empty { min-height: 220px; display: grid; place-content: center; justify-items: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }
.empty strong { color: var(--text); font-size: 14px; }
.empty span { margin-top: 6px; font-size: 12px; }
footer { min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; padding: 18px 0; color: var(--muted); border-top: 1px solid var(--line); font-size: 11px; }
.footer-meta, .footer-records { display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap; }
.footer-meta span + span::before { content: "·"; margin-right: 18px; color: var(--line); }
footer a { color: inherit; text-decoration: none; }
footer a:hover, footer a:focus-visible { color: var(--text); text-decoration: underline; }
.police-record { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.police-record img { width: 20px; height: 20px; flex: 0 0 20px; object-fit: contain; }

.modal { width: min(520px, calc(100% - 32px)); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 30px 80px rgba(0, 0, 0, .3); }
.modal::backdrop { background: rgba(12, 18, 16, .6); backdrop-filter: blur(4px); }
.lock-modal form { padding: 24px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-copy { margin: 10px 0 20px; color: var(--muted); font-size: 12px; }
.field { display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 11px; }
.field input, .field select, .field textarea { width: 100%; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; outline: 0; padding: 10px 11px; font-size: 13px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.field textarea { resize: vertical; }
#confirmPinField { margin-top: 14px; }
.form-error { min-height: 17px; margin: 9px 0; color: var(--danger); font-size: 11px; }
.primary-button, .secondary-button, .danger-button { min-height: 38px; padding: 0 14px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.primary-button { color: #fff; background: var(--accent); border: 1px solid var(--accent); }
.secondary-button { color: var(--text); background: var(--surface); border: 1px solid var(--line); }
.danger-button { color: var(--danger); background: transparent; border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line)); }
.lock-modal .primary-button { width: 100%; }

.editor-modal { width: min(1040px, calc(100% - 32px)); }
.editor-layout { min-height: 650px; display: grid; grid-template-columns: 300px 1fr; }
.editor-sidebar { display: flex; flex-direction: column; gap: 14px; padding: 22px; background: var(--bg); border-right: 1px solid var(--line); }
.editor-list { display: grid; gap: 6px; overflow-y: auto; max-height: 430px; }
.editor-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; color: var(--text); text-align: left; background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.editor-item:hover { background: var(--surface); }
.editor-item.active { background: var(--surface); border-color: var(--line); }
.editor-item i { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; background: var(--item-color); border-radius: 5px; font: 700 9px ui-monospace, monospace; font-style: normal; }
.editor-item span { min-width: 0; display: grid; gap: 2px; }
.editor-item strong, .editor-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-item strong { font-size: 12px; }
.editor-item small { color: var(--muted); font-size: 10px; }
.editor-imports { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: auto; }
.editor-imports .wide-button { grid-column: 1 / -1; }
.editor-form { padding: 28px; }
.form-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 25px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.form-heading span { color: var(--muted); font-size: 10px; }
.form-heading h3 { margin: 3px 0 0; font-size: 20px; }
.security-chip { padding: 5px 8px; color: var(--accent) !important; background: var(--accent-soft); border-radius: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field.wide { grid-column: 1 / -1; }
.form-actions { display: grid; grid-template-columns: auto 1fr auto auto; gap: 9px; align-items: center; margin-top: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; transform: translate(-50%, 20px); padding: 9px 13px; color: #fff; background: #1c2925; border-radius: 6px; opacity: 0; pointer-events: none; transition: .2s ease; font-size: 11px; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 900px) {
  .service-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tools { align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
  .filters { width: 100%; }
  .editor-layout { grid-template-columns: 240px 1fr; }
}

@media (max-width: 680px) {
  .app-shell { width: min(100% - 28px, 1180px); }
  .health { display: none; }
  .intro { min-height: 150px; align-items: flex-start; flex-direction: column; justify-content: center; padding: 28px 0 24px; }
  .clock { display: none; }
  .summary { grid-template-columns: 1fr 1fr; }
  .summary div { min-height: 72px; border-bottom: 1px solid var(--line); }
  .summary div:nth-child(2) { border-right: 0; }
  .summary div:nth-child(n+3) { border-bottom: 0; }
  .service-grid { grid-template-columns: 1fr; }
  .editor-modal { max-height: calc(100vh - 20px); overflow-y: auto; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-list { max-height: 180px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
  .form-actions { grid-template-columns: 1fr 1fr; }
  .form-actions span { display: none; }
  .form-actions button { width: 100%; }
  footer { min-height: 104px; padding: 20px 0; text-align: center; }
  .footer-meta, .footer-records { gap: 8px 14px; }
  .footer-meta span + span::before { margin-right: 14px; }
}

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