/* ============================================================
   SUBLIME MONEY ERP — Custom Theme
   Stack: Bootstrap 5.3 base + these overrides
   ============================================================ */

:root {
    --sm-sidebar-bg:          #1a2942;
    --sm-sidebar-hover:       #243656;
    --sm-sidebar-active:      #3d7eff;
    --sm-sidebar-text:        #a8b8d0;
    --sm-sidebar-text-active: #ffffff;
    --sm-sidebar-width:       245px;
    --sm-topbar-height:       56px;
    --sm-page-bg:             #f4f6f9;
    --sm-card-bg:             #ffffff;
    --sm-primary:             #3d7eff;
    --sm-primary-dark:        #2563d4;
    --sm-danger:              #e74c3c;
    --sm-success:             #27ae60;
    --sm-warning:             #f39c12;
    --sm-table-header:        #2c3e6b;
    --sm-border:              #e2e8f0;
}

/* ── Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 0.875rem;
    background: var(--sm-page-bg);
    color: #2d3748;
    margin: 0;
}

/* ── Layout Shell ─────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: var(--sm-sidebar-width);
    height: 100vh;
    background: var(--sm-sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    transition: width 0.25s ease;
    overflow: hidden;
}
.sidebar.collapsed { width: 60px; }

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    height: var(--sm-topbar-height);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-logo-icon {
    width: 32px; height: 32px;
    background: var(--sm-primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: #fff; font-size: 1rem; font-weight: 700;
}
.sidebar-logo-text {
    color: #fff; font-weight: 700; font-size: 0.95rem; letter-spacing: 0.3px;
}

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-section-label {
    font-size: 0.65rem; font-weight: 700; letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(168,184,208,0.5);
    padding: 12px 20px 4px;
    white-space: nowrap; overflow: hidden;
}
.sidebar.collapsed .nav-section-label { opacity: 0; }

.nav-item-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 20px;
    color: var(--sm-sidebar-text);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    border-left: 3px solid transparent;
}
.nav-item-link:hover { background: var(--sm-sidebar-hover); color: #fff; }
.nav-item-link.active {
    background: rgba(61,126,255,0.15);
    color: var(--sm-sidebar-text-active);
    border-left-color: var(--sm-sidebar-active);
}
.nav-item-link .nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item-label { font-size: 0.82rem; font-weight: 500; }
.sidebar.collapsed .nav-item-label { opacity: 0; width: 0; }

/* collapsible groups */
.nav-group-toggle {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 20px;
    color: var(--sm-sidebar-text);
    cursor: pointer; user-select: none;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s;
    list-style: none;
}
.nav-group-toggle:hover { background: var(--sm-sidebar-hover); color: #fff; }
.nav-group-toggle.open  { color: #fff; }

.nav-group-arrow {
    margin-left: auto; font-size: 0.7rem;
    transition: transform 0.2s; flex-shrink: 0;
}
.nav-group-toggle.open .nav-group-arrow { transform: rotate(90deg); }
.sidebar.collapsed .nav-group-arrow { display: none; }

.nav-sub { display: none; background: rgba(0,0,0,0.15); }
.nav-sub.open { display: block; }
.sidebar.collapsed .nav-sub { display: none !important; }

.nav-sub-link {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 20px 7px 44px;
    color: var(--sm-sidebar-text);
    text-decoration: none; font-size: 0.8rem;
    transition: background 0.15s, color 0.15s;
}
.nav-sub-link:hover { background: var(--sm-sidebar-hover); color: #fff; }
.nav-sub-link.active { color: var(--sm-sidebar-active); font-weight: 600; }

/* ── Main Content ─────────────────────────────────────── */
.main-area {
    margin-left: var(--sm-sidebar-width);
    flex: 1;
    min-width: 0;   /* let the column shrink to the screen; otherwise a wide table forces the whole page wider than a phone */
    display: flex; flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}
.sidebar.collapsed ~ .main-area { margin-left: 60px; }

/* ── Topbar ───────────────────────────────────────────── */
.topbar {
    height: var(--sm-topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--sm-border);
    display: flex; align-items: center;
    padding: 0 20px; gap: 12px;
    position: sticky; top: 0; z-index: 900;
}
.topbar-toggle {
    background: none; border: none; color: #6b7280;
    font-size: 1.1rem; cursor: pointer;
    padding: 4px 8px; border-radius: 6px;
    transition: background 0.15s;
}
.topbar-toggle:hover { background: #f3f4f6; }
.breadcrumb-area { flex: 1; }
.breadcrumb { margin: 0; padding: 0; font-size: 0.8rem; }
.breadcrumb-item a { color: var(--sm-primary); text-decoration: none; }
.breadcrumb-item.active { color: #6b7280; }
.breadcrumb-item + .breadcrumb-item::before { color: #9ca3af; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-branch {
    font-size: 0.78rem; color: #6b7280;
    background: #f3f4f6; padding: 4px 10px;
    border-radius: 20px; border: 1px solid var(--sm-border);
}
.topbar-branch strong { color: #374151; }
.topbar-user {
    display: flex; align-items: center; gap: 8px;
    text-decoration: none; color: #374151;
    padding: 4px 8px; border-radius: 8px;
    transition: background 0.15s;
}
.topbar-user:hover { background: #f3f4f6; }
.user-avatar {
    width: 32px; height: 32px;
    background: var(--sm-primary); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.75rem; font-weight: 700; flex-shrink: 0;
}
.user-name { font-size: 0.82rem; font-weight: 600; }

/* ── Page Content ─────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 1.25rem; font-weight: 700; color: #1a2942; margin: 0; }
.page-subtitle { font-size: 0.8rem; color: #6b7280; margin: 2px 0 0; }

/* ── Cards ────────────────────────────────────────────── */
.card {
    background: var(--sm-card-bg);
    border: 1px solid var(--sm-border);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--sm-border);
    background: transparent;
    font-weight: 600; font-size: 0.875rem; color: #1a2942;
    border-radius: 10px 10px 0 0 !important;
}
.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px; border-top: 1px solid var(--sm-border);
    background: #fafafa; border-radius: 0 0 10px 10px;
}

/* ── Tables ───────────────────────────────────────────── */
.table-responsive { border-radius: 8px; overflow-x: auto; overflow-y: hidden; }
.table { margin: 0; font-size: 0.825rem; border-collapse: separate; border-spacing: 0; }
.table thead th {
    background: var(--sm-table-header); color: #fff;
    font-weight: 600; font-size: 0.75rem;
    letter-spacing: 0.5px; text-transform: uppercase;
    border: none; padding: 11px 14px; white-space: nowrap;
}
.table tbody tr { transition: background 0.1s; }
.table tbody tr:hover { background: #f0f4ff; }
.table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--sm-border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table-striped tbody tr:nth-of-type(odd) { background: #f9fafb; }
.table-striped tbody tr:nth-of-type(odd):hover { background: #f0f4ff; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    font-size: 0.825rem; font-weight: 500;
    padding: 7px 16px; border-radius: 7px;
    transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary  { background: var(--sm-primary);  border-color: var(--sm-primary);  color: #fff; }
.btn-primary:hover { background: var(--sm-primary-dark); border-color: var(--sm-primary-dark); }
.btn-success  { background: var(--sm-success);  border-color: var(--sm-success);  color: #fff; }
.btn-danger   { background: var(--sm-danger);   border-color: var(--sm-danger);   color: #fff; }
.btn-warning  { background: var(--sm-warning);  border-color: var(--sm-warning);  color: #fff; }
.btn-outline-primary { border-color: var(--sm-primary); color: var(--sm-primary); }
.btn-outline-primary:hover { background: var(--sm-primary); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }

/* ── Action buttons in tables ─────────────────────────── */
.action-btns { display: flex; gap: 4px; align-items: center; }
.btn-action {
    padding: 4px 8px; border-radius: 5px; font-size: 0.75rem;
    border: 1px solid transparent; cursor: pointer;
    display: inline-flex; align-items: center;
    transition: all 0.15s; text-decoration: none;
}
.btn-action.view   { background: #e0e7ff; color: #4f46e5; border-color: #c7d2fe; }
.btn-action.edit   { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.btn-action.delete { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-action.print  { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.btn-action:hover  { filter: brightness(0.93); }

/* ── Forms ────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: 0.8rem; color: #374151; margin-bottom: 4px; }
.form-control, .form-select {
    font-size: 0.825rem;
    border-color: #d1d5db; border-radius: 7px;
    padding: 7px 11px; color: #1f2937;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--sm-primary);
    box-shadow: 0 0 0 3px rgba(61,126,255,0.12);
    outline: none;
}
.input-group-text {
    font-size: 0.825rem; background: #f9fafb;
    border-color: #d1d5db; color: #6b7280;
}

/* ── Search Bar ───────────────────────────────────────── */
.search-bar {
    background: #fff; border: 1px solid var(--sm-border);
    border-radius: 10px; padding: 14px 18px; margin-bottom: 18px;
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}

/* ── Modals ───────────────────────────────────────────── */
.modal-header {
    background: var(--sm-table-header); color: #fff;
    border-radius: 10px 10px 0 0; padding: 14px 20px;
}
.modal-header .btn-close { filter: invert(1); }
.modal-content { border-radius: 10px; border: none; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-footer { border-top: 1px solid var(--sm-border); padding: 12px 20px; }

/* ── Dashboard Stat Cards ─────────────────────────────── */
.stat-card {
    background: #fff; border: 1px solid var(--sm-border);
    border-radius: 10px; padding: 16px 18px;
    display: flex; flex-direction: column; gap: 0;
}
.stat-icon {
    width: 38px; height: 38px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem; flex-shrink: 0;
    margin-bottom: 10px;
}
.stat-value {
    font-size: 1.2rem; font-weight: 700; color: #1a2942; line-height: 1.25;
    word-break: break-word;
}
.stat-value .stat-currency {
    font-size: 0.72em; font-weight: 600; opacity: 0.6;
    margin-right: 1px; vertical-align: baseline;
}
.stat-label { font-size: 0.75rem; color: #6b7280; margin-top: 3px; }

/* ── Login Page ───────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a2942 0%, #2c3e6b 50%, #3d7eff 100%);
    display: flex; align-items: center; justify-content: center;
}
.login-card {
    background: #fff; border-radius: 16px; padding: 40px;
    width: 100%; max-width: 400px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
}
.login-logo {
    width: 56px; height: 56px; background: var(--sm-primary);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.5rem; font-weight: 800;
    margin: 0 auto 20px;
}
.login-title  { text-align: center; font-size: 1.35rem; font-weight: 700; color: #1a2942; margin-bottom: 4px; }
.login-subtitle { text-align: center; font-size: 0.8rem; color: #6b7280; margin-bottom: 28px; }

/* ── Pagination ───────────────────────────────────────── */
.pagination { font-size: 0.8rem; }
.page-link { color: var(--sm-primary); border-color: var(--sm-border); padding: 5px 11px; }
.page-item.active .page-link { background: var(--sm-primary); border-color: var(--sm-primary); }

/* ── Print ────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-area { margin-left: 0 !important; }
    .page-content { padding: 0; }
    .card { border: none; box-shadow: none; }
}

/* ── Voucher preview popup (iframed voucher form inside a modal) ── */
body.popup-mode .sidebar,
body.popup-mode .topbar { display: none !important; }
body.popup-mode .main-area { margin-left: 0 !important; }
body.popup-mode .page-content { padding: 12px; }
body.popup-mode fieldset { opacity: 0.85; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    /* '.sidebar.collapsed ~ .main-area' (desktop icon rail) is more specific than '.main-area', so it is named here too:
       on a phone the page always uses the full width, whatever the desktop collapsed state was. */
    .main-area,
    .sidebar.collapsed ~ .main-area { margin-left: 0; }
    /* the drawer is always the full menu, never the 60px icon rail */
    .sidebar.collapsed { width: var(--sm-sidebar-width); }
    .sidebar.collapsed .nav-section-label { opacity: 1; }
    .sidebar.collapsed .nav-item-label { opacity: 1; width: auto; }
    .sidebar.collapsed .nav-group-arrow { display: inline-block; }
}
/* ── Busy feedback: top progress bar, spinner, busy buttons (see site.js "Busy feedback") ─────────── */
.sm-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 2000;
    background: var(--sm-primary, #3d7eff); opacity: 0; pointer-events: none;
}
.sm-progress.on { opacity: 1; }
.sm-spin {
    display: inline-block; width: 1em; height: 1em; vertical-align: -.125em;
    border: .16em solid currentColor; border-right-color: transparent; border-radius: 50%;
    animation: sm-spin .7s linear infinite;
}
.sm-spin-btn { margin-right: 6px; }
.sm-spin-lg { width: 26px; height: 26px; border-width: 3px; color: var(--sm-primary, #3d7eff); }
@keyframes sm-spin { to { transform: rotate(360deg); } }
.sm-busy { cursor: progress !important; }
.sm-loading-box { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 24px 12px; color: #6b7280; font-size: .85rem; }
/* ── Centre "working" overlay (site.js smOverlay): voucher saves, long exports ───────────────────── */
.sm-overlay {
    position: fixed; inset: 0; z-index: 2100; display: none; align-items: center; justify-content: center;
    background: rgba(255,255,255,.78);
}
.sm-overlay.on { display: flex; }
.sm-overlay-box {
    background: #fff; border: 1px solid var(--sm-border, #e5e7eb); border-radius: 12px; padding: 22px 28px;
    min-width: 260px; max-width: 92vw; text-align: center; box-shadow: 0 8px 28px rgba(0,0,0,.12);
}
.sm-overlay-box .sm-spin { width: 36px; height: 36px; border-width: 4px; margin: 0 auto 12px; display: block; color: var(--sm-primary, #3d7eff); }
.sm-overlay-title { font-size: 1rem; font-weight: 600; color: #1f2937; }
.sm-overlay-sub { font-size: .82rem; color: #6b7280; margin-top: 4px; min-height: 2.4em; }
.sm-overlay-box.warn .sm-overlay-sub { color: #a16207; }
.sm-overlay-close { margin-top: 10px; display: none; }
