:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --border: #e0e0e0;
    --text: #252a2e;
    --text-muted: #6b6f73;
    --primary: #fd4f00;
    --primary-hover: #e04600;
    --primary-light: #fff1eb;
    --on-time: #2e7d32;
    --on-time-bg: #e8f5e9;
    --late: #c62828;
    --late-bg: #ffebee;
    --not-done: #ef6c00;
    --not-done-bg: #fff3e0;
    --missing: #6554c0;
    --missing-bg: #eae6ff;
    --brand-grey: #252a2e;
    --brand-grey-light: #3d4145;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

/* ── Header ── */
.app-header {
    background: var(--surface);
    border-bottom: 3px solid var(--primary);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.header-logo {
    height: 32px;
    width: auto;
}

.app-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}
.app-title-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
}

.main-nav { display: flex; gap: 4px; }

.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary); color: #fff; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg); border-color: #c1c7d0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* ── Forms ── */
.month-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}
.month-filter label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.input-field {
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.input-field:focus { border-color: var(--primary); }

/* ── Main content ── */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ── Refresh message ── */
.refresh-message {
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
}
.refresh-message.success { background: var(--on-time-bg); color: var(--on-time); }
.refresh-message.error { background: var(--late-bg); color: var(--late); }
.refresh-message.loading { background: var(--primary-light); color: var(--primary); }

/* ── Summary cards ── */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow);
}
.metric-card-clickable {
    cursor: pointer;
}
.metric-card-clickable:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(253, 79, 0, 0.15);
}
.metric-card-clickable.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(253, 79, 0, 0.2);
}
.metric-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}
.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}
.metric-on-time .metric-value { color: var(--on-time); }
.metric-late .metric-value { color: var(--late); }
.metric-not-done .metric-value { color: var(--not-done); }

/* ── Panels ── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}
.panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}
.panel h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ── Tables ── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th,
.data-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    position: sticky;
    top: 0;
}
.data-table tbody tr:hover { background: #f9fafb; }
.data-table td { max-width: 250px; overflow: hidden; text-overflow: ellipsis; }

/* ── Status badges ── */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}
.status-on_time { background: var(--on-time-bg); color: var(--on-time); }
.status-late { background: var(--late-bg); color: var(--late); }
.status-not_done { background: var(--not-done-bg); color: var(--not-done); }
.status-complete_missing_timestamp,
.status-missing { background: var(--missing-bg); color: var(--missing); }

.source-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    background: var(--bg);
    color: var(--text-muted);
    font-family: monospace;
}

/* ── Score badges ── */
.score-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
}
.score-high { background: var(--on-time-bg); color: var(--on-time); }
.score-mid { background: var(--not-done-bg); color: #b8860b; }
.score-low { background: var(--late-bg); color: var(--late); }

/* ── Chart ── */
.chart-container {
    position: relative;
    max-height: 350px;
    margin-bottom: 8px;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state h2 { font-size: 20px; margin-bottom: 8px; color: var(--text); }

.muted { color: var(--text-muted); font-size: 13px; margin-top: 8px; }

/* ── Breadcrumb ── */
.breadcrumb {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 16px;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.filter-group label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
}

/* ── Info panel ── */
.info-panel { background: #f8f9fa; border-color: #e9ecef; }
.info-panel ul {
    list-style: disc;
    padding-left: 20px;
}
.info-panel li {
    font-size: 13px;
    line-height: 1.8;
    color: var(--text);
}

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 16px 24px;
    font-size: 12px;
    color: #b0b3b6;
    background: var(--brand-grey);
    border-top: none;
    margin-top: 40px;
    display: flex;
    justify-content: center;
    gap: 16px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .app-header { padding: 10px 16px; }
    .header-left { flex-direction: column; align-items: flex-start; gap: 8px; }
    .header-right { width: 100%; justify-content: space-between; }
    .main-content { padding: 16px; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .metric-value { font-size: 22px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .data-table td { font-size: 12px; }
}

.brand-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.brand-versa {
    background: #e3f2fd;
    color: #1565c0;
}
.brand-tss {
    background: #fce4ec;
    color: #c62828;
}

.clickable-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
}
.clickable-row:hover {
    background-color: var(--primary-light);
}

.item-cell {
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.item-popover {
    position: fixed;
    background: var(--text);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
    max-width: 350px;
    white-space: normal;
    word-wrap: break-word;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    pointer-events: none;
}

@media (max-width: 480px) {
    .summary-cards { grid-template-columns: 1fr 1fr; gap: 8px; }
    .metric-card { padding: 12px; }
}

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}
.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    border: 1px solid var(--border);
}
.auth-title {
    font-size: 1.4rem;
    text-align: center;
    margin-bottom: 0.25rem;
    color: var(--primary);
}
.auth-subtitle {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
    color: var(--text);
}
.auth-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-align: center;
}
.auth-form .form-group {
    margin-bottom: 1rem;
}
.auth-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    color: var(--text);
}
.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
}
.auth-form input:focus,
.auth-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(253,79,0,0.15);
}
.form-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}
.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.form-check label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 400;
    cursor: pointer;
}
.btn-full {
    width: 100%;
    padding: 0.6rem;
    font-size: 0.95rem;
}
.auth-error {
    background: var(--late-bg);
    color: var(--late);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(222,53,11,0.2);
}
.auth-success {
    background: var(--on-time-bg);
    color: var(--on-time);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(0,135,90,0.2);
}
.auth-info {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(253,79,0,0.15);
}
.auth-links {
    text-align: center;
    margin-top: 1rem;
}
.auth-links a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.85rem;
}
.auth-links a:hover {
    text-decoration: underline;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
    padding-left: 1rem;
    border-left: 1px solid var(--border);
}
.user-info {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}
.btn-logout {
    background: transparent;
    color: var(--late);
    border-color: var(--late);
}
.btn-logout:hover {
    background: var(--late-bg);
}
.btn-danger {
    background: var(--late);
    color: #fff;
    border-color: var(--late);
}
.btn-danger:hover {
    background: #bf2600;
}
.btn-warning {
    background: var(--not-done);
    color: #fff;
    border-color: var(--not-done);
}
.btn-warning:hover {
    background: #e68a00;
}
.nav-separator {
    color: var(--border);
    margin: 0 0.25rem;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-green {
    background: var(--on-time-bg);
    color: var(--on-time);
}
.badge-red {
    background: var(--late-bg);
    color: var(--late);
}
.badge-orange {
    background: var(--not-done-bg);
    color: #b36b00;
}
.badge-blue {
    background: var(--primary-light);
    color: var(--primary);
}
.badge-gray {
    background: #f4f5f7;
    color: var(--text-muted);
}

