:root {
    --bg-color: #F5F5F7;
    --surface-white: #FFFFFF;

    /* Apple-like System Colors */
    --primary-color: #000000;
    --primary-soft: #1C1C1E;

    --accent-blue: #007AFF;
    --accent-green: #34C759;
    --accent-red: #FF3B30;
    --accent-orange: #FF9500;

    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --text-tertiary: #AEAEB2;

    --border-light: #E5E5EA;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --font-stack: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
}

/* --- Layout --- */
.app-container {
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 20px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-soft);
    color: white;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}

/* Nav Tabs */
.nav-tabs {
    display: flex;
    gap: 5px;
    background: rgba(118, 118, 128, 0.12);
    padding: 4px;
    border-radius: 12px;
}

.nav-tab {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: transparent;
}

.nav-tab.active {
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.user-menu {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.card {
    background: var(--surface-white);
    padding: 25px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.02);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.05em;
    margin: 10px 0 5px 0;
    color: var(--text-primary);
}

.metric-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-sub {
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

/* Tables */
.table-container {
    background: var(--surface-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    /* For radius */
}

.table-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-title {
    font-size: 1.1rem;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 15px 30px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    background: #FAFAFA;
    border-bottom: 1px solid var(--border-light);
}

td {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.95rem;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: #FAFAFA;
}

/* Buttons */
.btn {
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-soft);
    color: white;
}

.btn-primary:hover {
    background: black;
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.btn-danger {
    background: rgba(255, 59, 48, 0.1);
    color: var(--accent-red);
}

.btn-danger:hover {
    background: rgba(255, 59, 48, 0.2);
}

/* Status Badges */
.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge.green {
    background: rgba(52, 199, 89, 0.15);
    color: var(--accent-green);
}

.badge.red {
    background: rgba(255, 59, 48, 0.15);
    color: var(--accent-red);
}

.badge.orange {
    background: rgba(255, 149, 0, 0.15);
    color: var(--accent-orange);
}

.badge.grey {
    background: #F2F2F7;
    color: var(--text-secondary);
}

/* Inputs & Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: white;
    width: 90%;
    max-width: 450px;
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s cubic-bezier(0.19, 1, 0.22, 1);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

/* --- Sections --- */
section {
    display: none;
    animation: fadeIn 0.3s ease;
}

section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Login Page Specifics --- */
body.bg-light {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #F5F5F7;
    margin: 0;
}

.login-container {
    background: var(--surface-white);
    width: 100%;
    max-width: 400px;
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    text-align: center;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.login-header {
    margin-bottom: 30px;
}

.login-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin: 15px 0 5px 0;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.app-logo {
    width: 80px;
    height: auto;
    margin: 0 auto;
    display: block;
    object-fit: contain;
}

.btn-full {
    width: 100%;
    justify-content: center;
    margin-top: 10px;
}

.login-footer {
    margin-top: 30px;
    font-size: 0.85rem;
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* Fix for existing class names in index.html to map to new system */
.btn-app {
    background: var(--primary-soft);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-app:hover {
    background: black;
    transform: translateY(-1px);
}

/* Responsive Design */
@media (max-width: 768px) {

    /* Header Stack */
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
        margin-bottom: 30px;
    }

    .brand {
        width: 100%;
        justify-content: flex-start;
    }

    /* Scrollable Tabs */
    .nav-tabs {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 5px;
        /* Scrollbar space */
        -webkit-overflow-scrolling: touch;

        /* Hide scrollbar visually but keep functionality */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tab {
        flex: 0 0 auto;
        /* Don't shrink */
    }

    /* User Menu Stack */
    .user-menu {
        width: 100%;
        display: flex;
        justify-content: space-between;
        gap: 10px;
        padding-top: 10px;
        border-top: 1px solid var(--border-light);
    }

    .user-menu .btn {
        flex: 1;
        justify-content: center;
        padding: 12px;
    }

    /* Table Mobile (Existing + Tweaks) */
    .table-container {
        background: transparent;
        box-shadow: none;
        border-radius: 0;
    }

    .table-header {
        padding: 0 0 15px 0;
        border: none;
        flex-direction: column;
        /* Stack title and button */
        gap: 10px;
        align-items: flex-start;
    }

    thead {
        display: none;
    }

    tr {
        display: block;
        background: white;
        margin-bottom: 15px;
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
        padding: 20px;
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border-bottom: 1px solid var(--border-light);
    }

    td:last-child {
        border-bottom: none;
    }

    td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.85rem;
    }
}