/* AI-Box 監控平台 — 樣式表
   設計方向：保安控制室。資訊密度優先，鋼藍主色呼應「藍鋼」，
   小圓角、細分隔線、無大陰影；唯一高調之處是事件警示色。 */

:root {
  --ink:        #0e1722;
  --ink-2:      #17222f;
  --ink-3:      #223040;
  --surface:    #f4f6f9;
  --card:       #ffffff;
  --line:       #e2e8f0;
  --line-soft:  #eef2f6;
  --text:       #1c2735;
  --text-2:     #5b6b7d;
  --text-3:     #8a99a9;
  --steel:      #0b6ea8;
  --steel-dk:   #08557f;
  --steel-soft: #e8f2f9;
  --alarm:      #d92b36;
  --alarm-soft: #fdecec;
  --ok:         #14875c;
  --ok-soft:    #e6f5ee;
  --warn:       #c47f10;
  --warn-soft:  #fdf3e2;
  --radius:     6px;
  --radius-lg:  10px;
  --sidebar-w:  248px;
  --topbar-h:   58px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans HK",
          "PingFang HK", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible { outline: 2px solid var(--steel); outline-offset: 2px; }

.ic { width: 18px; height: 18px; flex: 0 0 18px; }

/* ---------- 版面骨架 ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--ink);
  color: #c8d4e0;
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0;
  z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius);
  background: var(--steel); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.brand-txt { display: flex; flex-direction: column; min-width: 0; }
.brand-name { color: #fff; font-weight: 600; font-size: 14px; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-org { color: #6f8098; font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; margin-bottom: 2px;
  border-radius: var(--radius);
  color: #b3c1d1; font-size: 13.5px;
}
.nav-item:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--steel); color: #fff; }
.nav-item.active .ic { color: #fff; }
.nav-sep {
  margin: 16px 11px 7px;
  font-size: 11px; color: #5f7189;
  border-top: 1px solid rgba(255,255,255,.07);
  padding-top: 12px;
}
.sidebar-foot { padding: 10px 18px; font-size: 11px; color: #4f6076;
  border-top: 1px solid rgba(255,255,255,.07); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 30;
}
.page-title { font-size: 16px; font-weight: 600; margin: 0; flex: 1; }
.top-right { display: flex; align-items: center; gap: 12px; }
.clock { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 9px; border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text-2); font-size: 12.5px;
}
.lang-btn:hover { background: var(--surface); text-decoration: none; }
.lang-btn .ic { width: 15px; height: 15px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius);
  color: var(--text-2); border: 1px solid var(--line); background: var(--card);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); color: var(--alarm); }

.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--steel-soft); color: var(--steel-dk);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}
.uname { display: flex; flex-direction: column; line-height: 1.2; }
.uname strong { font-size: 13px; font-weight: 600; }
.uname small { font-size: 11px; color: var(--text-3); }

.burger { display: none; background: none; border: 0; cursor: pointer; padding: 6px; }
.burger span { display: block; width: 20px; height: 2px; background: var(--text); margin: 4px 0; border-radius: 2px; }

.content { padding: 20px; flex: 1; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { font-size: 14px; font-weight: 600; margin: 0; flex: 1; }
.card-head .sub { font-size: 12px; color: var(--text-3); }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 15px 16px;
  display: flex; align-items: center; gap: 14px;
}
.kpi-ic {
  width: 40px; height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  background: var(--steel-soft); color: var(--steel);
}
.kpi.alarm .kpi-ic { background: var(--alarm-soft); color: var(--alarm); }
.kpi.ok .kpi-ic    { background: var(--ok-soft); color: var(--ok); }
.kpi.warn .kpi-ic  { background: var(--warn-soft); color: var(--warn); }
.kpi-num {
  font-size: 26px; font-weight: 650; line-height: 1.1;
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.kpi-lbl { font-size: 12.5px; color: var(--text-2); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 600; color: var(--text-2);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: #fafbfc; white-space: nowrap; font-size: 12.5px;
}
table.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: #fafcfe; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .mono { font-family: var(--mono); font-size: 12px; color: var(--text-2); }

.thumb {
  width: 84px; height: 48px; object-fit: cover;
  border-radius: 4px; border: 1px solid var(--line); background: var(--surface);
  display: block;
}
.thumb-lg { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); display: block; }

/* ---------- 標籤 ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  background: #eef1f5; color: var(--text-2);
}
.badge.danger  { background: var(--alarm-soft); color: var(--alarm); }
.badge.warn    { background: var(--warn-soft);  color: var(--warn); }
.badge.info    { background: var(--steel-soft); color: var(--steel-dk); }
.badge.ok      { background: var(--ok-soft);    color: var(--ok); }
.badge.default { background: #eef1f5; color: var(--text-2); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.on  { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: #b6c0cb; box-shadow: 0 0 0 3px #eef1f5; }
.dot.live { background: var(--alarm); box-shadow: 0 0 0 3px var(--alarm-soft); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface); text-decoration: none; }
.btn-primary { background: var(--steel); border-color: var(--steel); color: #fff; }
.btn-primary:hover { background: var(--steel-dk); border-color: var(--steel-dk); }
.btn-danger { background: var(--alarm); border-color: var(--alarm); color: #fff; }
.btn-danger:hover { background: #b81f29; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 表單 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--text-3); }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--text);
  font-size: 13.5px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--steel); outline: none;
  box-shadow: 0 0 0 3px var(--steel-soft); }
textarea { resize: vertical; min-height: 70px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: 15px; height: 15px; }
.form-actions {
  display: flex; gap: 8px; padding-top: 14px; margin-top: 14px;
  border-top: 1px solid var(--line-soft);
}

/* ---------- 篩選列 ---------- */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft); background: #fafbfc;
}
.filters .field { min-width: 140px; }

/* ---------- 提示 ---------- */
.alert {
  padding: 10px 14px; border-radius: var(--radius);
  margin-bottom: 14px; font-size: 13px; border: 1px solid transparent;
}
.alert-ok    { background: var(--ok-soft);    color: #0d6b4a; border-color: #b9e3d0; }
.alert-error { background: var(--alarm-soft); color: #a71f28; border-color: #f4c4c7; }
.alert-warn  { background: var(--warn-soft);  color: #8a5a06; border-color: #f0dcb4; }
.alert-info  { background: var(--steel-soft); color: var(--steel-dk); border-color: #c5dcec; }

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

/* ---------- 分頁 ---------- */
.pager { display: flex; gap: 5px; align-items: center; padding: 12px 16px; flex-wrap: wrap; }
.pager a, .pager span {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 12.5px; color: var(--text-2); background: #fff;
}
.pager .cur { background: var(--steel); border-color: var(--steel); color: #fff; }
.pager .info { border: 0; background: none; margin-left: auto; color: var(--text-3); }

/* ---------- 條形圖 ---------- */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 46px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-track { height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--steel); border-radius: 4px; }
.bar-fill.alarm { background: var(--alarm); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 84px; }
.spark-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.spark-bar { background: var(--steel); border-radius: 2px 2px 0 0; min-height: 2px; }
.spark-lbl { font-size: 9.5px; color: var(--text-3); text-align: center; margin-top: 4px;
  font-variant-numeric: tabular-nums; }

/* ---------- 實時頁 ---------- */
.live-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.frame-box {
  background: #0b1219; border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow: hidden; position: relative;
}
.frame-box iframe { width: 100%; height: 640px; border: 0; display: block; background: #0b1219; }
.feed { max-height: 640px; overflow-y: auto; }
.feed-item {
  display: flex; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft); font-size: 12.5px;
}
.feed-item:hover { background: #fafcfe; }
.feed-item .fi-time { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.feed-item .fi-name { font-weight: 600; }
.feed-new { animation: flashin 1.2s ease-out; }
@keyframes flashin { from { background: var(--alarm-soft); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .feed-new { animation: none; } }

.vgrid { display: grid; gap: 8px; }
.vgrid.g1 { grid-template-columns: 1fr; }
.vgrid.g4 { grid-template-columns: repeat(2, 1fr); }
.vgrid.g9 { grid-template-columns: repeat(3, 1fr); }
.vcell {
  background: #0b1219; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16/9; position: relative;
}
.vcell img { width: 100%; height: 100%; object-fit: contain; display: block; }
.vcell .vlabel {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.62); color: #fff; font-size: 11.5px;
  padding: 2px 8px; border-radius: 4px;
}
.vcell .vempty { color: #43556a; font-size: 12px; display: flex;
  align-items: center; justify-content: center; height: 100%; }

/* ---------- 登入頁 ---------- */
.login-page {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
  background: var(--ink);
}
.login-art {
  position: relative; color: #fff; padding: 52px 56px;
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(900px 460px at 12% 8%, rgba(11,110,168,.42), transparent 62%),
    linear-gradient(160deg, #0e1722 0%, #142334 62%, #0b1219 100%);
  overflow: hidden;
}
.login-art .grid-lines {
  position: absolute; inset: 0; opacity: .16;
  background-image: linear-gradient(rgba(255,255,255,.14) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.14) 1px, transparent 1px);
  background-size: 44px 44px;
}
.login-art .art-inner { position: relative; z-index: 1; }
.login-art h2 { font-size: 30px; margin: 0 0 12px; font-weight: 600; letter-spacing: -.01em; }
.login-art p { color: #93a6bb; max-width: 40ch; margin: 0; line-height: 1.65; }
.login-art .feat { display: flex; flex-direction: column; gap: 12px; margin-top: 30px; }
.login-art .feat div { display: flex; align-items: center; gap: 10px; color: #c2d0de; font-size: 13.5px; }
.login-art .feat .ic { color: var(--steel); }
.login-art .foot { position: relative; z-index: 1; color: #5f7189; font-size: 12px; }

.login-form-wrap {
  background: var(--card); display: flex; align-items: center; justify-content: center; padding: 40px;
}
.login-form { width: 100%; max-width: 340px; }
.login-form h1 { font-size: 21px; margin: 0 0 6px; font-weight: 600; }
.login-form .lead { color: var(--text-2); font-size: 13.5px; margin: 0 0 24px; }
.login-form .field { margin-bottom: 14px; }
.login-form .btn { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }
.login-lang { text-align: center; margin-top: 20px; font-size: 12.5px; }

/* ---------- 詳情列表 ---------- */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13px; }
.dl dt { color: var(--text-2); }
.dl dd { margin: 0; word-break: break-all; }

.snap-wrap { position: relative; display: inline-block; max-width: 100%; }
.snap-wrap img { display: block; max-width: 100%; border-radius: var(--radius); }
.bbox {
  position: absolute; border: 2px solid var(--alarm); border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.55) inset;
}
.bbox span {
  position: absolute; top: -19px; left: -2px;
  background: var(--alarm); color: #fff; font-size: 10.5px;
  padding: 1px 5px; border-radius: 3px; white-space: nowrap;
}

.code-box {
  font-family: var(--mono); font-size: 12px; background: #0e1722; color: #a8c4dd;
  padding: 11px 13px; border-radius: var(--radius); overflow-x: auto;
  white-space: pre-wrap; word-break: break-all;
}

.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.split-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }

/* ---------- 響應式 ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .live-grid, .split-2, .split-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .burger { display: block; }
  .content { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .user-chip .uname { display: none; }
  .clock { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
