:root {
    --bg: #F4F1EC;
    --surface: #FFFcf7;
    --ink: #1F1A16;
    --muted: #6B6259;
    --line: #E4DCD2;
    --brand: #2F6F4E;
    --danger: #9B1C1C;
    --ok: #166534;
    --font: "Cairo", system-ui, sans-serif;
    --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body.admin-body, body.auth-body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    min-height: 100dvh;
    line-height: 1.6;
}
img { max-width: 100%; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.admin-shell { display: grid; min-height: 100dvh; }
.admin-nav {
    background: #1F1A16; color: #F4EDE1;
    padding: 20px 16px; display: flex; flex-direction: column; gap: 12px;
}
.admin-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.admin-brand-mark {
    width: 40px; height: 40px; border-radius: 12px; background: var(--brand);
    display: grid; place-items: center; font-weight: 700; color: #fff;
}
.admin-brand small { display: block; opacity: .7; font-size: 12px; }
.admin-nav nav { display: flex; flex-direction: column; gap: 4px; }
.admin-nav a {
    color: inherit; text-decoration: none; padding: 10px 12px; border-radius: 10px;
    min-height: 44px; display: flex; align-items: center;
}
.admin-nav a.is-active, .admin-nav a:hover { background: rgba(255,255,255,.08); }
.admin-preview { margin-top: auto; border: 1px solid rgba(255,255,255,.2); text-align: center; }
.linkish {
    background: transparent; border: 0; color: #E8B4B4; min-height: 44px; text-align: right; width: 100%;
}
.admin-main { padding: 20px 16px 48px; }
.admin-top h1 { margin: 0 0 16px; font-size: 22px; }

.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; }
.alert-ok { background: #DCFCE7; color: var(--ok); }
.alert-err { background: #FEE2E2; color: var(--danger); }

.card-form, .table-wrap, .auth-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 20px;
}
.card-form label, .auth-card label { display: block; margin: 12px 0; font-weight: 600; }
.card-form input, .card-form textarea, .card-form select,
.auth-card input, .inline-form input {
    width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line);
    border-radius: 10px; background: #fff; min-height: 44px;
}
.card-form small, .hint { display: block; color: var(--muted); font-weight: 400; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; min-height: 20px; }
.btn, .auth-card button[type="submit"] {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px;
    background: var(--brand); color: #fff; font-weight: 700; text-decoration: none; margin-top: 8px;
}
.btn-ghost {
    background: transparent; border: 1px solid var(--line); border-radius: 10px;
    min-height: 40px; padding: 0 12px; color: inherit;
}
.toolbar { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.muted { color: var(--muted); }
.inline { display: inline; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { width: 140px; min-height: 40px; margin: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row.tight input { width: auto; flex: 1; min-width: 120px; }
.chip { border: 0; border-radius: 999px; padding: 6px 12px; min-height: 36px; font-weight: 600; }
.chip-ok { background: #DCFCE7; color: var(--ok); }
.chip-off { background: #FEE2E2; color: var(--danger); }
.link-danger { background: none; border: 0; color: var(--danger); min-height: 40px; }
.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; margin-top: 8px; }
.thumb.wide { width: 160px; height: 72px; }
.hours-grid { display: grid; gap: 8px; }
.hours-row { display: grid; grid-template-columns: 90px auto 1fr 1fr; gap: 8px; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 16px; }
.auth-body { display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); }
.auth-kicker { letter-spacing: .2em; font-size: 12px; color: var(--muted); margin: 0; }
.home-hero { max-width: 560px; text-align: center; }
.home-hero h1 { font-family: "Playfair Display", Cairo, serif; font-size: 48px; margin: 8px 0; }
.home-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

@media (min-width: 900px) {
    .admin-shell { grid-template-columns: 240px 1fr; }
    .admin-nav { position: sticky; top: 0; height: 100dvh; }
    .admin-main { padding: 32px 40px; }
}

/* ==========================================================================
   Orders & Reports Styles
   ========================================================================== */

.orders-header, .reports-header {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.orders-tabs, .reports-periods {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
}

.tab-item, .period-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.tab-item:hover, .period-pill:hover {
    border-color: var(--brand);
}

.tab-item.is-active, .period-pill.is-active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

.tab-badge {
    background: rgba(0, 0, 0, 0.08);
    color: inherit;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 12px;
}
.tab-item.is-active .tab-badge {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.orders-filter-bar, .reports-custom-range {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    background: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--line);
}

.filter-input-wrap {
    flex: 1;
    min-width: 240px;
    position: relative;
    display: flex;
    align-items: center;
}
.filter-input-wrap input {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.filter-clear {
    position: absolute;
    left: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: 18px;
    line-height: 1;
}

.orders-filter-bar select, .reports-custom-range input[type="date"] {
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.auto-refresh-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    margin-right: auto;
}

.empty-orders-box {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 16px;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* Order Cards Grid */
.orders-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}
@media (min-width: 900px) {
    .orders-grid {
        grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    }
}

.order-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.order-card:hover {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
}

.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0ece6;
    padding-bottom: 10px;
}
.order-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}
.order-num-pill {
    background: #1F1A16;
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 8px;
}
.order-time {
    font-size: 12px;
    color: var(--muted);
}

.order-badges {
    display: flex;
    align-items: center;
    gap: 6px;
}
.badge-type {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 6px;
    background: #f1f3f5;
    font-weight: 600;
}
.badge-status {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 8px;
}
.status-pending { background: #FEF3C7; color: #B45309; }
.status-preparing { background: #DBEAFE; color: #1D4ED8; }
.status-delivery { background: #EDE9FE; color: #6D28D9; }
.status-completed { background: #DCFCE7; color: #15803D; }
.status-cancelled { background: #FEE2E2; color: #B91C1C; }

/* Customer Box */
.order-customer-box {
    background: #FAF7F2;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.customer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.customer-actions {
    display: flex;
    gap: 6px;
}
.chip-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
}
.chip-call { background: #e0f2fe; color: #0369a1; }
.chip-wa { background: #dcfce7; color: #15803d; }

.customer-detail {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: #444;
}
.detail-tag { font-size: 12px; }
.detail-address { font-size: 12px; color: var(--muted); }
.customer-notes { font-size: 12px; color: #b45309; background: #fffbeb; padding: 4px 8px; border-radius: 6px; }

/* Items Table inside Card */
.order-items-table table {
    width: 100%;
    font-size: 13px;
}
.order-items-table th, .order-items-table td {
    padding: 6px 4px;
    border-bottom: 1px solid #f0f0f0;
}
.item-name-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}
.item-size-badge {
    background: #e9ecef;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
}
.item-addons-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}
.addon-pill {
    font-size: 11px;
    color: var(--muted);
    background: #f8f9fa;
    padding: 1px 6px;
    border-radius: 4px;
}

/* Totals Box */
.order-totals-box {
    border-top: 1px dashed var(--line);
    padding-top: 8px;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.totals-row {
    display: flex;
    justify-content: space-between;
}
.totals-row.grand-total {
    font-size: 15px;
    color: var(--brand);
    border-top: 1px solid #eee;
    padding-top: 4px;
    margin-top: 2px;
}

/* Card Actions */
.order-card-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
    flex-wrap: wrap;
}
.status-action-form {
    display: flex;
    gap: 6px;
    align-items: center;
}
.btn-action {
    border: 0;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s ease;
}
.btn-action:hover { opacity: 0.9; }
.btn-preparing { background: #2563EB; color: #fff; }
.btn-delivery { background: #7C3AED; color: #fff; }
.btn-complete { background: #166534; color: #fff; }
.btn-cancel { background: transparent; color: var(--danger); border: 1px solid #fecaca; }

.status-done-text { font-size: 13px; color: var(--ok); font-weight: 700; }
.status-cancelled-text { font-size: 13px; color: var(--danger); font-weight: 700; }

.btn-receipt {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    background: #fff;
    transition: background 0.15s ease;
}
.btn-receipt:hover { background: #f8f9fa; }

/* ==========================================================================
   KPI Cards & Reports
   ========================================================================== */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
}
.kpi-title { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 800; color: var(--brand); }
.kpi-sub { font-size: 11px; color: var(--muted); }

.report-section {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 24px;
}
.section-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}
.section-top h2 { margin: 0; font-size: 18px; }
.section-top p { margin: 4px 0 0; }

.badge-qty {
    background: #f1f3f5;
    padding: 3px 10px;
    border-radius: 8px;
    font-weight: 700;
}

.progress-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.progress-bar-fill {
    height: 8px;
    background: var(--brand);
    border-radius: 4px;
    min-width: 4px;
    flex-shrink: 0;
}
.progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    min-width: 35px;
}

.fulfillment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.fulfillment-card {
    background: #FAF7F2;
    border-radius: 12px;
    padding: 16px;
}
.fulfillment-card h3 { margin: 0 0 12px; font-size: 15px; }
.fulfillment-stats {
    display: flex;
    justify-content: space-between;
}
.fulfillment-stats div {
    display: flex;
    flex-direction: column;
}
.fulfillment-stats strong { font-size: 18px; color: var(--ink); }

@media print {
    .admin-nav, .orders-header, .reports-header, .no-print, .btn-ghost {
        display: none !important;
    }
    .admin-shell { display: block; }
    .admin-main { padding: 0; }
    .report-section, .kpi-card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
}

