:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #202522;
  background: #f3f5f4;
  font-synthesis: none;
  --green: #167a51;
  --green-dark: #0d5b3a;
  --green-soft: #e7f4ed;
  --ink: #202522;
  --muted: #69716c;
  --line: #d9dfdb;
  --panel: #ffffff;
  --sidebar: #202724;
  --danger: #b63636;
  --warning: #9a650d;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f3f5f4; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #e9efeb; }
.login-panel { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 34px; box-shadow: 0 18px 55px rgba(23, 43, 32, .12); }
.login-brand, .brand { display: flex; align-items: center; gap: 12px; }
.login-brand { margin-bottom: 30px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 38px; border-radius: 7px; background: var(--green); color: white; font-weight: 800; font-size: 20px; }
.login-brand h1 { margin: 0; font-size: 23px; }
.login-brand p, .brand small { margin: 4px 0 0; color: var(--muted); }
.stack-form, .dialog-form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-size: 14px; font-weight: 600; color: #424944; }
input, select, textarea { width: 100%; min-height: 42px; border: 1px solid #cbd3ce; border-radius: 5px; background: #fff; color: var(--ink); padding: 9px 11px; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 122, 81, .12); }
.form-error { min-height: 20px; margin: -4px 0 0; color: var(--danger); font-size: 13px; font-weight: 600; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 224px; display: flex; flex-direction: column; background: var(--sidebar); color: #eef4f0; border-right: 1px solid #151a18; }
.brand { height: 68px; padding: 0 18px; border-bottom: 1px solid #343d39; }
.brand strong, .brand small { display: block; }
.brand small { color: #9eaaa4; font-size: 11px; }
.main-nav { padding: 14px 10px; display: grid; gap: 4px; }
.nav-item { height: 42px; border: 0; border-radius: 5px; padding: 0 13px; text-align: left; color: #c9d2cd; background: transparent; font-weight: 600; }
.nav-item:hover { background: #2c3531; color: white; }
.nav-item.active { background: #e9f5ee; color: var(--green-dark); }
.sidebar-foot { margin-top: auto; padding: 16px 18px 20px; border-top: 1px solid #343d39; display: grid; gap: 6px; }
.role-badge { width: fit-content; color: #8ed5b1; font-size: 12px; }
.workspace { grid-column: 2; min-width: 0; }
.topbar { height: 68px; position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 0 24px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.balance-pill { min-height: 32px; display: flex; align-items: center; padding: 0 11px; border-radius: 16px; color: var(--green-dark); background: var(--green-soft); font-size: 13px; font-weight: 700; white-space: nowrap; }
.content { padding: 24px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.btn { min-height: 38px; border: 1px solid transparent; border-radius: 5px; padding: 8px 14px; font-weight: 700; color: #303632; background: white; }
.btn.primary { color: white; background: var(--green); border-color: var(--green); }
.btn.primary:hover { background: var(--green-dark); }
.btn.quiet { border-color: #cbd3ce; background: #fff; }
.btn.quiet:hover { border-color: #8f9a94; }
.btn.danger { color: var(--danger); border-color: #e6bbbb; background: #fff7f7; }
.btn.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 5px; display: grid; place-items: center; background: transparent; color: inherit; font-size: 22px; }
.icon-btn:hover { background: #edf1ef; }
.mobile-only { display: none; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { min-height: 112px; padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 14px; font-size: 28px; line-height: 1; }
.metric small { display: block; margin-top: 8px; color: #8b938e; }
.section-block, .view:not(#view-dashboard) { border: 1px solid var(--line); border-radius: 7px; background: var(--panel); padding: 20px; }
.section-head { display: flex; align-items: center; gap: 16px; justify-content: space-between; margin-bottom: 18px; }
.section-head h3 { margin: 0; font-size: 17px; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.status-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--line); }
.status-item { min-height: 80px; display: grid; align-content: center; gap: 8px; padding: 14px; background: #fff; }
.status-item span { color: var(--muted); font-size: 12px; }
.status-item strong { font-size: 20px; }

.filters { display: grid; grid-template-columns: minmax(220px, 1fr) 160px 180px auto; gap: 10px; margin-bottom: 14px; }
.inline-controls { display: flex; gap: 8px; align-items: center; }
.inline-controls select { min-width: 180px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; min-width: 760px; border-collapse: collapse; background: white; }
th, td { padding: 12px 13px; border-bottom: 1px solid #e7ebe8; text-align: left; font-size: 13px; vertical-align: middle; }
th { color: #5c655f; background: #f6f8f7; font-size: 12px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfb; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 190px; }
.select-cell { width: 42px; min-width: 42px; text-align: center; }
.select-cell input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--green); }
.mono { font-family: Consolas, monospace; font-size: 12px; white-space: nowrap; }
.status { display: inline-flex; align-items: center; min-height: 25px; border-radius: 13px; padding: 3px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.ok { color: #10623f; background: #e5f4ec; }
.status.warn { color: #825207; background: #fff2d5; }
.status.bad { color: #9b2f2f; background: #fde9e9; }
.status.neutral { color: #5d655f; background: #edf0ee; }
.empty-state { padding: 52px 20px; text-align: center; color: var(--muted); border: 1px dashed #cbd3ce; border-radius: 6px; }
.positive { color: var(--green); font-weight: 700; }
.negative { color: var(--danger); font-weight: 700; }

dialog { width: min(620px, calc(100vw - 28px)); max-height: calc(100vh - 36px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 0; color: var(--ink); box-shadow: 0 24px 80px rgba(16, 27, 21, .25); }
dialog::backdrop { background: rgba(17, 25, 21, .56); }
.dialog-form { padding: 22px; }
.compact-dialog { max-width: 480px; }
.config-dialog { width: min(760px, calc(100vw - 28px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.dialog-head h3 { margin: 0; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 4px; }
.dialog-context { margin: -2px 0 0; color: var(--muted); font-size: 13px; }
.form-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: 1 / -1; }
.toggle-row { grid-template-columns: auto 1fr; align-items: center; justify-content: start; }
.toggle-row input { width: 18px; min-height: 18px; }
.config-section { display: grid; gap: 13px; padding-top: 4px; }
.config-section + .config-section { padding-top: 17px; border-top: 1px solid var(--line); }
.config-section h4 { margin: 0; font-size: 14px; }
.fixed-security { display: flex; flex-wrap: wrap; gap: 8px; }
.fixed-security span { padding: 7px 10px; border-radius: 4px; color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 700; }
.cards-dialog textarea { font-family: Consolas, monospace; line-height: 1.7; }
.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: min(420px, calc(100vw - 32px)); transform: translateY(20px); opacity: 0; pointer-events: none; padding: 12px 15px; border-radius: 6px; color: white; background: #27312c; box-shadow: 0 10px 30px rgba(0,0,0,.2); transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #9d3333; }
.sidebar-overlay { display: none; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .btn { width: fit-content; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; z-index: 19; inset: 0; display: none; background: rgba(17,25,21,.48); }
  .sidebar-overlay.open { display: block; }
  .workspace { min-width: 0; }
  .mobile-only { display: grid; }
  .topbar { height: 62px; padding: 0 14px; }
  .topbar p { display: none; }
  .balance-pill { display: none; }
  .content { padding: 14px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { min-height: 98px; padding: 14px; }
  .metric strong { font-size: 24px; }
  .status-grid { grid-template-columns: 1fr 1fr; }
  .section-block, .view:not(#view-dashboard) { padding: 14px; }
  .section-head { align-items: flex-start; }
  .filters { grid-template-columns: 1fr; }
  .inline-controls { width: 100%; flex-wrap: wrap; }
  .inline-controls select { min-width: 0; flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .login-panel { padding: 26px 22px; }
}

@media (max-width: 420px) {
  .metric-grid { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: 1fr; }
  .section-head { flex-direction: column; }
  .section-head > .btn { width: 100%; }
}
