/* =====================================================================
 * main.css — 電信 IPAM Demo 共用深色 NOC 主題
 * 配色比照 mockups/01-topology-lenses.html
 * 後續所有頁面（index.html、pages/*.html）共用此檔。
 *
 * 使用方式：
 *   index.html（根目錄）：  <link rel="stylesheet" href="assets/css/main.css">
 *   pages/*.html        ：  <link rel="stylesheet" href="../assets/css/main.css">
 * ===================================================================== */

:root {
  /* 底色 / 面板 / 線條 */
  --bg: #0d1117;          /* 全站背景 */
  --panel: #161b22;       /* 側欄、topbar、卡片面板 */
  --panel2: #1c2230;      /* 次層面板（hover、active 區塊、巢狀） */
  --line: #2d3650;        /* 邊框 / 分隔線 */
  /* 文字 */
  --txt: #e6edf3;         /* 主要文字 */
  --muted: #8b98a9;       /* 次要 / 說明文字 */
  /* 主色 / 狀態色 */
  --accent: #3b82f6;      /* 路由 / 核心 / 連結 active（藍） */
  --green: #22c55e;       /* 使用中 active */
  --amber: #f59e0b;       /* 保留 reserved */
  --red: #ef4444;         /* 衝突 conflict */
  --gray: #6b7280;        /* 廢棄 deprecated / 可用 free */
  --purple: #a855f7;      /* 網段 prefix */
  --cyan: #06b6d4;        /* 強調點綴 */
  /* 尺寸 */
  --side-w: 220px;
  --topbar-h: 52px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }

/* =====================================================================
 * 版面 LAYOUT
 *  .app    — 整頁 grid：左側欄 + 主區，上方 topbar 橫跨兩欄
 *  .topbar — 上方 52px 全域列（logo + 搜尋 + 資料說明）
 *  .logo   — 品牌字（Tele 白 + IPAM 藍）
 *  .search — topbar 內的全域搜尋框
 *  .side   — 左側欄容器
 *  .nav    — 導覽連結群組（內含 a，active 連結加 .active）
 *  .main   — 右側主內容捲動區
 * ===================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
}

.topbar {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; letter-spacing: .5px; font-size: 16px; white-space: nowrap; }
.logo span { color: var(--accent); }

.topbar .search {
  flex: 1;
  max-width: 460px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  color: var(--txt);
  font-size: 13px;
  outline: none;
}
.topbar .search::placeholder { color: var(--muted); }
.topbar .search:focus { border-color: var(--accent); }
.topbar .dataset-info { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 側欄 / 導覽 */
.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px 8px;
  overflow: auto;
}
.nav-group {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 14px 10px 6px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  color: var(--txt);
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 0;
  font-size: 13px;
}
.nav a.active { background: var(--accent); color: #fff; }
.nav a.active .dot { background: #fff !important; }
.nav a:hover:not(.active) { background: var(--panel2); }
.nav.disabled { opacity: .5; }
.nav.disabled a { cursor: not-allowed; pointer-events: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }

.main { padding: 18px 22px; overflow: auto; }

/* =====================================================================
 * 頁首  .page-head / .page-head h1
 * ===================================================================== */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; font-weight: 600; }
.page-head .sub { color: var(--muted); font-size: 13px; }

/* =====================================================================
 * 卡片 / 指標卡  .card  .metric  .metric-grid
 *  .card        — 通用面板容器
 *  .card-title  — 卡片標題列
 *  .metric-grid — 指標卡網格容器
 *  .metric      — 單張指標卡（.value 數字 / .label 說明）
 *  .metric.accent/.green/.amber/.red/.purple — 強調左邊色條
 * ===================================================================== */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: var(--txt); }
.card-title .sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.metric .value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.metric .label { color: var(--muted); font-size: 12px; margin-top: 6px; }
.metric .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.metric.accent { border-left-color: var(--accent); }
.metric.green  { border-left-color: var(--green); }
.metric.amber  { border-left-color: var(--amber); }
.metric.red    { border-left-color: var(--red); }
.metric.purple { border-left-color: var(--purple); }
.metric.cyan   { border-left-color: var(--cyan); }

/* =====================================================================
 * 表格  .table
 *  深色表格、表頭固定樣式、hover 高亮列、可點列 .clickable、選中列 .selected
 *  巢狀縮排用 .indent-1 / .indent-2（網段樹）
 * ===================================================================== */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.table th, table.table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.table thead th {
  background: var(--panel2);
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: default;
}
table.table thead th.sortable { cursor: pointer; }
table.table thead th.sortable:hover { color: var(--txt); }
table.table tbody tr:hover { background: var(--panel2); }
table.table tbody tr.clickable { cursor: pointer; }
table.table tbody tr.selected { background: #1e2a4a; }
table.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.table td.mono, table.table .mono { font-family: "Consolas", "Courier New", monospace; }
.indent-1 { padding-left: 26px !important; }
.indent-2 { padding-left: 46px !important; }
.tree-toggle { cursor: pointer; user-select: none; color: var(--muted); margin-right: 6px; }

/* =====================================================================
 * 徽章 / 狀態標籤  .badge  .badge.status-*
 *  .status-active    使用中（綠）
 *  .status-reserved  保留（琥珀）
 *  .status-deprecated 廢棄（灰）
 *  .status-conflict  衝突（紅）
 *  另有 .badge.role-* 給角色/類型用中性色
 * ===================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.status-active     { color: var(--green);  background: rgba(34,197,94,.12);  border-color: rgba(34,197,94,.35); }
.badge.status-reserved   { color: var(--amber);  background: rgba(245,158,11,.12);  border-color: rgba(245,158,11,.35); }
.badge.status-deprecated { color: var(--gray);   background: rgba(107,114,128,.15); border-color: rgba(107,114,128,.4); }
.badge.status-conflict   { color: var(--red);    background: rgba(239,68,68,.14);   border-color: rgba(239,68,68,.4); }
.badge.status-offline     { color: var(--gray);   background: rgba(107,114,128,.15); border-color: rgba(107,114,128,.4); }
.badge.status-maintenance { color: var(--amber);  background: rgba(245,158,11,.12);  border-color: rgba(245,158,11,.35); }
/* 中性角色標籤（VRF / role / type 等），無前點 */
.badge.role { color: var(--muted); background: var(--panel2); border-color: var(--line); }
.badge.role::before { display: none; }
.badge.purple { color: var(--purple); background: rgba(168,85,247,.12); border-color: rgba(168,85,247,.35); }
.badge.purple::before { display: none; }
.badge.accent { color: var(--accent); background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.35); }
.badge.accent::before { display: none; }

/* =====================================================================
 * 使用率長條  .usage-bar
 *  <div class="usage-bar"><span style="width:NN%"></span></div>
 *  依比例自動上色：低=綠、中=琥珀、高(>90)=紅。
 *  .usage-bar.warn / .usage-bar.crit 可手動覆寫顏色。
 *  搭配 .usage-cell（含百分比文字 + bar）使用更佳。
 * ===================================================================== */
.usage-bar {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  min-width: 80px;
}
.usage-bar > span { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }
.usage-bar.warn > span { background: var(--amber); }
.usage-bar.crit > span { background: var(--red); }
.usage-cell { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.usage-cell .pct { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); width: 38px; text-align: right; }

/* =====================================================================
 * 篩選面板（左側欄內或主區頂部） .filter-panel
 *  .filter-panel — 容器
 *  .filter-group — 一組（label + 控制項）
 *  .filter-panel select / input — 統一深色控制項樣式
 * ===================================================================== */
.filter-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group > label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.filter-panel select,
.filter-panel input[type="text"],
.filter-panel input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--txt);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  min-width: 130px;
}
.filter-panel select:focus,
.filter-panel input:focus { border-color: var(--accent); }
.filter-panel .spacer { flex: 1; }
.btn {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* =====================================================================
 * 右側詳情面板  .detail-panel
 *  預設隱藏（transform 滑出畫面右側），加 .open 滑入。
 *  結構：.detail-panel > .detail-head(.close) + .detail-body
 *  .detail-row（label / value）成對顯示欄位。
 * ===================================================================== */
.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 92vw;
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0,0,0,.4);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.detail-panel.open { transform: translateX(0); }
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.detail-head h3 { margin: 0; font-size: 15px; }
.detail-head .close { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; background: none; border: none; }
.detail-head .close:hover { color: var(--txt); }
.detail-body { padding: 16px 18px; overflow: auto; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.detail-row .label { color: var(--muted); }
.detail-row .value { text-align: right; word-break: break-all; }
.detail-section-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; margin: 16px 0 6px; }

/* 點詳情面板外時的遮罩（可選） */
.detail-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 40;
}
.detail-overlay.open { opacity: 1; pointer-events: auto; }

/* =====================================================================
 * 拓撲分頁  .lens-tabs / .lens
 *  上方視角切換按鈕（L3 邏輯 / 基礎設施 / IP 分配）。
 *  .lens.active 為目前視角。
 * ===================================================================== */
.lens-tabs { display: flex; gap: 8px; margin: 4px 0 18px; flex-wrap: wrap; }
.lens {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.lens.active { border-color: var(--accent); color: var(--txt); background: var(--panel2); }
.lens b { font-weight: 600; }

/* 拓撲畫布容器（cytoscape 掛載點） */
.canvas {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 460px;
  position: relative;
  overflow: hidden;
}
.canvas .hint { position: absolute; bottom: 12px; right: 16px; color: var(--muted); font-size: 11px; pointer-events: none; }

/* 圖例 .legend */
.legend { display: flex; gap: 18px; margin-top: 12px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* =====================================================================
 * 其他工具 class
 * ===================================================================== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.muted { color: var(--muted); }
.mono { font-family: "Consolas", "Courier New", monospace; }
.txt-green { color: var(--green); }  .txt-amber { color: var(--amber); }
.txt-red { color: var(--red); }      .txt-purple { color: var(--purple); }
.txt-accent { color: var(--accent); }
.alert {
  display: flex; align-items: center; gap: 10px;
  background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.35);
  color: var(--red); border-radius: var(--radius); padding: 10px 14px; font-size: 13px;
}
.empty { color: var(--muted); text-align: center; padding: 40px; font-size: 13px; }
.loading { color: var(--muted); text-align: center; padding: 40px; font-size: 13px; }

/* =====================================================================
 * Toast 提示（IPAM.toast）— 右下滑入、可堆疊、深色 NOC 風
 * ===================================================================== */
.ipam-toast-host {
  position: fixed; right: 18px; bottom: 18px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}
.ipam-toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 11px 12px 11px 13px;
  color: var(--txt); font-size: 13px; line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  opacity: 0; transform: translateX(24px);
  transition: opacity .2s ease, transform .2s ease;
}
.ipam-toast.in { opacity: 1; transform: translateX(0); }
.ipam-toast.out { opacity: 0; transform: translateX(24px); }
.ipam-toast.success { border-left-color: var(--green); }
.ipam-toast.error   { border-left-color: var(--red); }
.ipam-toast.info    { border-left-color: var(--accent); }
.ipam-toast .ti {
  flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 11px; font-weight: 700; color: #fff;
}
.ipam-toast.success .ti { background: var(--green); }
.ipam-toast.error   .ti { background: var(--red); }
.ipam-toast.info    .ti { background: var(--accent); }
.ipam-toast .tm { flex: 1; word-break: break-word; }
.ipam-toast .tm .mono { font-family: "Consolas", monospace; }
.ipam-toast .tx {
  flex: 0 0 auto; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 12px; line-height: 1; padding: 2px 2px 0;
}
.ipam-toast .tx:hover { color: var(--txt); }
@media (max-width: 520px) {
  .ipam-toast-host { left: 12px; right: 12px; max-width: none; }
}

/* 自訂捲軸（深色） */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3d4a6b; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: var(--topbar-h) auto 1fr; }
  .side { grid-column: 1; border-right: none; border-bottom: 1px solid var(--line); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
