:root {
  --red: #c0181f;
  --blue: #2a5bd7;
  --side: #e6e7eb;
  --border: #e5e7eb;
  --text: #1f2328;
  --muted: #8a8f98;
  --green: #5fd38d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  color: var(--text); background: #f3f3f4; font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- layout ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 216px; background: var(--side);
  overflow-y: auto; transition: width .2s; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 26px 14px; color: #1d4fb8;
  font-size: 18px; font-weight: 700; letter-spacing: 8px; white-space: nowrap; }
.brand svg { flex: none; }
.menu-group > .menu-title { display: flex; align-items: center; gap: 8px; padding: 9px 20px; cursor: pointer;
  font-size: 15px; user-select: none; }
.menu-group > .menu-title .chev { margin-left: auto; transition: transform .2s; color: #888; }
.menu-group.collapsed > .menu-title .chev { transform: rotate(180deg); }
.menu-group.collapsed .menu-items { display: none; }
.menu-items a { display: flex; align-items: center; gap: 10px; margin: 2px 7px; padding: 7px 16px;
  border-radius: 4px; font-size: 13.5px; white-space: nowrap; }
.menu-items a:hover { background: #dadbe0; }
.menu-items a.active { background: var(--red); color: #fff; }
.menu-items a::before { content: "≡"; font-size: 17px; line-height: 1; font-weight: 700; }
.main { margin-left: 216px; min-height: 100%; transition: margin .2s; }
.topbar { position: sticky; top: 0; z-index: 10; height: 48px; background: #fff; display: flex; align-items: center;
  padding: 0 16px; box-shadow: 0 1px 4px rgba(0,0,0,.06); gap: 12px; }
.topbar .title { font-weight: 700; font-size: 15px; }
.topbar .spacer { flex: 1; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px; border-radius: 4px; color: #333;
  display: inline-flex; align-items: center; position: relative; }
.icon-btn:hover { background: #f0f0f2; }
.badge { position: absolute; top: 0; right: 0; background: var(--red); color: #fff; border-radius: 9px;
  font-size: 10px; padding: 0 5px; line-height: 15px; }
.user-chip { font-size: 13px; color: #555; }
body.side-collapsed .sidebar { width: 0; }
body.side-collapsed .main { margin-left: 0; }
.content { padding: 12px 14px 24px; }

/* ---------- cards / grid ---------- */
.card { background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 14px 14px; }
.card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.grid { display: grid; gap: 8px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g7 { grid-template-columns: repeat(7, 1fr); }
.row { display: flex; gap: 8px; }
.mb { margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.big { font-size: 26px; font-weight: 500; }
.unit { font-size: 15px; margin-left: 3px; }
.kv { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; }
.kv .v { text-align: right; }
.stack-right { text-align: right; }
.chart { width: 100%; height: 320px; }

/* ---------- forms ---------- */
.toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.toolbar .field { display: flex; flex-direction: column; gap: 6px; }
.toolbar .field label, .field-label { font-size: 13px; color: #333; }
.toolbar .right { margin-left: auto; display: flex; gap: 6px; }
select, input[type=date], input[type=month], input[type=number], input[type=text], input[type=password], input[type=week] {
  height: 32px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 8px; background: #fff; font: inherit;
  font-size: 13px; color: #333; min-width: 90px;
}
select:focus, input:focus { outline: none; border-color: #6d8fe6; }
.btn { height: 32px; padding: 0 14px; border: 1px solid #dcdfe6; border-radius: 4px; background: #fff; cursor: pointer;
  font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #b4bccc; }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.outline-blue { color: #3462c9; border-color: #8aa6e8; height: 28px; font-size: 12px; }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12px; }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: 36px; background: #fff; border: 1px solid var(--border);
  border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.1); min-width: 120px; z-index: 30; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a { display: block; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.dropdown-menu a:hover { background: #f3f5f9; }

/* multi select */
.ms { position: relative; width: 238px; }
.ms-box { height: 32px; border: 1px solid #dcdfe6; border-radius: 4px; display: flex; align-items: center; padding: 0 8px;
  cursor: pointer; background: #fff; font-size: 12px; color: #999; gap: 6px; }
.ms-box .ms-text { flex: 1; }
.ms-box .x { color: #666; font-size: 14px; }
.ms-panel { position: absolute; top: 34px; left: 0; width: 100%; max-height: 300px; overflow: auto; background: #fff;
  border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.12); z-index: 40; display: none; }
.ms.open .ms-panel { display: block; }
.ms-panel label { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.ms-panel label:hover { background: #f4f6fa; }
.ms-panel .ms-all { border-bottom: 1px solid var(--border); font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.tag { background: #e3ecfb; color: #34518f; border-radius: 12px; padding: 3px 10px; font-size: 12px; display: inline-flex;
  align-items: center; gap: 8px; }
.tag .x { cursor: pointer; font-size: 13px; color: #34518f; }
.section-title { font-size: 13.5px; margin: 6px 0 8px; }
.group-list .empty { font-size: 12px; color: #888; margin: 6px 0 14px; }
.group-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #c7d4f2; border-radius: 14px;
  padding: 3px 10px; margin: 4px 8px 12px 0; font-size: 12.5px; cursor: pointer; background: #f6f8fd; }
.group-chip .x { color: #999; }
.group-chip:hover { border-color: #6d8fe6; }

/* ---------- tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { border-bottom: 1px solid #eef0f3; padding: 8px 10px; text-align: left; }
table.data th { background: #fafbfc; font-weight: 600; color: #444; position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { max-height: 640px; overflow: auto; }
.bill { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.bill th, .bill td { border: 1px solid #666; padding: 6px 8px; }
.bill th { background: #fafafa; letter-spacing: 6px; }
.bill td.num { text-align: right; }

/* ---------- realtime tiles ---------- */
.tile { background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 18px 14px; display: flex;
  justify-content: space-between; align-items: center; min-height: 58px; }
.tile .name { font-size: 14px; }
.tile .val { font-size: 19px; }
.tile .val small { font-size: 13px; margin-left: 4px; }
.dcard { background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 14px; }
.dcard .head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.dcard .head b { font-size: 15px; }
.dcard .head span { font-size: 11px; color: #777; }
.dcard .line { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: 13px; }
.dcard .line .v { font-size: 17px; }
.dcard .line .v small { font-size: 12px; margin-left: 4px; }
.dcard.draggable { cursor: grab; position: relative; }
.dcard.dragging { opacity: .4; }
.dcard .remove { position: absolute; right: 6px; bottom: 4px; display: none; }
.dcard:hover .remove { display: inline-flex; }

/* ---------- misc ---------- */
.carousel-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.dots span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; border: 1px solid #999; margin-right: 4px; cursor: pointer; }
.dots span.on { background: #999; }
.arrows button { background: none; border: 0; cursor: pointer; font-size: 12px; color: #333; }
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: none; align-items: center; justify-content: center; z-index: 100; }
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: 8px; width: 560px; max-width: 94vw; max-height: 90vh; overflow: auto; padding: 20px 22px; }
.modal h2 { font-size: 17px; margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: 130px 1fr; gap: 10px 12px; align-items: center; }
.form-grid input, .form-grid select { width: 100%; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; top: 60px; right: 20px; background: #fff7e6; border: 1px solid #ffd591; color: #8a5a00;
  padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.1); z-index: 200; font-size: 13px; display: none; }
.toast.ok { background: #effaf2; border-color: #9be0b2; color: #146c33; }
.toast.err { background: #fff1f0; border-color: #ffa39e; color: #a8071a; }
.loading { opacity: .5; pointer-events: none; }
.level { padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.level.critical { background: #fde2e1; color: #b3261e; }
.level.warning { background: #fff1d6; color: #9a6200; }
.level.info { background: #e3ecfb; color: #34518f; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 13px; }
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid #d5d9e0; border-radius: 14px; padding: 3px 11px; font-size: 12.5px; cursor: pointer; background: #fff; }
.chip.on { background: #e3ecfb; border-color: #6d8fe6; color: #2948a6; }
.chip-label { font-size: 11.5px; color: #888; margin: 0 2px 0 6px; }
.mono { font-family: "JetBrains Mono", Consolas, "Microsoft JhengHei", monospace; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g7 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .sidebar { width: 0; }
  .main { margin-left: 0; }
  body.side-open .sidebar { width: 216px; }
  .g4, .g7 { grid-template-columns: 1fr; }
}

/* ---------- admin ---------- */
.topbar .admin-site { margin-left: 16px; font-size: 13px; color: #555; background: #fff6e0; border: 1px solid #f3d48b; border-radius: 4px; padding: 3px 10px; }
.topbar .admin-site a { margin-left: 8px; color: var(--blue); }
