/* Lugo Monitor — 延續原型的淺色、綠色主色、左側導覽。無外部 CDN。 */
:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-alt: #fbfcfb;
  --ink: #22332d;
  --muted: #6d7b74;
  --line: #e4eae6;
  --line-soft: #f0f3f1;
  --green: #21875e;
  --green-dark: #1a6e4c;
  --mint: #e6f4ec;
  --red: #c4483f;
  --red-bg: #fdecea;
  --amber: #a8741c;
  --amber-bg: #fff2d9;
  --blue: #2d6aa3;
  --blue-bg: #e8f0f8;
  --grey-bg: #eef1ef;
  --focus: #1f6feb;
  --radius: 12px;
  --radius-sm: 7px;
  --font-size: 14px;
  --font-small: 12px;
  --font-tiny: 11px;
  --sidebar: 222px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html { font: var(--font-size)/1.6 var(--font); color: var(--ink); }
body { margin: 0; background: var(--bg); }
a { color: var(--green); }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 20; }
.skip:focus { left: 8px; }

button, .button {
  cursor: pointer; border: 1px solid var(--line); background: var(--surface); padding: 7px 14px;
  border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .button:hover { border-color: var(--green); }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:hover { background: var(--green-dark); }
button.danger { color: var(--red); }
button.link { border: 0; background: none; color: var(--green); padding: 0; text-decoration: underline; }
button[disabled] { opacity: .55; cursor: not-allowed; }
button.block { width: 100%; justify-content: center; margin-top: 20px; }
button[data-state="pending"]::after { content: "…"; }

input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); max-width: 100%;
}
textarea { min-height: 84px; resize: vertical; width: 100%; }
label { display: block; margin: 14px 0 4px; font-weight: 600; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 10px 0; }
.hint { font-size: var(--font-small); color: var(--muted); margin-top: 3px; }
.field-error { color: var(--red); font-size: var(--font-small); margin-top: 3px; }
.form-error { background: var(--red-bg); color: var(--red); padding: 10px 12px; border-radius: var(--radius-sm); margin: 12px 0; }
form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
form input:not([type=checkbox]):not([type=radio]), form select, form textarea { width: 100%; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

/* 版面 */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--line);
  padding: 28px 18px; display: flex; flex-direction: column; overflow-y: auto;
}
.brand { font-size: 22px; font-weight: 750; letter-spacing: -1px; }
.brand b { color: var(--green); }
.brand span { font-weight: 400; }
.subtitle { font-size: var(--font-tiny); letter-spacing: 2px; color: var(--muted); margin-bottom: 30px; }
nav a {
  display: flex; gap: 10px; align-items: center; padding: 10px 14px; margin: 2px 0; color: #5f6d66; text-decoration: none; border-radius: var(--radius-sm);
}
nav a:hover { background: var(--surface-alt); color: var(--ink); }
nav a.active { background: var(--mint); color: var(--green); font-weight: 650; }
.aside-bottom { margin-top: auto; font-size: var(--font-small); color: var(--muted); padding-top: 20px; word-break: break-all; }
main { margin-left: var(--sidebar); padding: 22px 34px; max-width: 1700px; }
main:focus { outline: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 16px; font-size: var(--font-small); color: var(--muted); }
.env { font-size: var(--font-tiny); padding: 3px 9px; border-radius: 5px; background: var(--grey-bg); }
.env-development, .env-testing { background: var(--amber-bg); color: var(--amber); }
h1 { font-size: 26px; margin: 22px 0 3px; letter-spacing: -.6px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: var(--font-size); margin: 0 0 8px; }
p { margin: 0; color: var(--muted); }
.topline, .section-head, .tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topline { margin-bottom: 18px; }
.tools { flex-wrap: wrap; justify-content: flex-end; margin-top: 24px; }
.section-head { margin: 26px 0 14px; }
.footer { padding: 22px 0; color: var(--muted); font-size: var(--font-tiny); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.small { font-size: var(--font-small); color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--font-small); word-break: break-all; }
.good { color: var(--green); }
.bad { color: var(--red); }
.warn { color: var(--amber); }
.muted { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0; }
.stat-title { color: var(--muted); font-size: var(--font-small); }
.stat-number { font-size: 30px; font-weight: 700; margin: 6px 0; }
.stat-number .unit { font-size: var(--font-small); font-weight: 400; color: var(--muted); }
.alert-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.alert-list:empty { display: none; }
.alert-list > p { margin: 2px 0 0; }
.alert { display: flex; gap: 14px; align-items: center; background: #fff8ee; border: 1px solid #f0dfc3; border-radius: 9px; padding: 12px 16px; }
.alert.error { background: var(--red-bg); border-color: #f2c9c4; }
.alert.ok { background: var(--mint); border-color: #cbe6d6; }
.alert > .pill { min-width: 44px; justify-content: center; background: var(--surface); }
.alert-main { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; }
.alert-sub { color: var(--muted); font-size: var(--font-small); margin-top: 2px; }
.alert .button { flex-shrink: 0; }
.alert .grow { flex: 1; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 22px; }
.panel-body { padding: 18px; }
.table-tools { display: flex; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.table-tools input[type=search] { min-width: 260px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { font-size: var(--font-tiny); color: var(--muted); font-weight: 500; background: var(--surface-alt); padding: 10px 16px; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid var(--line-soft); font-size: 13px; vertical-align: top; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover, tbody tr.clickable:focus-within { background: #f8fbf9; }
.name { font-weight: 650; }
.name a { color: var(--ink); text-decoration: none; }
.name a:hover { text-decoration: underline; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }

/* 狀態：顏色 + 圖示 + 文字（不只靠色彩） */
.pill { display: inline-flex; gap: 4px; align-items: center; padding: 3px 8px; border-radius: 5px; font-size: var(--font-tiny); white-space: nowrap; }
.pill::before { font-size: 10px; }
.pill.ok { background: var(--mint); color: var(--green); }
.pill.ok::before { content: "●"; }
.pill.warning { background: var(--amber-bg); color: var(--amber); }
.pill.warning::before { content: "▲"; }
.pill.error { background: var(--red-bg); color: var(--red); }
.pill.error::before { content: "✕"; }
.pill.pending, .pill.unknown, .pill.stale, .pill.unconfigured, .pill.unsupported, .pill.disabled, .pill.info { background: var(--grey-bg); color: var(--muted); }
.pill.pending::before { content: "◌"; }
.pill.unknown::before, .pill.stale::before { content: "?"; }
.pill.unsupported::before, .pill.unconfigured::before, .pill.disabled::before { content: "–"; }
.pill.info { background: var(--blue-bg); color: var(--blue); }

.dims { display: flex; gap: 4px; flex-wrap: wrap; }
.uptime-bar { display: flex; gap: 2px; margin: 5px 0; }
.uptime-bar i { height: 18px; width: 5px; background: #d6ddd9; border-radius: 2px; }
.uptime-bar i.pass { background: #68bb93; }
.uptime-bar i.fail { background: #e57b70; }

.servers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.server-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.meter { height: 6px; border-radius: 3px; background: #edf1ee; margin: 6px 0 12px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--green); }
.meter i.warning { background: var(--amber); }
.meter i.critical { background: var(--red); }
.metric-label { display: flex; justify-content: space-between; font-size: var(--font-small); }
.services { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button[aria-pressed="true"] { background: var(--mint); border-color: var(--green); color: var(--green); }

.chart { width: 100%; height: 140px; display: block; }
.chart .axis { stroke: var(--line); }
.chart .lat { fill: none; stroke: var(--green); stroke-width: 1.5; }
.chart .bar-pass { fill: #9fd4b9; }
.chart .bar-fail { fill: #e57b70; }
.chart .bar-other { fill: #d6ddd9; }
.chart text { fill: var(--muted); font-size: 10px; }

.diff { background: var(--surface-alt); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; max-height: 360px; overflow: auto; white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: var(--font-small); }
.diff .add { background: #e6f4ec; color: #1a6e4c; display: block; }
.diff .del { background: #fdecea; color: #a03a33; display: block; text-decoration: line-through; }
.diff .ctx { display: block; color: var(--muted); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 14px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--green); }

.overlay { position: fixed; inset: 0; background: #17251d55; display: flex; justify-content: flex-end; z-index: 10; }
.drawer { width: 520px; max-width: 100%; background: var(--surface); padding: 26px 28px; overflow: auto; height: 100%; }
.drawer:focus { outline: none; }
.drawer .close { float: right; }
.detail-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 8px; z-index: 30; max-width: 90vw; }
.toast.error { background: var(--red); }
.empty, .loading, .error-box { padding: 36px; text-align: center; color: var(--muted); }
.error-box { color: var(--red); }
.secret-box { background: #fffbe8; border: 1px dashed var(--amber); padding: 12px; border-radius: var(--radius-sm); margin: 12px 0; }

.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 380px; max-width: 100%; }
.login-card h1 { font-size: 20px; margin-top: 0; }
.login-card input { width: 100%; }
.login-card .small { margin-top: 16px; }

@media (max-width: 1100px) {
  :root { --sidebar: 190px; }
  main { padding: 18px; }
  .servers, .grid-3 { grid-template-columns: 1fr 1fr; }
  .stats { gap: 10px; }
}
@media (max-width: 760px) {
  .sidebar { position: static; width: 100%; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .subtitle, .aside-bottom .small { display: none; }
  nav { display: flex; overflow-x: auto; gap: 2px; }
  nav a { white-space: nowrap; padding: 8px 10px; }
  .aside-bottom { display: flex; gap: 10px; align-items: center; padding-top: 8px; }
  main { margin: 0; padding: 14px 16px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .servers, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topline { flex-direction: column; align-items: flex-start; }
  .tools { justify-content: flex-start; margin-top: 8px; }
  .table-tools input[type=search] { min-width: 0; width: 100%; }
  table.responsive { min-width: 760px; }
  form .row { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
}

/* 收合式說明 */
details.note { margin: 10px 0; color: var(--muted); }
details.note summary { cursor: pointer; font-size: var(--font-small); color: var(--muted); }
details.note summary:hover { color: var(--green); }
details.note > div { margin-top: 6px; line-height: 1.7; }
.site-host { font-size: var(--font-small); color: var(--muted); }
.reason { font-size: var(--font-small); color: var(--muted); margin-top: 4px; }

a.stat-card { display: block; color: inherit; text-decoration: none; }
a.stat-card:hover { border-color: var(--green); }

.summary-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.tile { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions button { padding: 5px 10px; margin-left: 4px; }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, 1fr); } }

.legend i { display: inline-block; width: 10px; height: 3px; margin: 0 4px 3px 8px; vertical-align: middle; }
.legend i.c1 { background: #21875e; } .legend i.c2 { background: #2d6aa3; } .legend i.c3 { background: #a8741c; }

/* 可排序表頭 */
.sort-btn { border: 0; background: none; padding: 0; font: inherit; font-size: var(--font-tiny); color: var(--muted); display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.sort-btn:hover, .sort-btn.active { color: var(--ink); }
.sort-ind { font-size: 9px; opacity: .55; }
.sort-btn.active .sort-ind { opacity: 1; color: var(--green); }

/* ===== 試算表格線（客戶資料表） ===== */
.sheet { position: relative; overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); outline: none; }
.sheet:focus-visible { box-shadow: 0 0 0 2px var(--focus); }
.sheet-table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; min-width: 100%; }
.sheet-table col.rh { width: 44px; }
.sheet-table th, .sheet-table td { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 6px 8px; font-size: 13px; line-height: 1.45; vertical-align: top; text-align: left; white-space: pre-wrap; word-break: break-word; }
.sheet-table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-alt); color: var(--muted); font-weight: 500; font-size: var(--font-small); white-space: nowrap; }
.sheet-table th.rh, .sheet-table th.corner { position: sticky; left: 0; z-index: 1; background: var(--surface-alt); color: var(--muted); font-size: var(--font-tiny); text-align: center; font-weight: 400; }
.sheet-table th.corner { z-index: 3; }
.sheet-table td { cursor: cell; background: var(--surface); min-height: 30px; }
.sheet-table td.sel { box-shadow: inset 0 0 0 2px var(--focus); }
.sheet-table td.ro { color: var(--muted); }
.sheet-table td.bold { font-weight: 700; }
.sheet-table td.editing { color: transparent; }
.sheet-table td.secret::before { content: "🔒 "; font-size: 11px; }
.sheet-table td a { color: var(--green); }
.sheet-editor { position: absolute; z-index: 4; margin: 0; border: 0; border-radius: 0; padding: 6px 8px; font: inherit; font-size: 13px; line-height: 1.45; resize: none; background: var(--surface); box-shadow: 0 0 0 2px var(--focus), 0 4px 12px #0002; overflow: hidden; }
.sheet-editor.idle { opacity: 0; pointer-events: none; box-shadow: none; }
.sheet:focus-within { box-shadow: 0 0 0 2px var(--focus); }
.sheet-table tr.section td, .sheet-table tr.section th.rh { background: #c8d9ee; }
.sheet-table tr.section td { font-weight: 700; font-size: 15px; }
td.bg-pink, .swatch.bg-pink { background: #f4cccc !important; }
td.bg-yellow, .swatch.bg-yellow { background: #fff2cc !important; }
td.bg-green, .swatch.bg-green { background: #d9ead3 !important; }
td.bg-blue, .swatch.bg-blue { background: #cfe2f3 !important; }
td.bg-grey, .swatch.bg-grey { background: #e7e7e7 !important; }
.sheet-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.sheet-toolbar .grow { flex: 1; }
.color-bar { display: inline-flex; gap: 4px; align-items: center; }
.swatch { width: 24px; height: 24px; padding: 0; border-radius: 5px; justify-content: center; }
.save-state { font-size: var(--font-small); color: var(--muted); }
.save-state.error { color: var(--red); }
.ch-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: 4px; }
.ch-btn:hover { color: var(--ink); }
.name-cell { display: flex; justify-content: space-between; gap: 6px; }
.name-cell a { text-decoration: none; }
.col-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.col-row .tabs button { padding: 4px 8px; }

.ctx-menu { position: fixed; z-index: 40; min-width: 170px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 8px 24px #0002; padding: 4px; display: flex; flex-direction: column; }
.ctx-menu button { border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 5px; width: 100%; }
.ctx-menu button:hover, .ctx-menu button:focus { background: var(--mint); outline: none; }
.ctx-menu button.danger { color: var(--red); }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 0; }
