/* =========================================================
   Mess Management – Admin theme
   ========================================================= */
:root {
    --sidebar-w: 260px;
    --sidebar-mini-w: 78px;
    --topbar-h: 66px;
    --primary: #4f46e5;
    --primary-soft: #eef2ff;
    --body-bg: #f4f5fa;
    --border: #e7e9f0;
    --muted: #6b7280;
    --sidebar-bg: #111827;
    --sidebar-fg: #aab3c5;
}

html { font-size: 15px; }

body {
    background: var(--body-bg);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color: #1f2937;
}

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

.btn-primary { --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca; --bs-btn-active-bg: #3730a3; }
.btn-outline-primary { --bs-btn-color: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: var(--primary); --bs-btn-hover-border-color: var(--primary); }
.text-primary { color: var(--primary) !important; }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }

/* ---------- Sidebar ---------- */
.app-sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #111827 0%, #1e293b 100%);
    color: var(--sidebar-fg);
    z-index: 1040;
    display: flex; flex-direction: column;
    transition: width .25s ease, transform .25s ease;
    overflow-x: hidden; overflow-y: auto;
}

.sidebar-brand {
    height: var(--topbar-h); flex-shrink: 0;
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1.2rem;
    color: #fff; text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    white-space: nowrap;
}
.sidebar-brand:hover { color: #fff; }

.brand-icon {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    display: grid; place-items: center;
    font-size: 1.2rem;
    box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
}

.brand-text { font-weight: 700; font-size: 1.05rem; line-height: 1.15; }
.brand-text small { display: block; font-weight: 400; font-size: .72rem; color: #94a3b8; }

.sidebar-nav { padding: .5rem 0 1rem; flex: 1; }

.sidebar-nav .nav-section {
    text-transform: uppercase; letter-spacing: .08em;
    font-size: .68rem; font-weight: 600;
    color: #64748b;
    padding: 1.1rem 1.5rem .4rem;
    white-space: nowrap;
}

.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: .8rem;
    margin: .12rem .8rem;
    padding: .62rem .9rem;
    border-radius: .6rem;
    color: var(--sidebar-fg);
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav .nav-link.active {
    background: linear-gradient(90deg, #4f46e5, #6366f1);
    color: #fff;
    box-shadow: 0 6px 14px rgba(79, 70, 229, .35);
}

.sidebar-help {
    margin: 0 1rem 1rem; padding: .9rem;
    border-radius: .75rem;
    background: rgba(255, 255, 255, .05);
    display: flex; gap: .7rem;
    font-size: .8rem;
}
.sidebar-help i { color: #facc15; font-size: 1.1rem; }
.sidebar-help strong { display: block; color: #fff; }

.sidebar-backdrop { display: none; }

/* Mini sidebar (desktop collapsed) */
@media (min-width: 992px) {
    body.sidebar-collapsed .app-sidebar { width: var(--sidebar-mini-w); }
    body.sidebar-collapsed .app-main { margin-left: var(--sidebar-mini-w); }
    body.sidebar-collapsed .brand-text,
    body.sidebar-collapsed .sidebar-nav .nav-link span,
    body.sidebar-collapsed .sidebar-help { display: none; }
    body.sidebar-collapsed .sidebar-nav .nav-section { font-size: 0; padding: .6rem 0; border-top: 1px solid rgba(255, 255, 255, .06); margin: .4rem 1rem 0; }
    body.sidebar-collapsed .sidebar-nav .nav-link { justify-content: center; padding: .7rem 0; }
    body.sidebar-collapsed .sidebar-brand { padding: 0; justify-content: center; }
}

/* Off-canvas sidebar (mobile) */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    body.sidebar-open .app-sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1035; }
    .app-main { margin-left: 0 !important; }
}

/* ---------- Main / Topbar ---------- */
.app-main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex; flex-direction: column;
    transition: margin .25s ease;
}

.app-topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--topbar-h);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.5rem;
}

.topbar-title h1 { font-size: 1.15rem; font-weight: 700; margin: 0; }
.topbar-breadcrumb { font-size: .75rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.topbar-breadcrumb a { color: var(--muted); text-decoration: none; }
.topbar-breadcrumb i { font-size: .6rem; }
.topbar-date { align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); background: #f3f4f6; padding: .35rem .75rem; border-radius: 2rem; }

/* Real-time live indicator */
.live-badge {
    align-items: center; gap: .4rem;
    font-size: .78rem; font-weight: 600;
    padding: .3rem .7rem; border-radius: 2rem;
    border: 1px solid var(--border);
    background: #f9fafb; color: var(--muted);
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.live-badge.live-connected { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.live-badge.live-connected .live-dot { background: #10b981; animation: livePulse 2s infinite; }
.live-badge.live-reconnecting { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.live-badge.live-reconnecting .live-dot { background: #f59e0b; }
@keyframes livePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, .55); }
    60% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
}

.save-pill { font-size: .75rem; font-weight: 600; padding: .2rem .6rem; border-radius: 1rem; }

.btn-icon {
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: .6rem; border: 1px solid var(--border);
    background: #fff; color: #374151; font-size: 1.15rem;
}
.btn-icon:hover { background: var(--primary-soft); color: var(--primary); }

.user-btn { display: flex; align-items: center; gap: .6rem; border: 0; padding: .25rem .4rem; }

.avatar {
    width: 36px; height: 36px; flex-shrink: 0;
    border-radius: 50%;
    display: inline-grid; place-items: center;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: #fff; font-weight: 600; font-size: .85rem;
}
.avatar-sm { width: 32px; height: 32px; font-size: .75rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.4rem; }

.app-content { flex: 1; padding: 1.5rem; }

.app-footer {
    background: #fff;
    border-top: 1px solid var(--border);
    padding: .9rem 1.5rem;
    font-size: .82rem; color: var(--muted);
    display: flex; justify-content: space-between; gap: 1rem;
}

/* ---------- Cards & components ---------- */
.card {
    border: 1px solid var(--border);
    border-radius: .85rem;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: .9rem 1.25rem;
    font-weight: 600;
}
.card-header:first-child { border-radius: .85rem .85rem 0 0; }
.card-footer { background: #fff; border-top: 1px solid var(--border); }
.card-title-sm { font-size: .95rem; font-weight: 600; margin: 0; }

.page-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: .75rem;
    margin-bottom: 1.25rem;
}
.page-header p { color: var(--muted); margin: 0; }

.stat-card { position: relative; overflow: hidden; }
.stat-card .card-body { display: flex; align-items: center; gap: 1rem; }
.stat-card .stat-label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.stat-card .stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-sub { font-size: .75rem; color: var(--muted); }

.stat-icon {
    width: 50px; height: 50px; flex-shrink: 0;
    border-radius: 14px;
    display: grid; place-items: center;
    font-size: 1.4rem;
}
.bg-soft-primary { background: #eef2ff; color: #4f46e5; }
.bg-soft-success { background: #ecfdf5; color: #059669; }
.bg-soft-warning { background: #fffbeb; color: #d97706; }
.bg-soft-danger  { background: #fef2f2; color: #dc2626; }
.bg-soft-info    { background: #ecfeff; color: #0891b2; }
.bg-soft-purple  { background: #f5f3ff; color: #7c3aed; }
.bg-soft-pink    { background: #fdf2f8; color: #db2777; }
.bg-soft-secondary { background: #f3f4f6; color: #4b5563; }

.badge { font-weight: 600; }
.badge-soft-primary { background: #eef2ff; color: #4338ca; }
.badge-soft-success { background: #ecfdf5; color: #047857; }
.badge-soft-warning { background: #fffbeb; color: #b45309; }
.badge-soft-danger  { background: #fef2f2; color: #b91c1c; }
.badge-soft-info    { background: #ecfeff; color: #0e7490; }
.badge-soft-purple  { background: #f5f3ff; color: #6d28d9; }
.badge-soft-secondary { background: #f3f4f6; color: #4b5563; }

.table { --bs-table-hover-bg: #f9fafb; margin-bottom: 0; }
.table > thead th {
    font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted);
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    padding-top: .7rem; padding-bottom: .7rem;
}
.table > :not(caption) > * > * { padding-left: 1rem; padding-right: 1rem; }
.table tfoot td, .table tfoot th { background: #f9fafb; font-weight: 700; }

.cat-icon {
    width: 34px; height: 34px; flex-shrink: 0;
    border-radius: 10px;
    display: inline-grid; place-items: center;
    background: var(--primary-soft); color: var(--primary);
}

.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filter-bar .form-control, .filter-bar .form-select { width: auto; }

/* ---------- Multi-select dropdown ---------- */
.multi-select { position: relative; }
.multi-select-btn {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    width: 100%; text-align: left;
    background: #fff; border: 1px solid #dee2e6; border-radius: .375rem;
    padding: .375rem .75rem; font-size: .92rem; color: #1f2937;
    transition: border-color .15s, box-shadow .15s;
}
.multi-select-btn:hover, .multi-select-btn:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); outline: 0; }
.multi-select-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.multi-select-menu { width: 100%; min-width: 270px; max-width: 340px; padding: .5rem; border: 1px solid var(--border); border-radius: .65rem; }
.multi-select-list { max-height: 230px; overflow-y: auto; margin-top: .35rem; }
.multi-select-item {
    display: flex; align-items: center; gap: .55rem;
    padding: .42rem .55rem; border-radius: .4rem;
    cursor: pointer; font-size: .88rem; margin: 0; user-select: none;
}
.multi-select-item:hover { background: #f3f4f6; }
.multi-select-item input[type="checkbox"] { flex-shrink: 0; cursor: pointer; }
.filter-chip {
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .78rem; font-weight: 500;
    padding: .25rem .6rem; border-radius: 2rem;
    background: var(--primary-soft); color: #3730a3;
    border: 1px solid #c7d2fe;
}
.filter-chip button {
    border: 0; background: transparent; padding: 0; line-height: 1;
    color: #4f46e5; font-size: .9rem; cursor: pointer;
}
.filter-chip button:hover { color: #1e1b4b; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; color: #c7cbd6; }

.validation-summary-valid { display: none; }
.field-validation-error { font-size: .8rem; }
.input-validation-error { border-color: #dc3545; }

.text-due { color: #dc2626; font-weight: 600; }
.text-refund { color: #059669; font-weight: 600; }

/* ---------- Meal vote ---------- */
.meal-input { width: 86px; text-align: center; margin: 0 auto; }
.meal-static {
    display: inline-block; min-width: 44px; text-align: center;
    padding: .2rem .55rem; border-radius: .375rem;
    background: #f3f4f6; color: #374151; font-weight: 600; font-size: .875rem;
}
.meal-row.meal-off .meal-static { color: #9ca3af; font-weight: 500; }
.meal-row.meal-off td { opacity: .55; }
.meal-total { font-weight: 700; font-size: 1rem; }

/* ---------- Meal sheet ---------- */
.sheet-table { font-size: .8rem; border-color: #cbd5e1; }
.sheet-table th, .sheet-table td {
    text-align: center;
    padding: .35rem .28rem !important;
    min-width: 50px;
    vertical-align: middle;
    border-color: #cbd5e1 !important;
}
.sheet-table .sticky-col {
    position: sticky; left: 0; background: #fff; text-align: left;
    min-width: 170px; z-index: 2;
    padding-left: .85rem !important; padding-right: .75rem !important;
    box-shadow: inset -1px 0 0 #cbd5e1;
}
.sheet-table thead .sticky-col { background: #f9fafb; z-index: 3; }
.sheet-table tfoot .sticky-col { background: #f9fafb; }
.sheet-table .sheet-total-col { min-width: 68px; background: #f8fafc; }
.sheet-table .is-friday { background: #fff7ed !important; }
.sheet-table .is-today { background: #eef2ff !important; font-weight: 700; }
.sheet-table td.has-meal { color: #111827; font-weight: 600; background: #fcfdff; }
.sheet-table td.no-meal { color: #9ca3af; }
.sheet-table th a { color: inherit; text-decoration: none; }
.sheet-cell-link { display: block; color: inherit; text-decoration: none; }
.sheet-cell-link:hover .sheet-total { color: var(--primary); text-decoration: underline; }
.sheet-cell-link:hover .sheet-bld { border-color: #94a3b8; }
.sheet-total { font-weight: 700; font-size: .84rem; line-height: 1rem; min-height: 1rem; margin-bottom: .22rem; }
.sheet-table td.no-meal .sheet-total { color: #9ca3af; font-weight: 500; }
.sheet-bld {
    display: flex; flex-direction: column;
    border: 1px solid #cbd5e1; border-radius: 4px;
    overflow: hidden; background: #fff;
}
.sheet-bld .bld-tag {
    display: grid; grid-template-columns: 16px 1fr; align-items: stretch;
    font-size: .64rem; line-height: 1.25; font-weight: 600;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.sheet-bld .bld-tag + .bld-tag { border-top: 1px solid #cbd5e1; }
.sheet-bld .bld-tag em {
    display: flex; align-items: center; justify-content: center;
    font-style: normal; font-weight: 700;
    border-right: 1px solid #cbd5e1;
    padding: 1px 0;
}
.sheet-bld .bld-tag span {
    display: flex; align-items: center; justify-content: center;
    min-width: 14px; padding: 1px 3px;
}
.bld-b { background: #fffbeb; color: #b45309; }
.sheet-bld .bld-b em { background: #fef3c7; }
.bld-l { background: #ecfdf5; color: #047857; }
.sheet-bld .bld-l em { background: #d1fae5; }
.bld-d { background: #eef2ff; color: #4338ca; }
.sheet-bld .bld-d em { background: #e0e7ff; }
.bld-zero { background: #fff; color: #94a3b8; font-weight: 500; }
.sheet-bld .bld-zero em { background: #f1f5f9; color: #64748b; }
.sheet-sum-bld { font-size: .68rem; font-weight: 500; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.sheet-table.sheet-compact .sheet-bld,
.sheet-table.sheet-compact .sheet-sum-bld { display: none; }
.sheet-table.sheet-compact th,
.sheet-table.sheet-compact td { min-width: 34px; }
.sheet-table.sheet-compact .sticky-col { min-width: 170px; }
.sheet-table.sheet-compact .sheet-total-col { min-width: 60px; }
.sheet-table.sheet-compact .sheet-total { margin-bottom: 0; }
.sheet-table.sheet-single-meal:not(.sheet-compact) .sheet-total { display: none; }
.sheet-table.sheet-single-meal th,
.sheet-table.sheet-single-meal td { min-width: 44px; }
.sheet-table.sheet-single-meal .sticky-col { min-width: 170px; }
.sheet-table.sheet-single-meal .sheet-total-col { min-width: 64px; }

/* ---------- Dining setup ---------- */
.setup-preset-card {
    border: 1.5px solid var(--border);
    border-radius: .75rem;
    padding: 1rem;
    background: #fff;
    transition: border-color .15s, box-shadow .15s, background .15s;
    cursor: pointer;
}
.setup-preset-card:hover:not(:disabled) {
    border-color: #a5b4fc;
    background: #fafaff;
}
.setup-preset-card.active {
    border-color: var(--primary);
    background: #eef2ff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.setup-preset-card:disabled { opacity: .75; cursor: default; }
.setup-meal-row { transition: opacity .15s, background .15s; background: #fff; }
.setup-meal-row.is-disabled { opacity: .6; background: #f8fafc; }
.sheet-cell-preview { min-width: 64px; padding: .4rem; background: #fff; border: 1px solid #cbd5e1; border-radius: .375rem; }

/* ---------- Invoice ---------- */
.invoice { max-width: 820px; margin: 0 auto 1.5rem; }
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 2px dashed var(--border); padding-bottom: 1rem; margin-bottom: 1rem; }
.invoice-total { background: #f9fafb; border-radius: .75rem; padding: 1rem 1.25rem; }
.invoice .table > :not(caption) > * > * { padding-left: .5rem; padding-right: .5rem; }

/* ---------- Print ---------- */
@media print {
    html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .app-sidebar, .app-topbar, .app-footer, .no-print, .alert, #liveToastContainer { display: none !important; }
    body.sidebar-collapsed .app-main,
    .app-main { margin: 0 !important; padding: 0 !important; width: 100% !important; min-height: 0 !important; }
    .app-content { padding: 0 !important; margin: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd; break-inside: avoid; }
    .table-responsive { overflow: visible !important; }
    .invoice { page-break-after: always; break-after: page; }

    /* Monthly Meal Matrix — fit entire month cleanly on A4 landscape */
    .matrix-print-card { border: 0 !important; margin: 0 !important; padding: 0 !important; break-inside: auto !important; }
    .matrix-print-header {
        font-size: 8.5pt; line-height: 1.2;
        padding: 0 0 2.5mm; margin-bottom: 2mm;
        border-bottom: 1px solid #cbd5e1;
    }
    .matrix-print-legend .badge { font-size: 6.5pt; padding: 1.5px 4px; border: 1px solid #cbd5e1; }
    .sheet-table {
        width: 100% !important; table-layout: fixed !important;
        border-collapse: collapse !important; font-size: 6.8pt !important;
        border-color: #94a3b8 !important;
    }
    .sheet-table .col-member { width: 26mm !important; }
    .sheet-table .col-total { width: 11mm !important; }
    .sheet-table th,
    .sheet-table td,
    .sheet-table.sheet-compact th,
    .sheet-table.sheet-compact td,
    .sheet-table.sheet-single-meal th,
    .sheet-table.sheet-single-meal td {
        min-width: 0 !important; padding: 1.5px 1px !important;
        border-color: #94a3b8 !important; vertical-align: middle !important;
    }
    .sheet-table .sticky-col,
    .sheet-table.sheet-compact .sticky-col,
    .sheet-table.sheet-single-meal .sticky-col {
        position: static !important; min-width: 0 !important; width: 26mm !important;
        padding: 2px 4px !important; box-shadow: none !important;
        text-align: left !important; font-size: 7pt !important; line-height: 1.15 !important;
        overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important;
    }
    .sheet-table .sticky-col .small { font-size: 5.5pt !important; line-height: 1.05 !important; }
    .sheet-table .sheet-total-col,
    .sheet-table.sheet-compact .sheet-total-col,
    .sheet-table.sheet-single-meal .sheet-total-col { min-width: 0 !important; width: 11mm !important; padding: 1.5px 2px !important; }
    .sheet-table thead th { font-size: 6.8pt !important; line-height: 1.05 !important; padding: 2px 1px !important; }
    .sheet-table thead th small { font-size: 5pt !important; }
    .sheet-table tr { break-inside: avoid; }
    .sheet-table a { text-decoration: none !important; color: inherit !important; }
    .sheet-total { font-size: 6.8pt !important; line-height: 1.05 !important; min-height: 1.05em !important; margin-bottom: 1.5px !important; }
    .sheet-bld { border-width: 0.75px !important; border-radius: 2px !important; }
    .sheet-bld .bld-tag { grid-template-columns: 9px 1fr !important; font-size: 5.5pt !important; line-height: 1.15 !important; }
    .sheet-bld .bld-tag em { padding: 0.5px 0 !important; }
    .sheet-bld .bld-tag span { min-width: 0 !important; padding: 0.5px 1px !important; }
}
