:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --brand: #111827;
    --accent: #dc2626;
    --accent-ink: #ffffff;
    --ok: #16a34a;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --tap: 48px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-text-size-adjust: 100%;
}

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

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top) 16px 0;
    height: calc(56px + env(safe-area-inset-top));
    background: var(--brand);
    color: #fff;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
}

.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-size: 16px; letter-spacing: 0.2px; }

.app-main {
    flex: 1;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.page-title {
    font-size: 20px;
    margin: 4px 0 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* --- Search --- */
.search-bar { margin-bottom: 14px; }
.search-input {
    width: 100%;
    height: var(--tap);
    padding: 0 14px;
    font-size: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

/* --- Product / variants --- */
.product-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.product-thumb {
    width: 44px; height: 44px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--line);
}
.product-title { font-weight: 600; font-size: 15px; }

.ship-box {
    font-size: 13px;
    color: var(--muted);
    margin: -2px 0 10px;
}

.variant-list { display: flex; flex-direction: column; gap: 8px; }
.variant {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-height: var(--tap);
    padding: 8px 12px;
    text-align: left;
    background: #fafafa;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 15px;
    cursor: pointer;
}
.variant.active {
    border-color: var(--brand);
    box-shadow: inset 0 0 0 1px var(--brand);
    background: #fff;
}
.variant-name { font-weight: 600; }
.variant-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.variant-meta .price { font-weight: 700; }
.variant-meta .stock { font-size: 12px; color: var(--ok); }
.variant-meta .stock.out { color: var(--accent); }
.variant-meta .sku { font-size: 12px; color: var(--muted); }

/* --- Quote panel --- */
.quote-panel { position: sticky; bottom: 0; }
.quote-selected {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}
.quote-name { font-weight: 700; }
.quote-price { color: var(--muted); font-size: 14px; }

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field .qty {
    height: var(--tap);
    padding: 0 12px;
    font-size: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    width: 100%;
}

.rate-list { list-style: none; margin: 14px 0 6px; padding: 0; }
.rate {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 4px;
    border-bottom: 1px solid var(--line);
}
.rate:last-child { border-bottom: none; }
.rate-title { font-weight: 600; }
.rate-amount { font-weight: 800; font-size: 18px; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 18px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
}
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:disabled { opacity: 0.6; }
.btn-block { width: 100%; }

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 2px;
}
.logout-form { margin: 0; }
.app-header .link-btn { color: #fff; opacity: 0.9; }

/* --- Alerts --- */
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
.alert.info { background: #eff6ff; color: #1e3a8a; }
.alert.error { background: #fef2f2; color: #991b1b; }
.alert.success { background: #f0fdf4; color: #166534; }

/* --- Login --- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--brand);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.login-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.login-brand h1 { font-size: 20px; margin: 0; }
.login-form { margin-top: 16px; }

/* --- Header nav --- */
.app-nav { display: flex; align-items: center; gap: 14px; }
.nav-link {
    color: #fff;
    opacity: 0.75;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    padding: 4px 2px;
}
.nav-link.active { opacity: 1; border-bottom: 2px solid var(--accent); }

/* --- Select --- */
.select {
    height: var(--tap);
    padding: 0 12px;
    font-size: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    width: 100%;
}

/* --- Report --- */
.report-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin: 6px 0 12px;
}
.report-title { font-weight: 700; font-size: 17px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--surface);
}
.report-table th, .report-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
.report-table thead th {
    position: sticky;
    top: 0;
    background: #f9fafb;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}
.report-table .num { text-align: right; white-space: nowrap; }
.report-table .strong { font-weight: 800; }

/* --- Print: just the table, ink-friendly --- */
@media print {
    .no-print, .app-header, .app-nav { display: none !important; }
    .app-main { max-width: none; padding: 0; }
    .card { box-shadow: none; border: none; }
    body { background: #fff; }
    .report-table thead th { position: static; background: #fff; color: #000; }
    .report-table th, .report-table td { border-bottom: 1px solid #ccc; }
    .table-scroll { overflow: visible; }
    a[href]:after { content: ""; }
}
