:root {
    --color-bg: #f1f5f9;
    --color-surface: #ffffff;
    --color-primary: #18181b;
    --color-primary-dark: #000000;
    --color-primary-light: #f4f4f5;
    --color-accent: #3f3f46;
    --color-text: #1e293b;
    --color-muted: #64748b;
    --color-border: #e2e8f0;
    --color-error-bg: #fee2e2;
    --color-error-text: #991b1b;
    --color-reserved-bg: #fef3c7;
    --color-reserved-text: #92400e;
    --radius: 18px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-hover: 0 4px 8px rgba(15, 23, 42, 0.06), 0 16px 32px rgba(15, 23, 42, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Login ---------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    background: radial-gradient(circle at top, #f4f4f5 0%, #f1f5f9 55%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border-radius: 24px;
    box-shadow: var(--shadow-hover);
    padding: 40px 28px;
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle {
    margin: 0 0 28px;
    color: var(--color-muted);
    font-size: 14px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-card label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
    margin-top: 10px;
}

.login-card input {
    padding: 13px 14px;
    font-size: 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-card input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.login-card button,
.modal-actions button[type="submit"] {
    margin-top: 22px;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.15s ease;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.login-card button:active {
    transform: scale(0.98);
}

.alert {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin: 0 0 12px;
}

.alert-error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
}

/* ---------- App shell ---------- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.app-header-title {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.logo {
    font-weight: 800;
    font-size: 19px;
    letter-spacing: -0.01em;
    user-select: none;
}

.user-name {
    font-size: 12px;
    opacity: 0.85;
}

.logout-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    padding: 9px 14px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    transition: background 0.15s ease;
}

.logout-link:active {
    background: rgba(255, 255, 255, 0.25);
}

.app-main {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

.date-picker {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.date-picker label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
}

.date-picker input {
    padding: 13px 14px;
    font-size: 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.date-picker input:hover {
    border-color: var(--color-accent);
}

.date-picker input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

@media (min-width: 720px) {
    .app-header {
        padding: 18px 32px;
    }

    .app-main {
        max-width: 1180px;
        padding: 28px 32px 56px;
    }

    .date-picker {
        flex-direction: row;
        align-items: center;
        gap: 12px;
        margin-bottom: 28px;
    }

    .date-picker label {
        margin: 0;
    }

    .date-picker input {
        width: auto;
        min-width: 220px;
    }

    .logout-link:hover {
        background: rgba(255, 255, 255, 0.2);
    }
}

@media (min-width: 1400px) {
    .app-main {
        max-width: 1400px;
    }
}

.status-message {
    text-align: center;
    color: var(--color-muted);
    padding: 14px 0;
    font-size: 14px;
}

/* ---------- Summary / store cards ---------- */

.summary-card {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    padding: 22px;
    margin-bottom: 24px;
}

.summary-card .card-title h2 {
    color: #fff;
}

.summary-card .metric-label {
    color: rgba(255, 255, 255, 0.75);
}

.summary-card .metric-value {
    color: #fff;
}

.summary-card .metric {
    background: rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.stores-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 640px) {
    .stores-list {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 18px;
    }
}

@media (min-width: 1400px) {
    .stores-list {
        gap: 22px;
    }
}

.store-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    border-top: 4px solid var(--store-color, var(--color-primary));
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

@media (hover: hover) {
    .store-card:hover {
        transform: translateY(-3px);
        box-shadow: var(--shadow-hover);
    }
}

@media (min-width: 720px) {
    .store-card,
    .summary-card {
        padding: 24px;
    }
}

.card-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.summary-card .card-title,
.store-card .card-title {
    justify-content: space-between;
}

.store-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 12px;
    background: var(--store-color, var(--color-primary));
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

.store-card .card-title h3 {
    flex: 1;
}

.card-title h2,
.card-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.reserved-badge {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-reserved-text);
    background: var(--color-reserved-bg);
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.metric {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--color-bg);
}

.metric-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
}

.metric-value {
    flex-shrink: 0;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: right;
    white-space: nowrap;
}

.metric-invoices {
    background: var(--color-primary-light);
}

.metric-invoices .metric-value {
    color: var(--color-primary-dark);
}

.metric-reserved {
    background: var(--color-reserved-bg);
}

.metric-reserved .metric-value {
    color: var(--color-reserved-text);
}

/* ---------- T_R13 modal ---------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    animation: fade-in 0.15s ease;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 26px 24px calc(24px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.2);
    animation: slide-up 0.2s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slide-up {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (min-width: 640px) {
    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: var(--radius);
    }
}

.modal-content h2 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
}

.modal-content p {
    margin: 0 0 16px;
    color: var(--color-muted);
    font-size: 14px;
}

.modal-content input {
    width: 100%;
    padding: 13px 14px;
    font-size: 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.modal-actions button {
    flex: 1;
    padding: 13px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--color-border);
    background: #fff;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.modal-actions button:active {
    transform: scale(0.98);
}

.modal-actions button[type="submit"] {
    margin-top: 0;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff;
    border: none;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

@media (min-width: 480px) {
    .summary-card .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 720px) {
    .summary-card .metrics-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1400px) {
    .metric-value {
        font-size: 17px;
    }
}
