/* ═══════════════════════════════════════════════════════════════
   imtan-ops 面板样式
   深色为默认，跟随系统偏好，也可手动切换。
   不引入任何外部字体 / CSS 框架 —— 一方面 CSP 只允许 'self'，
   另一方面这台机器不需要为一条管理面板拉几十 KB 的 CDN 资源。
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg:        #0a0e14;
  --bg-soft:   #0e1420;
  --bg-elev:   #121a26;
  --bg-elev-2: #172231;
  --border:    #1f2b3a;
  --border-2:  #2a3949;
  --text:      #e3ecf7;
  --text-2:    #9fb0c4;
  --text-3:    #6b7c91;
  --accent:    #2fd6a5;
  --accent-dim:#1a7f66;
  --blue:      #5b9dff;
  --warn:      #f5b544;
  --crit:      #ff5c68;
  --ok:        #2fd6a5;
  --shadow:    0 8px 32px rgba(0, 0, 0, .45);
  --radius:    12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

[data-theme="light"] {
  --bg:        #f4f7fb;
  --bg-soft:   #eef3f9;
  --bg-elev:   #ffffff;
  --bg-elev-2: #f7f9fc;
  --border:    #dde5ef;
  --border-2:  #c9d4e2;
  --text:      #14202e;
  --text-2:    #4d6076;
  --text-3:    #7a8ca1;
  --accent:    #0f9f7a;
  --accent-dim:#0b7a5e;
  --blue:      #2563eb;
  --warn:      #b7791f;
  --crit:      #d92d3a;
  --ok:        #0f9f7a;
  --shadow:    0 8px 30px rgba(20, 32, 46, .10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* hidden 必须压得住 #login / #app 的 display:flex，否则登录层会一直盖在面板上 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: var(--accent-dim); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ───────────────────────── 登录 ───────────────────────── */

#login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 600px at 50% -10%, rgba(47, 214, 165, .10), transparent 60%),
    radial-gradient(800px 500px at 100% 110%, rgba(91, 157, 255, .08), transparent 55%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 26px;
  box-shadow: var(--shadow);
}

.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-brand .dot {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #1f8f74);
  display: grid; place-items: center; font-weight: 700; color: #04120e; font-size: 15px;
}
.login-brand h1 { font-size: 17px; font-weight: 650; letter-spacing: .01em; }
.login-sub { color: var(--text-3); font-size: 12.5px; margin-bottom: 24px; font-family: var(--mono); }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; color: var(--text-2);
  margin-bottom: 6px; font-weight: 550; letter-spacing: .02em;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(47, 214, 165, .12);
}
.field .hint { font-size: 11.5px; color: var(--text-3); margin-top: 6px; }
.field .hint.warn { color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 550; font-size: 13px;
  transition: background .15s, border-color .15s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: var(--border); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, #33e0ae, #23b98c);
  border-color: #1d9d78; color: #03150f; font-weight: 650;
}
.btn.primary:hover { background: linear-gradient(180deg, #3ae9b6, #26c495); }
.btn.danger { color: var(--crit); border-color: rgba(255, 92, 104, .35); }
.btn.danger:hover { background: rgba(255, 92, 104, .12); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ───────────────────────── 布局 ───────────────────────── */

#app { display: flex; height: 100vh; }

.sidebar {
  width: 224px; flex: 0 0 224px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .dot {
  width: 28px; height: 28px; border-radius: 8px; flex: 0 0 28px;
  background: linear-gradient(135deg, var(--accent), #1f8f74);
  display: grid; place-items: center; font-weight: 700; color: #04120e; font-size: 14px;
}
.brand .txt { min-width: 0; }
.brand .txt b { display: block; font-size: 13.5px; font-weight: 650; letter-spacing: .01em; }
.brand .txt span { display: block; font-size: 10.5px; color: var(--text-3); font-family: var(--mono); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-size: 13px; font-weight: 500;
  text-decoration: none; transition: background .12s, color .12s;
}
.nav a svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: .8; }
.nav a:hover { background: var(--bg-elev); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg-elev-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav a.active svg { opacity: 1; color: var(--accent); }
.nav .badge {
  margin-left: auto; font-size: 10.5px; font-family: var(--mono);
  padding: 1px 6px; border-radius: 20px; background: var(--border); color: var(--text-2);
}
.nav .badge.crit { background: rgba(255, 92, 104, .18); color: var(--crit); }
.nav .badge.warn { background: rgba(245, 181, 68, .18); color: var(--warn); }

.side-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px; margin-top: 8px;
  font-size: 11.5px; color: var(--text-3); font-family: var(--mono);
  display: flex; flex-direction: column; gap: 6px;
}
.side-foot .row { display: flex; justify-content: space-between; gap: 8px; }
.side-foot .row span:last-child { color: var(--text-2); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px; flex: 0 0 56px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.topbar h2 { font-size: 15px; font-weight: 620; }
.topbar .sub { color: var(--text-3); font-size: 12px; font-family: var(--mono); }
.topbar .spacer { flex: 1; }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-3); font-family: var(--mono);
}
.live .pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(47, 214, 165, .55); animation: pulse 2.4s infinite;
}
.live.stale .pulse { background: var(--warn); animation: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(47, 214, 165, .5); }
  70%  { box-shadow: 0 0 0 8px rgba(47, 214, 165, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 214, 165, 0); }
}

.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 8px; border: 1px solid var(--border); background: transparent;
  cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.view { flex: 1; overflow-y: auto; padding: 22px; }
.view-inner { max-width: 1320px; margin: 0 auto; }

/* ───────────────────────── 通用块 ───────────────────────── */

.grid { display: grid; gap: 14px; }
.g-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }

@media (max-width: 1200px) {
  .g-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .g-6, .g-4, .g-3, .g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.card-head h3 { font-size: 13px; font-weight: 620; color: var(--text); letter-spacing: .01em; }
.card-head .spacer { flex: 1; }
.card-head .meta { font-size: 11.5px; color: var(--text-3); font-family: var(--mono); }

.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-3); font-weight: 650; margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* KPI */
.kpi { position: relative; overflow: hidden; }
.kpi .label { font-size: 11.5px; color: var(--text-3); font-weight: 550; letter-spacing: .03em; }
.kpi .value {
  font-size: 26px; font-weight: 620; font-family: var(--mono);
  line-height: 1.2; margin-top: 4px; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi .value.long { font-size: 20px; letter-spacing: -.03em; }
.kpi .value small { font-size: 13px; color: var(--text-3); font-weight: 500; margin-left: 2px; }
.kpi .foot { font-size: 11.5px; color: var(--text-3); margin-top: 6px; font-family: var(--mono); }
.kpi .spark { position: absolute; right: 0; bottom: 0; left: 0; height: 34px; opacity: .5; pointer-events: none; }
.kpi .spark path { fill: none; stroke-width: 1.5; }
.kpi.warn .value { color: var(--warn); }
.kpi.crit .value { color: var(--crit); }

.bar {
  height: 5px; border-radius: 3px; background: var(--border);
  overflow: hidden; margin-top: 10px;
}
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s; }
.bar > i.warn { background: var(--warn); }
.bar > i.crit { background: var(--crit); }

/* 状态点 */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 550; font-family: var(--mono);
  border: 1px solid transparent; white-space: nowrap;
}
.pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok      { color: var(--ok);      background: rgba(47,214,165,.10); border-color: rgba(47,214,165,.22); }
.pill.warn    { color: var(--warn);    background: rgba(245,181,68,.10); border-color: rgba(245,181,68,.24); }
.pill.crit    { color: var(--crit);    background: rgba(255,92,104,.10); border-color: rgba(255,92,104,.24); }
.pill.down    { color: var(--crit);    background: rgba(255,92,104,.10); border-color: rgba(255,92,104,.24); }
.pill.degraded{ color: var(--warn);    background: rgba(245,181,68,.10); border-color: rgba(245,181,68,.24); }
.pill.stopped { color: var(--text-3);  background: var(--bg-elev-2);     border-color: var(--border-2); }
.pill.unknown { color: var(--text-3);  background: transparent;          border-color: var(--border-2); }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 6px;
  font-size: 11px; font-family: var(--mono); color: var(--text-2);
  background: var(--bg-elev-2); border: 1px solid var(--border);
}

/* 表格 */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); font-weight: 620; padding: 10px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--bg-elev); z-index: 1;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: var(--bg-elev-2); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl .mono { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.tbl .muted { color: var(--text-3); }
.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty {
  padding: 36px 20px; text-align: center; color: var(--text-3); font-size: 13px;
}

/* 服务卡片 */
.svc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: 10px; }
.svc {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; cursor: pointer;
  transition: border-color .15s, transform .1s;
  border-left: 2px solid var(--border-2);
}
.svc:hover { border-color: var(--border-2); transform: translateY(-1px); }
.svc.ok      { border-left-color: var(--ok); }
.svc.warn, .svc.degraded { border-left-color: var(--warn); }
.svc.crit, .svc.down { border-left-color: var(--crit); }
.svc.stopped, .svc.unknown { border-left-color: var(--border-2); }
.svc .top { display: flex; align-items: center; gap: 8px; }
.svc .name { font-weight: 600; font-size: 13px; flex: 1; min-width: 0;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc .role { font-size: 11.5px; color: var(--text-3); margin-top: 3px;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc .foot { display: flex; align-items: center; gap: 6px; margin-top: 8px;
             font-size: 11px; color: var(--text-3); font-family: var(--mono); }

/* 图表 */
.chart-wrap { position: relative; }
.chart { width: 100%; height: 132px; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; opacity: .65; }
.chart .axis { fill: var(--text-3); font-size: 9.5px; font-family: var(--mono); }
.chart .line { fill: none; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .13; }

/* 日志 */
.log-box {
  background: #070b11; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; max-height: 60vh; overflow: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word; color: #b6c6d8;
}
[data-theme="light"] .log-box { background: #f8fafc; color: #33413a; }
.log-box .ln { display: block; }
.log-box .ln.err { color: #ff8b93; }
.log-box .ln.warn { color: #f0c060; }
.log-box mark { background: rgba(91, 157, 255, .28); color: inherit; border-radius: 2px; }

/* 抽屉 / 弹窗 */
.overlay {
  position: fixed; inset: 0; background: rgba(4, 8, 12, .6);
  backdrop-filter: blur(2px); z-index: 60;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(640px, 100%); height: 100%; overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--border);
  padding: 22px; animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }

.modal-wrap { align-items: center; justify-content: center; }
.modal {
  width: min(520px, 100%); background: var(--bg-elev);
  border: 1px solid var(--border-2); border-radius: 14px;
  padding: 22px; box-shadow: var(--shadow);
}
.modal h3 { font-size: 15px; margin-bottom: 6px; }
.modal p { color: var(--text-2); font-size: 13px; margin-bottom: 16px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.drawer-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 18px; }
.drawer-head h2 { font-size: 17px; font-weight: 650; }
.drawer-head .sub { color: var(--text-3); font-size: 12px; font-family: var(--mono); }
.drawer-head .spacer { flex: 1; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); font-size: 12px; padding-top: 1px; }
.kv dd { color: var(--text); word-break: break-word; }
.kv dd.mono { font-family: var(--mono); font-size: 12px; }

.note {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 2px solid var(--blue); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 12.5px; color: var(--text-2); margin-top: 12px;
}
.note.warn { border-left-color: var(--warn); }
.note.crit { border-left-color: var(--crit); }

/* Toast */
#toast { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 240px; max-width: 420px;
  background: var(--bg-elev-2); border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; font-size: 13px;
  box-shadow: var(--shadow); animation: toastIn .18s ease-out;
}
.toast.err { border-left-color: var(--crit); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 杂项 */
.mono { font-family: var(--mono); }
.muted { color: var(--text-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy {
  font-family: var(--mono); font-size: 12px; background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
  word-break: break-all; cursor: pointer; position: relative;
}
.copy:hover { border-color: var(--accent-dim); }

.seg { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--border);
       border-radius: 8px; padding: 2px; gap: 2px; }
.seg button {
  background: transparent; border: none; padding: 5px 12px; border-radius: 6px;
  font-size: 12px; color: var(--text-2); cursor: pointer; font-weight: 550;
}
.seg button.active { background: var(--bg-elev-2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }

.check { display: flex; align-items: flex-start; gap: 8px; padding: 7px 0; font-size: 13px; }
.check input { margin-top: 3px; accent-color: var(--accent); }

.skeleton {
  background: linear-gradient(90deg, var(--bg-elev-2) 25%, var(--border) 50%, var(--bg-elev-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.loading-line { height: 3px; background: var(--border); overflow: hidden; border-radius: 2px; }
.loading-line i { display: block; height: 100%; width: 30%; background: var(--accent);
                  animation: slideBar 1.1s infinite ease-in-out; }
@keyframes slideBar { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
