/* === Variables & Theme === */
:root {
    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --primary: #3498db;
    --primary-hover: #2980b9;
    --success: #27ae60;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --border: #dfe6e9;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 8px;
    --nav-bg: #2c3e50;
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --bg-card: #16213e;
    --text: #eaeaea;
    --text-muted: #a0a0a0;
    --border: #2a2a4a;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --nav-bg: #0f3460;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Layout === */
.container { max-width: 1000px; margin: 0 auto; padding: 20px; flex: 1; }

/* === Navbar === */
.navbar {
    background: var(--nav-bg);
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.nav-brand {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
}

.powered-by {
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.7;
    margin-left: 4px;
    font-style: italic;
}

.nav-links {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-links a {
    color: rgba(255,255,255,0.8);
    padding: 8px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s, color 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
    text-decoration: none;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
}

/* Dropdown */
.nav-dropdown { position: relative; }
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 180px;
    list-style: none;
    z-index: 200;
}
.dropdown-menu a {
    display: block;
    padding: 10px 16px;
    color: var(--text);
    font-size: 0.9rem;
}
.dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.nav-dropdown:hover .dropdown-menu { display: block; }

/* Theme toggle */
.theme-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border-top: 3px solid var(--primary);
}

.stat-card.highlight { border-top-color: var(--success); }

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* === Section === */
.section { margin-bottom: 24px; }
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

/* === Table === */
.table-responsive { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.table th {
    background: var(--nav-bg);
    color: #fff;
    padding: 12px 14px;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.table tbody tr:hover { background: rgba(52, 152, 219, 0.05); }

/* === Forms === */
.form { max-width: 600px; }

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--bg-card);
    color: var(--text);
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
}

.form-inline {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.form-error {
    display: block;
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.inline-form { display: inline; }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    text-align: center;
    color: var(--text);
    background: var(--bg);
}

.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #c8d6e5; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1.05rem; }

/* === Brand Management === */
.brand-list { display: flex; flex-direction: column; gap: 8px; }

.brand-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.brand-edit-form {
    display: flex;
    gap: 8px;
    flex: 1;
    align-items: center;
}

.brand-input { flex: 1; }

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; }

/* === Misc === */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.help-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

/* === Date Opened Column === */
.date-opened-cell {
    white-space: nowrap;
}

.date-opened-status {
    font-size: 0.85rem;
    font-weight: 500;
}

.date-opened-status.all-opened {
    color: var(--success);
}

.date-opened-status.some-opened {
    color: #856404;
}

.date-opened-status.not-opened {
    color: var(--text-muted);
    font-style: italic;
    font-weight: 400;
}

/* === Box Openings === */
.box-opening-row td {
    padding: 4px 14px 12px !important;
    background: var(--bg);
    border-bottom: 2px solid var(--border);
}

.box-opening-row:hover {
    background: transparent !important;
}

.box-opening-strip {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.box-opening-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    padding-top: 6px;
}

.box-opening-items {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.box-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
}

.box-chip.chip-opened {
    border-color: var(--success);
    background: #d4edda;
}

[data-theme="dark"] .box-chip.chip-opened {
    background: rgba(39, 174, 96, 0.15);
}

.box-chip.chip-unopened {
    border-color: var(--border);
    background: var(--bg-card);
}

.chip-label {
    font-weight: 600;
    white-space: nowrap;
}

.chip-date {
    color: var(--success);
    font-weight: 500;
}

.chip-form {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chip-date-input {
    padding: 2px 6px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text);
    width: 130px;
}

.chip-btn {
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.chip-btn-open {
    background: var(--primary);
    color: #fff;
}

.chip-btn-open:hover {
    background: var(--primary-hover);
}

.chip-btn-update {
    background: var(--border);
    color: var(--text);
}

.chip-btn-update:hover {
    background: #c8d6e5;
}

.actions-cell {
    white-space: nowrap;
}

.quick-actions { text-align: center; margin-top: 20px; }
.export-actions { margin-top: 20px; display: flex; gap: 12px; }

.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
    .nav-toggle { display: block; }

    .nav-links {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--nav-bg);
        flex-direction: column;
        padding: 12px;
        gap: 4px;
        box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    }

    .nav-links.open { display: flex; }
    .nav-links a { display: block; }

    .dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        background: rgba(255,255,255,0.05);
        border-radius: var(--radius);
    }
    .dropdown-menu a { color: rgba(255,255,255,0.8); }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-value { font-size: 1.4rem; }

    .form-row { grid-template-columns: 1fr; }
    .brand-item { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .container { padding: 12px; }
}
