* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Navigation */
nav {
    background: #1a5276;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 0;
}

nav a {
    color: #ecf0f1;
    text-decoration: none;
    padding: 15px 20px;
    display: inline-block;
    transition: background 0.2s;
}

nav a:hover, nav a.active {
    background: #1f6a96;
}

nav .brand {
    font-weight: bold;
    font-size: 1.1em;
    margin-right: 20px;
}

nav .spacer {
    flex-grow: 1;
}

h1 {
    color: #1a5276;
    margin-bottom: 10px;
}

/* Period Bar */
.period-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.period-tabs {
    display: flex;
    gap: 4px;
    background: #fff;
    padding: 6px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: fit-content;
}

.period-tab {
    padding: 8px 18px;
    border-radius: 5px;
    text-decoration: none;
    color: #555;
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.2s;
}

.period-tab:hover {
    background: #eef2f7;
}

.period-tab.active {
    background: #1a5276;
    color: #fff;
}

/* Date Range Picker */
.date-range {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.date-range input[type="date"] {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 7px 10px;
    font-size: 0.88em;
    font-family: inherit;
    color: #333;
}

.date-range input[type="date"]:focus {
    outline: none;
    border-color: #1a5276;
}

.date-sep {
    color: #aaa;
    font-size: 0.9em;
}

/* KPI Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin: 20px 0;
}

.card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card h3 {
    font-size: 0.8em;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.card .value {
    font-size: 1.8em;
    font-weight: 700;
    color: #1a5276;
}

.card-subtitle {
    font-size: 0.82em;
    color: #27ae60;
    margin-top: 4px;
    font-weight: 500;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 24px 0;
}

.chart-box {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chart-box h3 {
    font-size: 0.95em;
    color: #555;
    margin-bottom: 12px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin: 10px 0;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background: #1a5276;
    color: #fff;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
}

tr:hover {
    background: #f8f9fa;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 0.78em;
    font-weight: 600;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}

.badge-warning {
    background: #fff3cd;
    color: #856404;
}

/* Section */
.section {
    margin: 30px 0;
}

.section h2 {
    margin-bottom: 12px;
    color: #1a5276;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
}

.form-group input:focus {
    outline: none;
    border-color: #1a5276;
    box-shadow: 0 0 0 2px rgba(26,82,118,0.2);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    text-decoration: none;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.85;
}

.btn-primary {
    background: #1a5276;
    color: #fff;
}

/* Alerts */
.alert {
    padding: 12px 20px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Login */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-box {
    background: #fff;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #1a5276;
}

/* Daily Breakdown Table */
.daily-table .day-row {
    cursor: pointer;
    transition: background 0.15s;
}

.daily-table .day-row:hover {
    background: #edf2f7;
}

.daily-table .day-row.expanded {
    background: #e1ecf7;
}

.expand-icon {
    width: 28px;
    text-align: center;
    color: #999;
    font-size: 0.75em;
    transition: color 0.15s;
    user-select: none;
}

.day-row.expanded .expand-icon {
    color: #1a5276;
}

.day-date {
    font-weight: 600;
    color: #1a5276;
}

.day-row .total-hint {
    color: #aaa;
    font-size: 0.85em;
}

.day-detail-row td {
    padding: 0;
    background: #f8fafb;
}

.day-detail-content {
    padding: 12px 20px;
}

.day-detail-content .no-data {
    color: #999;
    font-style: italic;
    padding: 8px 0;
}

.daily-totals-row td {
    background: #f0f4f8;
    border-top: 2px solid #d0d8e0;
    font-size: 0.92em;
    color: #333;
}

.empty-state {
    background: #fff;
    padding: 40px;
    text-align: center;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    color: #999;
    font-size: 1.05em;
}

.ref-code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.9em;
    color: #1a5276;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Detail Orders Sub-Table */
.detail-orders-table {
    width: 100%;
    border-collapse: collapse;
    box-shadow: none;
    margin: 0;
    border-radius: 4px;
    overflow: hidden;
    table-layout: fixed;
}

.detail-orders-table th,
.detail-orders-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-orders-table th:nth-child(1),
.detail-orders-table td:nth-child(1) { width: 14%; }
.detail-orders-table th:nth-child(2),
.detail-orders-table td:nth-child(2) { width: 12%; }
.detail-orders-table th:nth-child(3),
.detail-orders-table td:nth-child(3) { width: 28%; }
.detail-orders-table th:nth-child(4),
.detail-orders-table td:nth-child(4) { width: 28%; }
.detail-orders-table th:nth-child(5),
.detail-orders-table td:nth-child(5) { width: 18%; }

.detail-orders-table th {
    background: #2c3e50;
    font-size: 0.78em;
    padding: 8px 12px;
}

.detail-orders-table td {
    padding: 7px 12px;
    font-size: 0.88em;
    border-bottom: 1px solid #eef0f2;
}

.detail-orders-table tr:hover {
    background: #f0f4f8;
}

/* Utility */
.text-danger {
    color: #e74c3c;
    font-weight: 600;
}

.badge-secondary {
    background: #e2e3e5;
    color: #383d41;
}

.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.85em;
}

.btn-secondary {
    background: #95a5a6;
    color: #fff;
}

/* Referral link box */
.referral-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #eef2f7;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.referral-label {
    font-weight: 600;
    color: #555;
    white-space: nowrap;
    font-size: 0.9em;
}

.referral-icon {
    width: 20px;
    height: 20px;
    vertical-align: text-bottom;
    margin-right: 4px;
}

.referral-link {
    background: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.9em;
    user-select: all;
    word-break: break-all;
    flex: 1;
}

/* Notification badge in nav */
.nav-badge {
    display: inline-block;
    background: #e74c3c;
    color: #fff;
    font-size: 0.7em;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 4px;
    vertical-align: top;
    min-width: 16px;
    text-align: center;
    line-height: 1.4;
}

/* Alert success */
.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    padding: 12px 20px;
    border-radius: 4px;
    margin-bottom: 20px;
}

/* Settings Page */
.settings-page {
    max-width: 480px;
}

.settings-section h3 {
    color: #1a5276;
    font-size: 1em;
    margin-bottom: 12px;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-select {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95em;
    font-family: inherit;
    min-width: 180px;
}

.settings-form {
    max-width: 320px;
}

.settings-divider {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 24px 0;
}

/* Responsive */
@media (max-width: 900px) {
    .cards {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 500px) {
    .cards {
        grid-template-columns: 1fr;
    }
    .period-tabs {
        flex-wrap: wrap;
    }
}
