/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --sidebar-w: 240px;
    --topbar-h: 60px;

    --c-bg:        #f4f6f9;
    --c-sidebar:   #1a1a2e;
    --c-sidebar-h: #0f3460;
    --c-card:      #ffffff;
    --c-border:    #e8ecf0;
    --c-text:      #2d3748;
    --c-muted:     #718096;
    --c-logo:      #e94560;

    --c-blue:   #4361ee;
    --c-green:  #2ecc71;
    --c-orange: #f39c12;
    --c-purple: #9b59b6;
    --c-red:    #e74c3c;

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.07);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
    --radius:    10px;
    --transition: 0.2s ease;
}

html { font-size: 16px; }

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

a { text-decoration: none; color: inherit; }
button, input, select { font-family: inherit; }

/* ===== LAYOUT ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--c-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    transition: transform var(--transition);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo .logo-icon {
    width: 34px; height: 34px;
    background: var(--c-logo);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; color: #fff;
    flex-shrink: 0;
}
.sidebar-logo .logo-text { color: #fff; font-weight: 700; font-size: 0.95rem; line-height: 1.2; }
.sidebar-logo .logo-sub { color: rgba(255,255,255,0.45); font-size: 0.7rem; font-weight: 400; }

.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.nav-section { padding: 0 1rem; margin-bottom: 0.5rem; }
.nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.3);
    padding: 0.5rem 0.5rem 0.3rem;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 7px;
    color: rgba(255,255,255,0.65);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 0.15rem;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--c-logo); color: #fff; }
.nav-item i { width: 18px; text-align: center; font-size: 0.9rem; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.75rem;
    color: rgba(255,255,255,0.3);
    text-align: center;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
    height: var(--topbar-h);
    background: var(--c-card);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-title { font-size: 1rem; font-weight: 600; color: var(--c-text); }
.topbar-subtitle { font-size: 0.8rem; color: var(--c-muted); }

.topbar-right { display: flex; align-items: center; gap: 1rem; }

.live-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: #e8f8f0;
    color: #1e8449;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.live-badge .dot {
    width: 7px; height: 7px;
    background: var(--c-green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--c-muted);
}
.user-chip .avatar {
    width: 30px; height: 30px;
    background: var(--c-sidebar-h);
    border-radius: 50%;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--c-muted);
    cursor: pointer;
    padding: 0.25rem;
}

/* ===== PAGE BODY ===== */
.page-body { padding: 1.5rem; flex: 1; }

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.toolbar-left { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 7px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity var(--transition), background var(--transition);
    white-space: nowrap;
}
.btn:hover { opacity: 0.88; }
.btn-primary { background: var(--c-blue); color: #fff; }
.btn-secondary { background: var(--c-muted); color: #fff; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--c-border);
    color: var(--c-text);
}
.btn-outline:hover { background: var(--c-bg); opacity: 1; }
.btn-danger { background: var(--c-red); color: #fff; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-xs { padding: 0.2rem 0.5rem; font-size: 0.75rem; }

/* ===== FORM CONTROLS ===== */
.input {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--c-border);
    border-radius: 7px;
    font-size: 0.85rem;
    color: var(--c-text);
    background: #fff;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus { border-color: var(--c-blue); box-shadow: 0 0 0 3px rgba(67,97,238,0.12); }

/* ===== KPI CARDS ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.kpi-card {
    background: var(--c-card);
    border-radius: var(--radius);
    padding: 1.2rem 1.4rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 4px;
    border-radius: var(--radius) 0 0 var(--radius);
}
.kpi-card.blue::before   { background: var(--c-blue); }
.kpi-card.green::before  { background: var(--c-green); }
.kpi-card.orange::before { background: var(--c-orange); }
.kpi-card.purple::before { background: var(--c-purple); }

.kpi-icon {
    width: 42px; height: 42px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.kpi-card.blue   .kpi-icon { background: rgba(67,97,238,0.12);  color: var(--c-blue); }
.kpi-card.green  .kpi-icon { background: rgba(46,204,113,0.12); color: #1e8449; }
.kpi-card.orange .kpi-icon { background: rgba(243,156,18,0.12); color: #d68910; }
.kpi-card.purple .kpi-icon { background: rgba(155,89,182,0.12); color: var(--c-purple); }

.kpi-body { flex: 1; min-width: 0; }
.kpi-value { font-size: 1.65rem; font-weight: 700; color: var(--c-text); line-height: 1.1; }
.kpi-label { font-size: 0.78rem; color: var(--c-muted); margin-top: 0.2rem; font-weight: 500; }
.kpi-sub { font-size: 0.73rem; color: var(--c-muted); margin-top: 0.4rem; }

/* ===== CHARTS ROW ===== */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.card {
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--c-border);
}
.card-title { font-size: 0.9rem; font-weight: 600; color: var(--c-text); }
.card-body { padding: 1.25rem; }

.chart-wrap { position: relative; height: 220px; }

/* ===== RECENTS LIST ===== */
.recents-list { list-style: none; }
.recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--c-border);
    gap: 0.5rem;
}
.recent-item:last-child { border-bottom: none; }
.recent-plate { font-family: "Courier New", monospace; font-weight: 700; font-size: 0.88rem; }
.recent-weight { font-weight: 700; color: var(--c-blue); font-size: 0.88rem; }
.recent-time { font-size: 0.75rem; color: var(--c-muted); }

/* ===== TABLE CARD ===== */
.table-card {
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--c-border);
    gap: 0.75rem;
    flex-wrap: wrap;
}
.table-toolbar-left { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.table-toolbar-right { display: flex; align-items: center; gap: 0.5rem; }

.search-wrap { position: relative; }
.search-wrap i { position: absolute; left: 0.6rem; top: 50%; transform: translateY(-50%); color: var(--c-muted); font-size: 0.8rem; }
.search-wrap .input { padding-left: 2rem; width: 200px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    background: #f8f9fb;
    padding: 0.65rem 1rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--c-muted);
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
thead th:hover { color: var(--c-text); }
thead th i { margin-left: 0.3rem; font-size: 0.65rem; }

tbody td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover td { background: #f8f9fb; }

.td-ticket { font-family: "Courier New", monospace; font-size: 0.8rem; color: var(--c-muted); }
.td-time { font-size: 0.82rem; color: var(--c-muted); white-space: nowrap; }
.td-plate {
    font-family: "Courier New", monospace;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    background: var(--c-bg);
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
}
.td-weight { font-weight: 700; color: var(--c-blue); white-space: nowrap; }
.td-tag {
    font-size: 0.75rem;
    background: var(--c-bg);
    color: var(--c-muted);
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    display: inline-block;
    white-space: nowrap;
}
.empty-row td { text-align: center; color: var(--c-muted); padding: 2.5rem !important; font-size: 0.9rem; }

/* ===== STATUS BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-green  { background: #d4efdf; color: #1e8449; }
.badge-yellow { background: #fef9e7; color: #d68910; }
.badge-red    { background: #fdedec; color: #c0392b; }
.badge-gray   { background: #f0f3f6; color: #718096; }

/* ===== TABLE FOOTER ===== */
.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--c-border);
    font-size: 0.8rem;
    color: var(--c-muted);
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    background: var(--c-bg);
}
.login-left {
    flex: 1;
    background: linear-gradient(145deg, #1a1a2e 0%, #0f3460 60%, #16213e 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}
.login-left::after {
    content: '';
    position: absolute;
    bottom: -60px; right: -60px;
    width: 300px; height: 300px;
    background: rgba(233,69,96,0.12);
    border-radius: 50%;
}
.login-left::before {
    content: '';
    position: absolute;
    top: -40px; left: -40px;
    width: 200px; height: 200px;
    background: rgba(67,97,238,0.1);
    border-radius: 50%;
}
.login-brand { position: relative; z-index: 1; text-align: center; }
.login-brand-icon {
    width: 70px; height: 70px;
    background: var(--c-logo);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8rem; color: #fff;
    margin: 0 auto 1.2rem;
    box-shadow: 0 8px 24px rgba(233,69,96,0.35);
}
.login-brand h1 { color: #fff; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.4rem; }
.login-brand p { color: rgba(255,255,255,0.55); font-size: 0.9rem; max-width: 280px; line-height: 1.5; }
.login-features { margin-top: 2.5rem; position: relative; z-index: 1; }
.login-feature {
    display: flex; align-items: center; gap: 0.75rem;
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    margin-bottom: 0.9rem;
}
.login-feature i { color: var(--c-green); font-size: 0.9rem; width: 16px; }

.login-right {
    width: 440px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.login-box {
    width: 100%;
    max-width: 360px;
}
.login-box h2 { font-size: 1.4rem; font-weight: 700; color: var(--c-text); margin-bottom: 0.3rem; }
.login-box .login-sub { font-size: 0.87rem; color: var(--c-muted); margin-bottom: 2rem; }

.form-group { margin-bottom: 1.1rem; }
.form-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--c-text); margin-bottom: 0.4rem; }
.input-icon-wrap { position: relative; }
.input-icon-wrap i { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--c-muted); font-size: 0.85rem; }
.input-icon-wrap .input { width: 100%; padding-left: 2.2rem; padding-top: 0.6rem; padding-bottom: 0.6rem; font-size: 0.9rem; }

.login-box .btn-primary { width: 100%; justify-content: center; padding: 0.65rem; font-size: 0.9rem; margin-top: 0.5rem; }

.alert {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem;
    border-radius: 7px;
    font-size: 0.85rem;
    margin-bottom: 1.1rem;
}
.alert-error { background: #fdedec; color: #c0392b; border: 1px solid #f5c6cb; }

.login-footer { margin-top: 2rem; text-align: center; font-size: 0.78rem; color: var(--c-muted); }

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-left: 0; }
    .hamburger { display: flex; }
}

@media (max-width: 600px) {
    .login-page { flex-direction: column; }
    .login-left { display: none; }
    .login-right { width: 100%; padding: 2rem 1.25rem; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .page-body { padding: 1rem; }
    .table-toolbar { flex-direction: column; align-items: flex-start; }
    .search-wrap .input { width: 100%; }
}

@media (max-width: 380px) {
    .kpi-grid { grid-template-columns: 1fr; }
}
