*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f2f7f8;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --surface-hover: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --primary: #0F6C73;
    --primary-hover: #0c5a60;
    --primary-light: #14919a;
    --primary-subtle: #e8f5f6;
    --primary-border: #b8dde0;
    --secondary: #E6682A;
    --secondary-hover: #cf5c24;
    --secondary-light: #f08045;
    --secondary-subtle: #fef4eb;
    --secondary-border: #f5c4a3;
    --header-bg: linear-gradient(135deg, #094d54 0%, #0F6C73 52%, #12818a 100%);
    --header-shadow: 0 4px 20px rgba(15, 106, 115, 0.28);
    --success: #15803d;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --radius: 14px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.08);
    --header-height: 76px;
    --content-max: 760px;
    --content-wide: 1080px;
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 2.75rem;
    --transition: 0.2s ease;
    --focus-ring: 0 0 0 3px rgba(15, 106, 115, 0.32);
    --focus-ring-secondary: 0 0 0 3px rgba(230, 104, 42, 0.32);
}

html {
    color-scheme: light;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    color: var(--primary-hover);
}

/* ── App layout ── */

.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg) var(--space-2xl);
}

.main-content--wide {
    max-width: var(--content-wide);
}

.main-content--centered {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: var(--space-2xl);
    padding-bottom: var(--space-2xl);
}

.content-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.page-login .main-content--centered {
    padding-top: var(--space-xl);
}

/* ── Site header (prominent) ── */

.site-header {
    background: var(--header-bg);
    box-shadow: var(--header-shadow);
    position: sticky;
    top: 0;
    z-index: 200;
}

.header-inner {
    max-width: var(--content-wide);
    margin: 0 auto;
    padding: 0 var(--space-lg);
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    text-decoration: none;
    color: #fff;
    flex-shrink: 0;
    min-width: 0;
}

.header-brand:hover {
    color: #fff;
    text-decoration: none;
}

.header-brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: #fff;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
}

.header-brand-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.header-brand-title {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
    white-space: nowrap;
}

.header-brand-sub {
    font-size: 0.72rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.72);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
}

.header-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    border: 1px solid transparent;
}

.header-nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
}

.header-nav-link.active {
    color: var(--primary);
    background: #fff;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.header-actions {
    flex-shrink: 0;
}

.btn-header-logout {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}

.btn-header-logout:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
}

.btn-header-logout:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}

.logout-form {
    display: inline;
}

/* ── Footer ── */

.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.footer-inner {
    max-width: var(--content-wide);
    margin: 0 auto;
    padding: var(--space-lg) var(--space-lg);
    text-align: center;
}

.footer-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.footer-text strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.footer-dot {
    margin: 0 0.35rem;
    color: var(--border-strong);
}

.footer-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.85;
}

/* ── Page header ── */

.page-header {
    margin-bottom: var(--space-xl);
}

.page-title {
    font-size: 1.875rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.25;
    color: var(--text);
    margin-bottom: var(--space-xs);
}

.page-subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    max-width: 560px;
    line-height: 1.55;
}

/* ── Cards ── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.login-card {
    width: 100%;
    max-width: 440px;
}

.card-header {
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border);
    background: var(--surface-hover);
}

.card-header--centered {
    text-align: center;
    padding: var(--space-xl);
}

.card-header--split {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    margin-bottom: 0.25rem;
    line-height: 1.35;
}

.card-description {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.card-body {
    padding: var(--space-xl);
}

.card-body--bordered {
    border-top: 1px solid var(--border);
}

.card-body--flush {
    padding: 0;
}

/* ── Badge ── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-subtle);
    border: 1px solid var(--primary-border);
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge--accent {
    color: var(--secondary);
    background: var(--secondary-subtle);
    border-color: var(--secondary-border);
}

.badge--success {
    color: var(--success);
    background: var(--success-bg);
    border-color: var(--success-border);
}

/* ── Forms ── */

.form {
    display: flex;
    flex-direction: column;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg) var(--space-xl);
    margin-bottom: var(--space-xl);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9375rem;
    line-height: 1.4;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input::placeholder {
    color: #94a3b8;
}

.form-group input:hover {
    border-color: #94a3b8;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: var(--focus-ring);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border);
}

.login-card .form-actions {
    padding-top: var(--space-md);
    border-top: none;
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.35rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), box-shadow var(--transition), transform 0.1s ease;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

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

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

.btn-primary:focus-visible {
    box-shadow: var(--focus-ring-primary);
}

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

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

.btn-secondary:focus-visible {
    box-shadow: var(--focus-ring-secondary);
}

/* ── Messages ── */

.messages {
    list-style: none;
    margin-bottom: var(--space-lg);
}

.messages li {
    padding: 0.8rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: var(--space-xs);
    font-weight: 500;
}

.messages .success {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success);
}

.messages .error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger);
}

/* ── Login ── */

.login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: var(--primary-subtle);
    color: var(--primary);
    border-radius: var(--radius);
    margin-bottom: var(--space-md);
}

/* ── Generate form toggle ── */

.generate-form {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.45s ease, opacity 0.3s ease;
}

.generate-form.visible {
    max-height: 600px;
    opacity: 1;
}

/* ── Data tables ── */

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table thead th {
    text-align: left;
    padding: 0.85rem 1.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 700;
    color: var(--text-muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table thead th:first-child {
    padding-left: var(--space-xl);
}

.data-table thead th:last-child {
    padding-right: var(--space-xl);
}

.data-table tbody td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    vertical-align: middle;
}

.data-table tbody td:first-child {
    padding-left: var(--space-xl);
}

.data-table tbody td:last-child {
    padding-right: var(--space-xl);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--surface-hover);
}

.data-table tbody tr:nth-child(even) {
    background: rgba(248, 250, 252, 0.6);
}

.data-table tbody tr:nth-child(even):hover {
    background: var(--surface-hover);
}

.col-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.col-actions {
    text-align: center;
    width: 90px;
}

.cell-badge {
    display: inline-block;
    font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-subtle);
    border: 1px solid var(--primary-border);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-xs);
}

.cell-product {
    font-weight: 500;
    color: var(--text);
}

.cell-muted {
    color: var(--text-muted);
}

.cell-time {
    display: block;
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 0.1rem;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: var(--primary-subtle);
    color: var(--primary);
    border: 1px solid var(--primary-border);
    transition: background var(--transition), color var(--transition), border-color var(--transition), transform 0.1s ease;
}

.download-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    text-decoration: none;
    transform: translateY(-1px);
}

.download-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ── Empty state ── */

.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-xl);
    color: var(--text-muted);
}

.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    margin-bottom: var(--space-lg);
}

.empty-state strong {
    display: block;
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: var(--space-xs);
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: var(--space-lg);
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

/* ── Responsive ── */

@media (max-width: 900px) {
    .header-inner {
        gap: var(--space-md);
    }

    .header-brand-sub {
        display: none;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: var(--space-lg) var(--space-md) var(--space-xl);
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }

    .card-header,
    .card-body {
        padding: var(--space-lg);
    }

    .card-header--split {
        flex-direction: column;
        align-items: stretch;
    }

    .card-header--split .btn {
        width: 100%;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .data-table thead th:first-child,
    .data-table tbody td:first-child {
        padding-left: var(--space-lg);
    }

    .data-table thead th:last-child,
    .data-table tbody td:last-child {
        padding-right: var(--space-lg);
    }
}

@media (max-width: 640px) {
    :root {
        --header-height: auto;
    }

    .header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: var(--space-md);
        gap: var(--space-sm);
    }

    .header-nav {
        order: 3;
        width: 100%;
        margin-left: 0;
        justify-content: stretch;
    }

    .header-nav-link {
        flex: 1;
        justify-content: center;
        padding: 0.6rem 0.5rem;
    }

    .header-actions {
        margin-left: auto;
    }

    .footer-dot {
        display: none;
    }

    .footer-text {
        font-size: 0.8rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
