/* 電表登記系統 */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.6 "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  color: #1f2937;
  background: #f4f6fa;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 18px; }

/* ---------- 頂部 ---------- */
.topbar {
  background: #0f172a;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  position: sticky; top: 0; z-index: 20;
}
.topbar .wrap { display: flex; align-items: center; gap: 24px; height: 58px; }
.brand { color: #fff; font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-ico { font-size: 19px; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a {
  color: #cbd5e1; padding: 7px 14px; border-radius: 7px; font-size: 14.5px; white-space: nowrap;
}
.topbar nav a:hover { background: #1e293b; color: #fff; text-decoration: none; }
.topbar nav a.on { background: #2563eb; color: #fff; }

main.wrap { padding-top: 20px; padding-bottom: 40px; }

/* ---------- 提示 ---------- */
.flash {
  padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; font-size: 14.5px;
  background: #dcfce7; color: #14532d; border: 1px solid #86efac;
}
.flash.err { background: #fee2e2; color: #7f1d1d; border-color: #fca5a5; }
.flash.warn { background: #fef3c7; color: #78350f; border-color: #fcd34d; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, #1e3a8a, #2563eb 55%, #0ea5e9);
  color: #fff; border-radius: 14px; padding: 22px 24px; margin-bottom: 18px;
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: space-between;
}
.hero h1 { font-size: 22px; margin-bottom: 4px; }
.hero p { margin: 0; font-size: 13.5px; color: #dbeafe; max-width: 560px; }
.hero-tiles { display: flex; gap: 10px; flex-wrap: wrap; }
.tile {
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2);
  border-radius: 10px; padding: 10px 16px; min-width: 132px;
}
.tile-l { display: block; font-size: 12px; color: #dbeafe; }
.tile strong { font-size: 22px; font-weight: 700; }
.tile em { font-style: normal; font-size: 12px; margin-left: 3px; opacity: .85; }

/* ---------- 卡片 ---------- */
.card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.card-h { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-h h2 { font-size: 17px; }
.card-sub { font-size: 13px; color: #6b7280; }
.card-more { margin-left: auto; font-size: 13.5px; }
.note { font-size: 13px; color: #6b7280; margin: 12px 0 0; line-height: 1.7; }
.empty { text-align: center; color: #9ca3af; padding: 26px 0; }

/* ---------- 快速登記 ---------- */
.quick-time { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.quick-time label { font-weight: 600; font-size: 14px; }
.hint { font-size: 12.5px; color: #9ca3af; }
.quick-shortcut { display: flex; gap: 6px; }

.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.qr {
  border: 1px solid #e5e7eb; border-top: 3px solid var(--c); border-radius: 10px;
  padding: 12px 13px; background: #fcfdff;
}
.qr-h { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 14.5px; margin-bottom: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.qr input[type=number] {
  width: 100%; font-size: 19px; font-weight: 600; padding: 9px 10px;
  border: 1px solid #d1d5db; border-radius: 8px; font-family: ui-monospace, Consolas, monospace;
}
.qr input[type=number]:focus { outline: 2px solid var(--c); outline-offset: -1px; border-color: var(--c); }
.mini-note { width: 100%; margin-top: 6px; padding: 6px 8px; border: 1px solid #e5e7eb; border-radius: 7px; font-size: 12.5px; }
.qr-f { font-size: 12px; color: #6b7280; margin-top: 7px; line-height: 1.5; }
.quick-act { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 房間卡片 ---------- */
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.rcard {
  background: #fff; border: 1px solid #e5e7eb; border-top: 3px solid var(--c);
  border-radius: 12px; padding: 15px 16px; box-shadow: 0 1px 2px rgba(16,24,40,.04);
  display: flex; flex-direction: column;
}
.rcard-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rcard-h h3 { font-size: 15.5px; }
.trend { margin-left: auto; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 20px; }
.trend.up   { background: #fee2e2; color: #b91c1c; }
.trend.down { background: #dcfce7; color: #15803d; }
.trend.flat { background: #f3f4f6; color: #6b7280; }
.rcard-main { margin-bottom: 10px; }
.rcard-main .k { display: block; font-size: 12px; color: #6b7280; }
.rcard-main strong {
  font-size: 27px; font-weight: 700; letter-spacing: -.5px;
  font-family: ui-monospace, Consolas, monospace; display: block; line-height: 1.25;
}
.rcard-main .when { font-size: 12px; color: #9ca3af; }
.spark { width: 100%; height: 44px; display: block; }
.spark-empty { height: 44px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #cbd5e1; }
.spark-cap { font-size: 11.5px; color: #9ca3af; text-align: right; margin-bottom: 8px; }

table.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
table.mini th { text-align: left; font-weight: 400; color: #6b7280; padding: 5px 0; white-space: nowrap; }
table.mini td { text-align: right; padding: 5px 0; }
table.mini td b { font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
table.mini tr + tr { border-top: 1px dashed #eef0f4; }
table.mini tr.hl th, table.mini tr.hl td { padding-top: 8px; }
table.mini tr.hl td b { color: #b45309; }
.sub { color: #9ca3af; font-size: 12px; margin-left: 4px; }
.rcard-link { margin-top: 12px; font-size: 13px; }

/* ---------- 排行 ---------- */
.rank { display: flex; flex-direction: column; gap: 9px; }
.rank-row { display: flex; align-items: center; gap: 10px; }
.rank-no {
  width: 22px; height: 22px; border-radius: 50%; background: #eef2f7; color: #64748b;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none;
}
.rank-row:first-child .rank-no { background: #fef3c7; color: #b45309; }
.rank-name { width: 96px; font-size: 14px; font-weight: 600; flex: none; }
.rank-bar { flex: 1; background: #f1f5f9; border-radius: 6px; height: 20px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; border-radius: 6px; }
.rank-val { width: 104px; text-align: right; font-family: ui-monospace, Consolas, monospace; font-weight: 700; font-size: 14px; flex: none; }
.rank-val em { font-style: normal; font-weight: 400; font-size: 11.5px; color: #9ca3af; }

/* ---------- 圖表 ---------- */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; min-width: 640px; height: auto; display: block; }
.chart .ax  { font-size: 11px; fill: #6b7280; font-family: inherit; }
.chart .ax2 { font-size: 10px; fill: #94a3b8; font-family: inherit; }
.chart .ax3 { font-size: 10px; fill: #cbd5e1; font-family: inherit; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; color: #4b5563; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- 表格 ---------- */
.tbl-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th, table.tbl td { padding: 9px 10px; border-bottom: 1px solid #eef0f4; text-align: left; }
table.tbl thead th { background: #f8fafc; color: #64748b; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
table.tbl tfoot th { background: #f8fafc; font-size: 13px; border-top: 2px solid #e2e8f0; }
table.tbl tbody tr:hover { background: #fafbfe; }
table.tbl .r { text-align: right; }
table.tbl .c { text-align: center; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.b { font-weight: 700; }
.neg { color: #dc2626; }
.nowrap { white-space: nowrap; }
tr.rowwarn { background: #fff7ed; }
tr.rowwarn:hover { background: #ffedd5; }

.tag {
  display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 20px;
  background: #f1f5f9; border: 1px solid #e2e8f0;   /* 舊瀏覽器 fallback */
  background: color-mix(in srgb, var(--c, #64748b) 14%, #fff);
  color: var(--c, #475569); border: 1px solid color-mix(in srgb, var(--c, #64748b) 35%, #fff);
  font-weight: 600; white-space: nowrap;
}
.tag.warn { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.tag.danger { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }

.pctbar { display: inline-block; width: 60px; height: 6px; background: #f1f5f9; border-radius: 4px; overflow: hidden; margin-right: 6px; vertical-align: 1px; }
.pctbar span { display: block; height: 100%; }

/* ---------- 表單 ---------- */
input[type=text], input[type=number], input[type=date], input[type=datetime-local], select {
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
  font-family: inherit; background: #fff; color: #1f2937;
}
input:focus, select:focus { outline: 2px solid #93c5fd; outline-offset: -1px; border-color: #3b82f6; }
input[type=color] { width: 44px; height: 32px; padding: 2px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; }
.w70 { width: 70px; }

.form1 .f-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.form1 .f-row > label:first-child { width: 96px; font-size: 14px; font-weight: 600; flex: none; }
.chk { font-size: 13.5px; color: #4b5563; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.chk.sm { font-size: 12px; margin-top: 6px; }

.filter { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filter > div { display: flex; align-items: center; gap: 7px; }
.filter label { font-size: 13px; color: #6b7280; }
.filter-act { gap: 8px; }
.rangebtns { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  display: inline-block; padding: 9px 18px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-family: inherit; cursor: pointer; background: #f1f5f9; color: #334155; font-weight: 600;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: #2563eb; color: #fff; }
.btn-ghost { background: #fff; border-color: #d1d5db; color: #475569; }
.btn-xs { padding: 4px 10px; font-size: 12.5px; font-weight: 500; }
.btn-danger { background: #fff; border-color: #fca5a5; color: #dc2626; }
.btn-danger:hover { background: #fee2e2; }
form.inline { display: inline; }

.chip {
  display: inline-block; padding: 5px 12px; border-radius: 20px; border: 1px solid #d1d5db;
  background: #fff; color: #475569; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.chip:hover { background: #f1f5f9; text-decoration: none; }
.chip.on { background: #2563eb; border-color: #2563eb; color: #fff; }

.pager { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 14px; }
.pager a { padding: 5px 11px; border: 1px solid #e2e8f0; border-radius: 7px; font-size: 13px; color: #475569; }
.pager a.on { background: #2563eb; border-color: #2563eb; color: #fff; }

.btn-hero {
  display: inline-block; margin-top: 12px; background: #fff; color: #1d4ed8;
  padding: 9px 20px; font-weight: 700;
}
.btn-hero:hover { background: #eff6ff; text-decoration: none; }
.tile strong.sm { font-size: 14px; line-height: 1.45; display: block; padding: 3px 0; }
.tile-f { display: block; font-size: 11.5px; color: #bfdbfe; margin-top: 2px; }

/* 整戶電費估算 */
.house { display: flex; align-items: stretch; gap: 12px; flex-wrap: wrap; }
.house-b {
  flex: 1 1 180px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 12px 16px; text-align: center;
}
.house-b span { display: block; font-size: 12.5px; color: #6b7280; margin-bottom: 3px; }
.house-b strong { font-size: 24px; font-family: ui-monospace, Consolas, monospace; }
.house-b strong.sm { font-size: 15px; font-family: inherit; }
.house-b em { font-style: normal; font-size: 12px; color: #9ca3af; margin-left: 3px; }
.house-b.big { background: #eff6ff; border-color: #bfdbfe; }
.house-b.big strong { color: #1d4ed8; }
.house-op { display: flex; align-items: center; color: #cbd5e1; font-size: 20px; font-weight: 700; }

.radios { display: flex; gap: 18px; flex-wrap: wrap; }
.sec-t { font-size: 14.5px; margin: 20px 0 8px; padding-top: 14px; border-top: 1px solid #eef0f4; color: #334155; }
.w110 { width: 110px; text-align: right; }
table.tiers input { text-align: right; }

.danger-zone { border-color: #fecaca; background: #fffbfb; }
.danger-zone .card-h h2 { color: #b91c1c; }

.help h4 { font-size: 14.5px; margin: 16px 0 5px; color: #1e40af; }
.help h4:first-child { margin-top: 0; }
.help p { margin: 0; font-size: 13.5px; color: #4b5563; line-height: 1.8; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; color: #be123c; }

.foot { text-align: center; color: #9ca3af; font-size: 12.5px; padding: 20px 0 32px; }

/* ---------- RWD ---------- */
@media (max-width: 1000px) {
  .grid4, .quick-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .wrap { padding: 0 12px; }
  .topbar .wrap { height: auto; padding: 8px 12px; flex-direction: column; align-items: flex-start; gap: 6px; }
  .topbar nav { width: 100%; }
  .grid4, .quick-grid { grid-template-columns: 1fr; }
  .hero { padding: 18px; }
  .hero-tiles { width: 100%; }
  .tile { flex: 1 1 45%; min-width: 0; }
  .rank-name { width: 70px; font-size: 13px; }
  .rank-val { width: 88px; font-size: 13px; }
  .form1 .f-row > label:first-child { width: 100%; }
}
