:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e3e7ee;
    --text: #1a1f2b;
    --muted: #6b7280;
    --primary: #2f6df6;
    --primary-hover: #245bd6;
    --primary-soft: #e9f0ff;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --sidebar: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #1e293b;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

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

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 1rem; }
code { background: #eef1f6; padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* ---------- Guest layout (login) ---------- */

.guest-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.guest-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
}

.brand-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800;
}

/* ---------- App layout ---------- */

.app {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: 100vh;
}

/* Sidebar: pinned to the viewport, scrolls on its own; never grows with the page */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 10px 16px; }
.sidebar .brand { color: #fff; }
.sidebar-close { display: none; background: none; border: none; color: var(--sidebar-text); padding: 6px; border-radius: 8px; cursor: pointer; }
.sidebar-close:hover { background: var(--sidebar-active); color: #fff; }
.sidebar-close svg { width: 20px; height: 20px; display: block; }
.sidebar-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* Mobile top bar (hidden on desktop) */
.topbar {
    display: none;
    grid-column: 1 / -1;
    position: sticky; top: 0; z-index: 30;
    align-items: center; gap: 10px;
    height: 56px; padding: 0 12px;
    background: var(--sidebar); color: #fff;
}
.topbar .brand { color: #fff; font-size: 1.05rem; }
.topbar-toggle { background: none; border: none; color: #fff; padding: 8px; border-radius: 8px; cursor: pointer; display: inline-flex; }
.topbar-toggle:hover { background: var(--sidebar-active); }
.topbar-toggle svg { width: 24px; height: 24px; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 40; }

.nav { list-style: none; margin: 0; padding: 0; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 10px 6px; }
.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-weight: 500;
}
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; }

.sidebar-footer { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid #1e293b; font-size: .85rem; }
.sidebar-footer .who { color: #fff; font-weight: 600; display: block; }
.sidebar-footer .who:hover { text-decoration: none; color: #fff; opacity: .85; }
.sidebar-footer .email { color: #94a3b8; font-size: .8rem; word-break: break-all; }

.main { padding: 28px 32px; max-width: 1100px; width: 100%; min-width: 0; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header p { color: var(--muted); margin: 4px 0 0; }

/* ---------- Components ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.card-subtitle { color: var(--muted); font-size: .9rem; margin-bottom: 18px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }

.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: .82rem; margin-top: 6px; }
.field .error { color: var(--danger); font-size: .85rem; margin-top: 6px; }

.input {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: #fff;
    border: 1px solid #cfd6e0;
    border-radius: 8px;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.is-invalid { border-color: var(--danger); }
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px;
    font: inherit; font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: #cfd6e0; }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--primary); padding: 0; font-weight: 500; cursor: pointer; }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    margin-bottom: 18px;
    font-size: .93rem;
}
.alert-success { background: var(--success-soft); color: #14532d; border-color: #bbf7d0; }
.alert-error { background: var(--danger-soft); color: #7f1d1d; border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: #78350f; border-color: #fde68a; }
.alert-info { background: var(--primary-soft); color: #1e3a8a; border-color: #c7d7fe; }

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .78rem; font-weight: 600;
}
.badge-success { background: var(--success-soft); color: #166534; }
.badge-muted { background: #eef1f6; color: var(--muted); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.stat-label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.05rem; font-weight: 600; margin-top: 2px; word-break: break-all; }

dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; font-size: .92rem; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 20px; }
.optional { color: var(--muted); font-weight: 400; }
.text-danger { color: var(--danger); }
.badge-danger { background: var(--danger-soft); color: #991b1b; }
.btn-sm { padding: 6px 12px; font-size: .85rem; }
select.input { appearance: auto; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table .row-note td { padding-top: 0; font-size: .85rem; color: var(--muted); }

.profile { display: flex; align-items: center; gap: 20px; }
.avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); flex: none; }
.avatar-placeholder { display: flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 2rem; }
.profile-name { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; }
.stat-big { font-size: 2.2rem; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }

.text-primary { color: var(--primary); }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.table .cell-service { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-orders tbody tr.row-eligible { background: #f0fdf4; }
.table-orders tbody tr:hover { background: #f8fafc; }
.table-orders tbody tr.row-eligible:hover { background: #e7fbee; }
.empty { color: var(--muted); text-align: center; padding: 20px 0 6px; margin: 0; }

/* order status pills */
.status { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; text-transform: capitalize; white-space: nowrap; }
.st-completed { background: var(--success-soft); color: #166534; }
.st-partial { background: var(--warning-soft); color: #92400e; }
.st-progress { background: var(--primary-soft); color: #1e40af; }
.st-pending { background: #eef1f6; color: var(--muted); }
.st-canceled { background: #f1f5f9; color: #475569; text-decoration: line-through; }
.st-error { background: var(--danger-soft); color: #991b1b; }

/* ---------- Progress panel ---------- */

.progress-card { border-color: #c7d7fe; background: linear-gradient(180deg, #fbfcff, #fff); }
.progress-head { display: flex; align-items: center; gap: 22px; }
.progress-ring {
    --p: 0;
    width: 92px; height: 92px; border-radius: 50%; flex: none;
    background: conic-gradient(var(--primary) calc(var(--p) * 1%), #e5eaf3 0);
    display: grid; place-items: center;
    transition: background .3s;
}
.progress-ring::before { content: ""; position: absolute; width: 74px; height: 74px; border-radius: 50%; background: #fff; }
.progress-ring { position: relative; }
.progress-pct { position: relative; font-weight: 800; font-size: 1.5rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.progress-pct small { font-size: .8rem; font-weight: 600; color: var(--muted); margin-left: 1px; }
.progress-copy { flex: 1; min-width: 0; }
.progress-title { font-weight: 700; font-size: 1.05rem; }
.progress-status { color: var(--muted); font-size: .9rem; margin: 4px 0 10px; min-height: 1.3em; }
.progress-bar { height: 8px; border-radius: 999px; background: #e5eaf3; overflow: hidden; position: relative; }
.progress-bar-fill {
    height: 100%; width: 0; border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), #6ea0ff);
    transition: width .35s ease;
    position: relative; overflow: hidden;
}
.progress-bar-fill::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
    transform: translateX(-100%); animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.stages { list-style: none; margin: 20px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.stages li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: #f4f6fa; color: var(--muted); font-size: .9rem; min-width: 0; }
.stages li .stage-label { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stages li .stage-meta { font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.stage-icon { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #cbd5e1; flex: none; position: relative; }
.stages li.active { background: var(--primary-soft); color: #1e3a8a; }
.stages li.active .stage-icon { border-color: var(--primary); border-top-color: transparent; animation: spin .8s linear infinite; }
.stages li.done { background: var(--success-soft); color: #14532d; }
.stages li.done .stage-icon { border-color: var(--success); background: var(--success); }
.stages li.done .stage-icon::after { content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.stages li.error { background: var(--danger-soft); color: #7f1d1d; }
.stages li.error .stage-icon { border-color: var(--danger); background: var(--danger); }
.stages li.error .stage-icon::after { content: "!"; position: absolute; inset: 0; color: #fff; font-size: 11px; font-weight: 800; text-align: center; line-height: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Report ---------- */

.report-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.report-side { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }

.callout { display: flex; align-items: center; gap: 18px; margin-top: 22px; padding: 18px 22px; border-radius: var(--radius); border: 1px solid; }
.callout-action { background: linear-gradient(135deg, #eef4ff, #f7faff); border-color: #c7d7fe; }
.callout-ok { background: linear-gradient(135deg, #f0fdf4, #f8fffa); border-color: #bbf7d0; }
.callout-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.callout-action .callout-icon { background: var(--primary); color: #fff; }
.callout-ok .callout-icon { background: var(--success); color: #fff; }
.callout-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.callout-action .callout-label { color: #1e40af; }
.callout-ok .callout-label { color: #166534; }
.callout-value { font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.callout-action .callout-value { color: var(--primary); }
.callout-ok .callout-value { color: var(--success); }
.callout-text { color: var(--text); font-size: .93rem; margin-top: 4px; }
.callout-text strong { font-weight: 600; }
.report-side .btn svg { flex: none; }
.report-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 22px; font-size: .85rem; }
.report-meta div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.report-meta span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.report-meta strong { font-weight: 600; word-break: break-word; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.tile-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.tile-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.tile-accent { border-color: #bbf7d0; background: linear-gradient(180deg, #f6fef9, #fff); }
.tile-accent .tile-value { color: #15803d; }

.report-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: .9rem; font-weight: 500; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track { width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .2s; flex: none; }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s; }
.toggle input:checked + .toggle-track { background: var(--success); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { box-shadow: 0 0 0 3px var(--primary-soft); }

.error-page { text-align: center; padding: 80px 16px; }
.error-page .code { font-size: 4rem; font-weight: 800; color: #cbd5e1; }
pre.trace { text-align: left; background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 8px; overflow: auto; font-size: .8rem; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .topbar { display: flex; }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
        width: min(280px, 85vw);
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .35);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; }
    .sidebar-close { display: inline-flex; }

    .main { padding: 18px 16px 32px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn, .page-header .badge { align-self: flex-start; }
    .card { padding: 18px 16px; }
    .guest-card { padding: 24px 20px; }

    .progress-head { flex-direction: column; align-items: flex-start; gap: 14px; }
    .progress-ring { width: 76px; height: 76px; }
    .progress-ring::before { width: 60px; height: 60px; }
    .progress-pct { font-size: 1.2rem; }
    .stages { grid-template-columns: 1fr; }

    .report-head { flex-direction: column; align-items: stretch; }
    .report-side { width: 100%; }
    .report-side .btn { width: 100%; }
    .callout { flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }
    .callout-value { font-size: 2rem; }
    .report-toolbar { flex-direction: column; align-items: flex-start; }

    .table th, .table td { padding: 9px 10px; }
    .table .cell-service { max-width: 200px; }
    .actions form { display: inline; }
}

@media (max-width: 480px) {
    html, body { font-size: 14px; }
    h1 { font-size: 1.3rem; }
    .stat-big { font-size: 1.8rem; }
    .tile-value { font-size: 1.6rem; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
    .tile { padding: 14px; }
    .profile { gap: 14px; }
    .avatar { width: 64px; height: 64px; }
    .actions { gap: 8px; }
    .actions .btn { flex: 1 1 auto; justify-content: center; }
    .actions .hint { flex-basis: 100%; }
}
