/* ── 全局重置 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #f0f4f8;
    --card:     #ffffff;
    --border:   #e8edf3;
    --text:     #1a202c;
    --muted:    #718096;
    --blue:     #3b82f6;
    --green:    #22c55e;
    --orange:   #f59e0b;
    --red:      #ef4444;
    --shadow:   0 2px 12px rgba(0,0,0,0.07);
    --radius:   14px;
    --radius-sm:8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ── 首頁 ── */
.home-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.home-card {
    background: var(--card);
    border-radius: 20px;
    padding: 48px 40px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 480px;
    text-align: center;
}

.home-icon { font-size: 52px; margin-bottom: 12px; }

.home-title { font-size: 26px; font-weight: 700; margin-bottom: 6px; }

.home-sub { color: var(--muted); margin-bottom: 24px; }

.mqtt-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    margin-bottom: 24px;
    font-weight: 500;
}
.mqtt-badge .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.badge-ok  { background: #dcfce7; color: #166534; }
.badge-ok .dot  { background: var(--green); }
.badge-warn{ background: #fef9c3; color: #854d0e; }
.badge-warn .dot{ background: var(--orange); animation: blink 1s infinite; }

.input-row {
    display: flex;
    gap: 10px;
}
.imei-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
    transition: border-color .2s;
}
.imei-input:focus { border-color: var(--blue); }

.btn-enter {
    padding: 12px 20px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .2s;
}
.btn-enter:disabled { opacity: .4; cursor: not-allowed; }
.btn-enter:not(:disabled):hover { opacity: .9; }

.input-error { color: var(--red); margin-top: 10px; font-size: 13px; }

/* ── 頂部導覽列 ── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--card);
    padding: 12px 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    position: sticky;
    top: 0;
    z-index: 100;
}

.btn-back {
    padding: 7px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
}
.btn-back:hover { background: #e2e8f0; }

.topbar-center {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: center;
    flex-wrap: wrap;
}
.topbar-imei { font-size: 14px; }

.device-status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dot-online  { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.dot-offline { background: var(--red); }

.device-status-text { font-size: 13px; font-weight: 600; }

.badge-sleep {
    background: #fef3c7;
    color: #92400e;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.topbar-mqtt {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 500;
    white-space: nowrap;
}
.dot-sm {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.mqtt-ok  { background: #dcfce7; color: #166534; }
.mqtt-ok .dot-sm  { background: var(--green); }
.mqtt-err { background: #fee2e2; color: #991b1b; }
.mqtt-err .dot-sm { background: var(--red); animation: blink 1s infinite; }

/* ── 頁面主體 ── */
.page-body {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── 卡片 ── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card-head {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: space-between;
}
.head-time {
    font-size: 11px;
    font-weight: 400;
    color: var(--muted);
}

/* ── 三欄 ── */
.row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
@media (max-width: 900px) {
    .row-3 { grid-template-columns: 1fr; }
}

/* ── kv 列 ── */
.kv {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
}
.kv span { color: var(--muted); }
.kv b    { font-weight: 600; }
.mt8 { margin-top: 8px; }

.no-data {
    color: var(--muted);
    font-size: 13px;
    text-align: center;
    padding: 24px 0;
    line-height: 1.8;
}

.updated {
    margin-top: 10px;
    font-size: 11px;
    color: var(--muted);
    text-align: right;
}

/* ── 車輛資料 ── */
.vehicle-main {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
@media (max-width: 900px) {
    .vehicle-main { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 500px) {
    .vehicle-main { grid-template-columns: repeat(2, 1fr); }
}

.big-stat {
    background: #f8fafc;
    border-radius: var(--radius-sm);
    padding: 14px 10px;
    text-align: center;
    border: 1px solid var(--border);
}
.big-val {
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 6px;
}
.big-label { font-size: 11px; color: var(--muted); }

.vehicle-detail {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}
@media (max-width: 700px) {
    .vehicle-detail { grid-template-columns: 1fr; }
}

.detail-group { }
.detail-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }

.lights-row { display: flex; gap: 8px; flex-wrap: wrap; }
.light {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: #f1f5f9;
    color: var(--muted);
    border: 1px solid var(--border);
}
.light-on {
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde68a;
}

/* ── 電池包 ── */
.soc-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 6px;
}
.soc-pct { font-weight: 700; }

.soc-track {
    background: #f1f5f9;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
    margin-bottom: 12px;
}
.soc-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .5s ease;
}
.soc-green  { background: var(--green); color: #166534; }
.soc-orange { background: var(--orange); color: #92400e; }
.soc-red    { background: var(--red); color: #991b1b; }

/* ── ADC 電源 ── */
.card-adc { }
.adc-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.adc-item {
    flex: 1;
    min-width: 100px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}
.adc-val   { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.adc-label { font-size: 11px; color: var(--muted); }

/* ── 訊息日誌 ── */
.card-log { }
.log-table-wrap { overflow-x: auto; }

.log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.log-table th {
    text-align: left;
    padding: 8px 10px;
    background: #f8fafc;
    color: var(--muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.log-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #f8fafc;
    vertical-align: top;
}
.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover td { background: #f8fafc; }

.log-time    { white-space: nowrap; color: var(--muted); }
.log-topic   { white-space: nowrap; font-family: monospace; }
.log-payload { word-break: break-all; font-family: monospace; color: #475569; max-width: 600px; }

/* 日誌行顏色 */
.log-vehicle  td { border-left: 3px solid #60a5fa; }
.log-battery  td { border-left: 3px solid var(--green); }
.log-hb       td { border-left: 3px solid var(--orange); }
.log-gps      td { border-left: 3px solid #a78bfa; }
.log-status   td { border-left: 3px solid #fb923c; }
.log-resp     td { border-left: 3px solid #94a3b8; }

/* ── 狀態色彩 ── */
.val-ok   { color: #166534; }
.val-warn { color: #92400e; }
.val-err  { color: #991b1b; }
.val-off  { color: var(--muted); }

/* ── 動畫 ── */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: .3; }
}
