:root {
    --sidebar-w: 256px;
    --sidebar-bg: #0f172a;
    --sidebar-fg: #cbd5e1;
    --sidebar-active: #2563eb;
    --body-bg: #f1f5f9;
    --card-radius: .75rem;
    --brand: #2563eb;
}

body { background: var(--body-bg); font-size: .925rem; color: #1e293b; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.btn-link { text-decoration: none; }
.btn:hover, .nav-link:hover, .nav-sub:hover, .dropdown-item:hover, .list-group-item:hover, .search-item:hover, .notif-item:hover, .stat-card:hover, .sidebar-brand:hover { text-decoration: none; }
.app-wrapper { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-fg);
    position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 1040; transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.07); }
.sidebar-brand:hover { color: #fff; }
.brand-icon { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #2563eb, #22c55e); display: inline-flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.brand-icon-lg { width: 56px; height: 56px; font-size: 1.5rem; border-radius: 14px; }
.brand-logo { max-width: 40px; max-height: 40px; border-radius: 8px; background: #fff; padding: 2px; }
.brand-text { font-weight: 700; line-height: 1.1; font-size: .95rem; }
.brand-text small { display: block; font-weight: 400; color: #94a3b8; font-size: .72rem; margin-top: 2px; }
.sidebar-nav { padding: .75rem .6rem 2rem; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: .7rem; color: var(--sidebar-fg); padding: .55rem .75rem; border-radius: .5rem; font-size: .88rem; margin-bottom: 2px;
}
.sidebar-nav .nav-link i:first-child { width: 18px; text-align: center; opacity: .85; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav .nav-highlight { color: #fde68a; }
.sidebar-nav .caret { margin-left: auto; font-size: .65rem; transition: transform .2s; }
.sidebar-nav .nav-toggle[aria-expanded="true"] .caret { transform: rotate(180deg); }
.sidebar-nav .nav-sub { display: block; color: #94a3b8; padding: .38rem .75rem .38rem 2.6rem; font-size: .84rem; text-decoration: none; border-radius: .4rem; }
.sidebar-nav .nav-sub:hover { color: #fff; background: rgba(255,255,255,.04); }
.sidebar-nav .nav-sub.active { color: #fff; font-weight: 600; }
.sidebar-backdrop { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 1030; background: #fff; border-bottom: 1px solid #e2e8f0;
    display: flex; align-items: center; gap: .75rem; padding: .55rem 1.25rem; min-height: 60px;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.content { padding: 1.4rem; flex: 1; }
.app-footer { padding: .8rem 1.4rem; color: #94a3b8; font-size: .78rem; }

.global-search { position: relative; flex: 1; max-width: 520px; }
.global-search > i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.global-search input { padding-left: 2.2rem; background: #f8fafc; border-radius: 2rem; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border-radius: .6rem; display: none; max-height: 70vh; overflow-y: auto; z-index: 1050; border: 1px solid #e2e8f0; }
.search-results.show { display: block; }
.search-item { display: flex; gap: .75rem; padding: .6rem .9rem; text-decoration: none; color: inherit; border-bottom: 1px solid #f1f5f9; }
.search-item:hover, .search-item.focus { background: #eff6ff; }
.search-item .si-icon { width: 30px; height: 30px; border-radius: 8px; background: #e0e7ff; color: #3730a3; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.search-item .si-type { font-size: .7rem; text-transform: uppercase; color: #64748b; letter-spacing: .03em; }

.notif-count { position: absolute; top: 2px; right: 0; font-size: .62rem; }
.notif-menu { width: 360px; max-width: 92vw; padding: 0; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: block; padding: .65rem 1rem; border-bottom: 1px solid #f1f5f9; text-decoration: none; color: inherit; font-size: .84rem; }
.notif-item.unread { background: #eff6ff; }
.notif-item:hover { background: #f8fafc; }

/* ---------- Components ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.2rem; }
.page-header h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-header h1 i { color: var(--brand); margin-right: .35rem; }
.page-header .subtitle { color: #64748b; font-size: .85rem; }
.card { border: 1px solid #e2e8f0; border-radius: var(--card-radius); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-header { background: #fff; border-bottom: 1px solid #eef2f7; font-weight: 600; padding: .85rem 1.1rem; border-radius: var(--card-radius) var(--card-radius) 0 0 !important; }

.stat-card { padding: 1rem 1.15rem; display: flex; flex-direction: row; gap: .9rem; align-items: center; height: 100%; text-decoration: none; color: inherit; transition: transform .12s, box-shadow .12s; }
a.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15,23,42,.08); color: inherit; }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.stat-card .stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #64748b; font-weight: 600; }
.stat-card > div:last-child { min-width: 0; }
.stat-card .stat-value { font-size: clamp(1.05rem, 1.25vw, 1.35rem); font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-card .stat-sub { font-size: .78rem; color: #64748b; }
.bg-soft-primary { background: #dbeafe; color: #1d4ed8; }
.bg-soft-success { background: #dcfce7; color: #15803d; }
.bg-soft-warning { background: #fef3c7; color: #b45309; }
.bg-soft-danger { background: #fee2e2; color: #b91c1c; }
.bg-soft-info { background: #e0f2fe; color: #0369a1; }
.bg-soft-secondary { background: #f1f5f9; color: #475569; }

.due-list .due-item { display: flex; align-items: center; gap: .8rem; padding: .7rem 1.1rem; border-bottom: 1px solid #f1f5f9; }
.due-list .due-item:last-child { border-bottom: 0; }
.due-when { width: 74px; flex-shrink: 0; font-size: .72rem; font-weight: 700; text-transform: uppercase; text-align: center; border-radius: .5rem; padding: .35rem .2rem; }
.due-item .due-main { flex: 1; min-width: 0; }
.due-item .due-main .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due-item .due-amount { font-weight: 700; white-space: nowrap; }

.light { display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; font-weight: 700; padding: .25rem .55rem; border-radius: 1rem; white-space: nowrap; letter-spacing: .02em; }
.light::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.light-success { background: #dcfce7; color: #15803d; }
.light-warning { background: #fef3c7; color: #a16207; }
.light-danger { background: #fee2e2; color: #b91c1c; }
.light-primary { background: #dbeafe; color: #1d4ed8; }
.light-info { background: #e0f2fe; color: #0369a1; }
.light-secondary { background: #f1f5f9; color: #475569; }

.filter-pills .btn { border-radius: 2rem; font-size: .82rem; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table > :not(caption) > * > * { padding: .6rem .7rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: #64748b; font-weight: 600; background: #f8fafc; white-space: nowrap; }
table.dataTable td.dt-type-numeric, table.dataTable th.dt-type-numeric { text-align: right; }
.dt-container .dt-search input { border-radius: 2rem; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { padding: .2rem .45rem; }

/* Invoice form */
.items-table input { min-width: 70px; }
.items-table td { vertical-align: middle; }
.items-table .desc-col { min-width: 220px; }
.totals-box { background: #f8fafc; border-radius: .6rem; padding: 1rem 1.2rem; }
.totals-box .row-t { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals-box .grand { font-size: 1.2rem; font-weight: 700; border-top: 2px solid #e2e8f0; margin-top: .4rem; padding-top: .5rem; }

/* Invoice view */
.invoice-sheet { background: #fff; }
.invoice-sheet .inv-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; }
.balance-big { font-size: 1.8rem; font-weight: 800; }

/* Calendar */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar .cal-head { text-align: center; font-size: .75rem; font-weight: 700; color: #64748b; text-transform: uppercase; padding: .3rem 0; }
.calendar .cal-day { background: #fff; border: 1px solid #e2e8f0; border-radius: .6rem; min-height: 104px; padding: .45rem .55rem; cursor: pointer; transition: box-shadow .12s, border-color .12s; display: flex; flex-direction: column; }
.calendar .cal-day:hover { border-color: var(--brand); box-shadow: 0 4px 12px rgba(37,99,235,.12); }
.calendar .cal-day.empty { background: transparent; border: 0; cursor: default; box-shadow: none; }
.calendar .cal-day.today { border: 2px solid var(--brand); }
.calendar .cal-num { font-weight: 700; font-size: .95rem; }
.calendar .cal-due { margin-top: auto; border-radius: .4rem; padding: .25rem .4rem; font-size: .72rem; line-height: 1.25; }
.calendar .cal-due.pending { background: #fef3c7; color: #92400e; }
.calendar .cal-due.overdue { background: #fee2e2; color: #991b1b; }
.calendar .cal-paid { font-size: .7rem; color: #15803d; margin-top: 2px; }
.cal-legend span { display: inline-flex; align-items: center; gap: .3rem; margin-right: 1rem; font-size: .8rem; }
.cal-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Guest */
.guest-body { background: radial-gradient(circle at 20% 20%, #1e3a8a, #0f172a 60%); min-height: 100vh; }
.guest-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.guest-card { width: 100%; max-width: 420px; border-radius: 1rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; border-left: 2px solid #e2e8f0; margin-left: .4rem; font-size: .85rem; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline li .when { color: #94a3b8; font-size: .75rem; }

.ts-wrapper.form-select { padding: 0; }
.ts-control { border-radius: .375rem; }
.swal2-popup { font-size: .9rem !important; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
    .main { margin-left: 0; }
    .content { padding: 1rem; }
    .calendar .cal-day { min-height: 70px; padding: .3rem; }
    .calendar .cal-due { font-size: .62rem; padding: .15rem .25rem; }
    .calendar .cal-due .amt, .calendar .cal-paid { display: none; }
}
@media (max-width: 575.98px) {
    .stat-card .stat-value { font-size: 1rem; white-space: normal; overflow: visible; }
    .stat-card { padding: .8rem; gap: .6rem; }
    .stat-card .stat-icon { width: 38px; height: 38px; font-size: 1rem; }
    .calendar { gap: 3px; }
    .calendar .cal-head { font-size: .62rem; }
    .topbar { padding: .5rem .6rem; }
}

@media print {
    .sidebar, .topbar, .app-footer, .no-print, .dt-length, .dt-search, .dt-paging { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
    body { background: #fff; }
}
