/* ============================================================
   CoreBooks - Global Stylesheet (modern design system)
   Colors are driven by CSS custom properties. The header may
   inject a <style> block after this file to override the theme
   from database settings.
   ============================================================ */

:root {
    /* --- Theme (overridable from DB settings) --- */
    --bg:            #eaeaea;
    --sidebar-bg:    #1e293b;
    --accent:        #4f46e5;
    --accent-hover:  #3730a3;
    --card-bg:       #ffffff;
    --text:          #1e293b;
    --text-muted:    #64748b;
    --border:        #e2e8f0;
    --danger:        #ef4444;
    --success:       #22c55e;
    --warning:       #f59e0b;
    --info:          #0ea5e9;

    /* --- Derived / structural --- */
    --sidebar-text:      #cbd5e1;
    --sidebar-muted:     #94a3b8;
    --sidebar-active-bg: rgba(255,255,255,.08);
    --surface:           var(--card-bg);
    --radius:            12px;
    --radius-sm:         6px;
    --shadow:            0 1px 3px rgba(0,0,0,.08);
    --shadow-md:         0 8px 30px rgba(0,0,0,.12);
    --sidebar-w:         220px;
    --topbar-h:          50px;

    /* --- Legacy aliases (kept so existing pages don't break) --- */
    --primary:      var(--accent);
    --primary-dark: var(--accent-hover);
    --brand:        var(--accent);
    --brand-dark:   var(--accent-hover);
}

* { box-sizing: border-box; }

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

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

/* ============================================================
   Layout
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 40;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    height: var(--topbar-h);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    font-size: .8rem;
    display: flex; align-items: center; justify-content: center;
    letter-spacing: .3px;
    flex-shrink: 0;
}
.brand-text { color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: .2px; }

/* Flat sidebar brand (Phase 6 rebuild) */
.brand-logo {
    width: 32px; height: 32px;
    background: var(--accent, #4f46e5);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 12px; font-weight: 700;
    flex-shrink: 0;
}
.brand-name { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .3px; }

.sidebar-nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 8px; }

/* Flat sidebar (Phase 6 rebuild) — hardcoded nav, section separators,
   no icons/emoji, no arrows, no collapse. Active item gets a left accent. */
.nav-sep {
    padding: 14px 14px 4px;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,.3);
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-sep::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,.08); }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 7px 14px 7px 20px;
    color: rgba(255,255,255,.68);
    font-size: 12.5px;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all .15s;
    position: relative;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.06); border-left-color: rgba(255,255,255,.2); text-decoration: none; }
.nav-link.active { color: #fff; background: rgba(255,255,255,.1); border-left-color: var(--accent, #4f46e5); font-weight: 600; }

.nav-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .4; margin-right: 8px; flex-shrink: 0; }
.nav-link.active .nav-dot { opacity: 1; background: var(--accent, #4f46e5); }

.nav-count {
    margin-left: auto;
    background: var(--accent, #4f46e5);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    min-width: 17px;
    height: 17px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.sidebar-footer {
    padding: 12px 16px;
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,.07);
    color: var(--sidebar-muted);
    font-size: .72rem;
}

/* ============================================================
   Main / Topbar
   ============================================================ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: var(--sidebar-w);
    transition: margin-left .25s ease;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-title { font-size: 1rem; margin: 0; font-weight: 600; color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.sidebar-toggle {
    background: transparent; border: none; font-size: 1.3rem; cursor: pointer;
    color: var(--text); display: none; padding: 4px 6px; line-height: 1;
}

/* Currency chip */
.currency-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    background: #f8fafc;
}
.currency-chip .cur-symbol { color: var(--accent); font-weight: 800; }

/* Notification bell */
.topbar-bell {
    position: relative;
    background: transparent; border: none; cursor: pointer;
    font-size: 1.1rem; color: var(--text-muted); line-height: 1;
    padding: 4px;
}
.topbar-bell:hover { color: var(--text); }
.topbar-bell .bell-dot {
    position: absolute; top: 2px; right: 2px;
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--danger); border: 1px solid #fff;
}

/* User chip */
.user-chip { display: flex; align-items: center; gap: 9px; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .8rem;
    flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; font-size: .8rem; }

/* ---------- Content ---------- */
.content { padding: 20px; flex: 1; background: var(--bg); }
.app-footer {
    padding: 12px 20px;
    color: var(--text-muted);
    font-size: .78rem;
    border-top: 1px solid var(--border);
    background: #fff;
}

.page-header { display:flex; align-items:center; justify-content:space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }

/* ---------- Breadcrumb ---------- */
.breadcrumb {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    list-style: none; margin: 0 0 16px; padding: 0;
    font-size: .8rem; color: var(--text-muted);
}
.breadcrumb li { display: flex; align-items: center; gap: 6px; }
.breadcrumb li + li::before { content: "/"; color: var(--border); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .current { color: var(--text); font-weight: 600; }

/* ---------- Action buttons in tables ---------- */
.action-buttons { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.actions-col { white-space: nowrap; }

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: .82rem;
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px;
}
.card-body { padding: 16px; }

/* ---------- Stat cards ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 46px; height: 46px; flex-shrink: 0;
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    background: rgba(79,70,229,.1);
}
.stat-icon.teal   { background: rgba(20,184,166,.14); }
.stat-icon.green  { background: rgba(34,197,94,.14); }
.stat-icon.amber  { background: rgba(245,158,11,.16); }
.stat-icon.blue   { background: rgba(79,70,229,.12); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: .78rem; }

/* ============================================================
   Tables  (styles BOTH .data-table and .table)
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.data-table, table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
}
table.data-table th, table.data-table td,
table.table th, table.table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
table.data-table thead th, table.table thead th {
    background: #f8fafc;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    font-size: .68rem;
    letter-spacing: .04em;
    border-bottom: 2px solid var(--border);
}
table.data-table tbody tr, table.table tbody tr { transition: background .12s; }
table.data-table tbody tr:hover, table.table tbody tr:hover { background: #f8fafc; }

/* Alternating row colors */
table.data-table tbody tr:nth-child(even) { background: #fafbfe; }
table.data-table tbody tr:nth-child(even):hover { background: #f1f5f9; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.empty-state { text-align: center; color: var(--text-muted); padding: 28px; }

/* Expandable detail row (audit log etc.) */
.detail-row > td { background: #f8fafc; padding: 0; }
.detail-inner { padding: 14px 18px; display: flex; gap: 24px; flex-wrap: wrap; }
.detail-block { flex: 1; min-width: 240px; }
.detail-block h5 { margin: 0 0 6px; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.detail-block pre {
    margin: 0; background: #0f172a; color: #e2e8f0; padding: 12px;
    border-radius: var(--radius-sm); font-size: .74rem; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}

/* Pagination */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.pagination a, .pagination span {
    padding: 5px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-size: .8rem; text-decoration: none; background: #fff;
}
.pagination a:hover { background: #f1f5f9; text-decoration: none; }
.pagination .active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination .disabled { opacity: .5; pointer-events: none; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 5px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    transition: transform .12s, background .15s, box-shadow .15s, filter .15s;
    background: #e5e7eb; color: var(--text);
    text-decoration: none;
}
.btn:hover { transform: translateY(-1px); text-decoration: none; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 3px 9px; font-size: 11px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 3px 10px rgba(79,70,229,.3); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.95); }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { filter: brightness(.95); }
.btn-info    { background: var(--info); color: #fff; }
.btn-info:hover { filter: brightness(.95); }
.btn-secondary { background: #64748b; color: #fff; }
.btn-secondary:hover { filter: brightness(.95); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); box-shadow: none; }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .02em;
    background: #e5e7eb; color: #374151;
}
.badge-success { background: rgba(34,197,94,.15);  color: #15803d; }
.badge-danger  { background: rgba(239,68,68,.15);  color: #b91c1c; }
.badge-warning { background: rgba(245,158,11,.18); color: #b45309; }
.badge-info    { background: rgba(14,165,233,.15); color: #0369a1; }
.badge-muted   { background: #e5e7eb; color: #4b5563; }
.badge-secondary { background: #64748b; color: #fff; }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
    position: relative;
    padding: 12px 40px 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid transparent;
    font-size: .84rem;
}
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #ecfeff; border-color: #a5f3fc; color: #155e75; }
.alert-close {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    cursor: pointer; font-size: 1.2rem; line-height: 1; opacity: .6;
}
.alert-close:hover { opacity: 1; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 14px; }
.form-label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 12px; color: var(--text-muted); }
.form-control, select.form-control, textarea.form-control {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }
.form-hint { font-size: .74rem; color: var(--text-muted); margin-top: 4px; }
.is-invalid { border-color: var(--danger) !important; }
.field-error { color: var(--danger); font-size: .74rem; margin-top: 4px; }

/* Input with an inline adornment (e.g. password show/hide) */
.input-wrap { position: relative; }
.input-wrap .form-control { padding-right: 42px; }
.input-toggle {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: transparent; border: none; cursor: pointer;
    color: var(--text-muted); font-size: .95rem; line-height: 1; padding: 4px;
}
.input-toggle:hover { color: var(--text); }

/* ============================================================
   Modal (CSS + JS driven)
   ============================================================ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    display: none;
    align-items: center; justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto;
    animation: modalIn .18s ease;
}
.modal.modal-lg { max-width: 720px; }
@keyframes modalIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 18px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* ============================================================
   Toolbar / search
   ============================================================ */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-input { max-width: 320px; }

/* ============================================================
   Login page (split showcase / card)
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    background: var(--bg);
}
.login-split { display: flex; width: 100%; min-height: 100vh; }
.login-showcase {
    flex: 0 0 60%;
    background: linear-gradient(135deg, var(--sidebar-bg) 0%, var(--accent-hover) 130%);
    color: #fff;
    display: flex; flex-direction: column; justify-content: center;
    padding: 56px 60px;
}
.login-showcase .showcase-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 40px; }
.login-showcase .showcase-brand .brand-mark { width: 48px; height: 48px; font-size: 1.15rem; border-radius: 12px; }
.login-showcase .showcase-brand h1 { font-size: 1.7rem; margin: 0; font-weight: 800; letter-spacing: .3px; }
.login-showcase h2 { font-size: 2.1rem; line-height: 1.2; margin: 0 0 14px; font-weight: 800; max-width: 520px; }
.login-showcase .showcase-tag { font-size: 1rem; color: rgba(255,255,255,.82); margin: 0 0 36px; max-width: 460px; }
.showcase-features { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.showcase-features li { display: flex; align-items: flex-start; gap: 12px; font-size: .95rem; color: rgba(255,255,255,.92); }
.showcase-features .feat-icon {
    width: 34px; height: 34px; flex-shrink: 0;
    border-radius: 9px; background: rgba(255,255,255,.14);
    display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.showcase-features strong { display: block; font-weight: 700; margin-bottom: 1px; }
.showcase-features small { color: rgba(255,255,255,.7); }

.login-panel {
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    padding: 32px 28px;
    background: var(--bg);
}
.login-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,.12);
    width: 100%; max-width: 380px;
    padding: 34px 30px;
}
.login-card .login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card .login-logo .brand-mark { width: 34px; height: 34px; font-size: .85rem; }
.login-card .login-logo span.brand-text { color: var(--text); font-size: 1.05rem; font-weight: 800; }
.login-card h2 { font-size: 1.35rem; margin: 0 0 4px; font-weight: 800; }
.login-card .login-sub { color: var(--text-muted); margin: 0 0 22px; font-size: .85rem; }
.login-input-icon { position: relative; }
.login-input-icon .lii { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: .95rem; }
.login-input-icon .form-control { padding-left: 34px; }
.login-input-icon.input-wrap .form-control { padding-right: 42px; }
.login-footer { text-align: center; margin-top: 20px; color: var(--text-muted); font-size: .76rem; }

/* ============================================================
   Theme preview swatches (settings page)
   ============================================================ */
.theme-swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.theme-swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .7rem; color: var(--text-muted); }
.theme-swatch .sw {
    width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.03);
}
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input[type="color"] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.color-field input[type="text"] { max-width: 130px; }

/* ============================================================
   Invoice / Document layout
   ============================================================ */
.totals-panel {
    margin-top: 16px;
    margin-left: auto;
    max-width: 340px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 8px 14px;
}
.totals-panel > div {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
}
.totals-panel > div:last-child { border-bottom: none; }
.totals-panel .grand {
    font-size: 1.1rem;
    font-weight: 700;
    border-top: 2px solid #cbd5e1;
    margin-top: 4px;
}
.document .doc-head,
.document .doc-meta {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}
.document .doc-head h3 { margin: 0 0 4px; }
.document .doc-meta { border-top: 1px solid #edf2f7; padding-top: 14px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
    .main { margin-left: 0; }
    .sidebar-toggle { display: inline-block; }
    .login-showcase { display: none; }
    .login-panel { flex: 1 0 100%; }
    .user-meta { display: none; }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
    .no-print { display: none !important; }
    .sidebar, .topbar, .app-footer, .btn, .toolbar, .sidebar-toggle { display: none !important; }
    .main { margin-left: 0 !important; }
    .main, .content { margin: 0; padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ccc; }
    table.data-table thead th, table.table thead th { background: #eee !important; -webkit-print-color-adjust: exact; }
    @page { margin: 1.5cm; }
}
