/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
    --bg:           #0D1B2A;
    --card-bg:      #162032;
    --text:         #FFFFFF;
    --text-muted:   #8899BB;
    --accent:       #4488FF;
    --border:       #1E3050;
    --danger:       #CC3333;
    --success:      #22AA55;

    /* Battery use */
    --use-competition: #22AA55;
    --use-practice:    #4488FF;
    --use-programming: #FF7700;
    --use-inverter:    #CC3333;

    /* Battery status */
    --status-charging: #FFB300;
    --status-cooling:  #00CFFF;
    --status-ready:    #22AA55;
    --status-testing:         #AA44FF;
    --status-waiting-charge:  #AADD00;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ────────────────────────────────────────────────────────────── */
header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
}
.header-brand img {
    height: 40px;
    mix-blend-mode: screen;
}
.header-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}
.header-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}
nav {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.nav-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: var(--border); color: var(--text); text-decoration: none; }
.nav-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Main layout ───────────────────────────────────────────────────────── */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-title {
    font-size: 1.1rem;
    font-weight: 700;
}

/* ── Action buttons ────────────────────────────────────────────────────── */
.btn {
    padding: 0.55rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: #5599ff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dd4444; }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { background: #33bb66; }
.btn-ghost    { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-amber    { background: #FFB300; color: #0D1B2A; }
.btn-amber:hover { background: #ffcc44; }
.btn-cyan     { background: #00CFFF; color: #0D1B2A; }
.btn-cyan:hover { background: #33daff; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}
/* Use badges */
.badge-competition { background: rgba(34,170,85,0.18); color: var(--use-competition); border: 1px solid rgba(34,170,85,0.35); }
.badge-practice    { background: rgba(68,136,255,0.18); color: var(--use-practice);    border: 1px solid rgba(68,136,255,0.35); }
.badge-programming { background: rgba(255,119,0,0.18);  color: var(--use-programming); border: 1px solid rgba(255,119,0,0.35); }
.badge-inverter    { background: rgba(204,51,51,0.18);  color: var(--use-inverter);    border: 1px solid rgba(204,51,51,0.35); }
/* Status badges */
.badge-charging { background: rgba(255,179,0,0.18);  color: var(--status-charging); border: 1px solid rgba(255,179,0,0.35); }
.badge-cooling  { background: rgba(0,207,255,0.18);  color: var(--status-cooling);  border: 1px solid rgba(0,207,255,0.35); }
.badge-ready    { background: rgba(34,170,85,0.18);  color: var(--status-ready);    border: 1px solid rgba(34,170,85,0.35); }
.badge-testing         { background: rgba(170,68,255,0.18);  color: var(--status-testing);         border: 1px solid rgba(170,68,255,0.35); }
.badge-in-robot        { background: rgba(85,102,170,0.18);  color: #8899DD;                        border: 1px solid rgba(85,102,170,0.35); }
.badge-waiting-charge  { background: rgba(170,221,0,0.18);   color: var(--status-waiting-charge);  border: 1px solid rgba(170,221,0,0.35); }

/* ── Dashboard table ───────────────────────────────────────────────────── */
.table-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead tr {
    background: rgba(30,48,80,0.6);
}
thead th {
    padding: 0.7rem 0.85rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
thead th:first-child { padding-left: 1.1rem; }
thead th:last-child  { padding-right: 1.1rem; }
tbody tr {
    border-bottom: 1px solid rgba(30,48,80,0.5);
    transition: background 0.12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(68,136,255,0.06); }
tbody td {
    padding: 0.7rem 0.85rem;
    vertical-align: middle;
    white-space: nowrap;
}
tbody td:first-child { padding-left: 1.1rem; }
tbody td:last-child  { padding-right: 1.1rem; }
.td-id a {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent);
}
.td-name { color: var(--text); }
.td-mono {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    color: var(--text);
}
.td-muted { color: var(--text-muted); font-size: 0.82rem; }
/* Queue column */
.queue-cell {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.queue-pos {
    font-size: 1rem;
    font-weight: 800;
    color: var(--use-competition);
    min-width: 1.2rem;
    text-align: center;
}
.queue-btns {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.queue-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
    font-size: 0.6rem;
    line-height: 1;
    padding: 1px 4px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.queue-btn:hover:not(:disabled) { background: var(--border); color: var(--text); }
.queue-btn:disabled { opacity: 0.25; cursor: not-allowed; }

.checkin-link, .history-link {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    transition: background 0.12s;
    cursor: pointer;
    white-space: nowrap;
}
.checkin-link { color: var(--accent); background: transparent; text-decoration: none; }
.checkin-link:hover { background: var(--border); text-decoration: none; }
.history-link { color: var(--text-muted); background: transparent; }
.history-link:hover { background: var(--border); color: var(--text); }
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state p { margin-top: 0.5rem; font-size: 0.85rem; }

/* ── Checkin page ──────────────────────────────────────────────────────── */
.checkin-wrap {
    max-width: 680px;
    margin: 0 auto;
}
.battery-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.battery-card-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}
.battery-card-id {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
}
.battery-card-meta {
    flex: 1;
}
.battery-card-name {
    font-size: 1.1rem;
    font-weight: 600;
}
.battery-card-details {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.detail-item label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
.detail-item span {
    font-size: 0.9rem;
    font-weight: 500;
}
.detail-item .mono {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* Charge action buttons */
.charge-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.charge-btn {
    padding: 1.1rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}
.charge-btn:hover { transform: translateY(-1px); }
.charge-btn:active { transform: translateY(0); }
.charge-btn-icon { font-size: 1.5rem; }
.charge-btn-label { font-size: 0.75rem; font-weight: 600; opacity: 0.85; }
.btn-on-charge  { background: #FFB300; color: #0D1B2A; }
.btn-on-charge:hover  { background: #ffcc44; }
.btn-off-charge { background: #00CFFF; color: #0D1B2A; }
.btn-off-charge:hover { background: #33daff; }
.btn-off-robot  { background: #5566AA; color: #fff; }
.btn-off-robot:hover  { background: #6677BB; }

/* Data entry form */
.form-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.form-card h3 {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
    margin-bottom: 0.85rem;
}
.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.form-field.full { grid-column: 1 / -1; }
.form-field label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.form-field input,
.form-field select,
.form-field textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    padding: 0.55rem 0.75rem;
    font-family: inherit;
    transition: border-color 0.15s;
    width: 100%;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.form-field textarea { resize: vertical; min-height: 72px; }
.form-field select option { background: var(--card-bg); }

/* ── History table ─────────────────────────────────────────────────────── */
.section-title {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.history-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    overflow-x: auto;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 500;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    z-index: 999;
    white-space: nowrap;
}
#toast.show { opacity: 1; }
#toast.success { border-color: var(--success); color: var(--success); }
#toast.error   { border-color: var(--danger);  color: var(--danger); }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    main { padding: 1rem; }
    .form-grid { grid-template-columns: 1fr; }
    .charge-actions { grid-template-columns: 1fr; }
    .battery-card-id { font-size: 1.4rem; }
    header { padding: 0.65rem 1rem; }
    nav { display: none; }
}
