/* ============================================================
   Digital Business Ledger — Design System
   Aesthetic: Dark refined ledger — deep slate, gold accents,
   serif display headers, clean mono data
   ============================================================ */

/* --- TOKENS ------------------------------------------------ */
:root {
    --bg-base:       #0d1117;
    --bg-surface:    #161b22;
    --bg-elevated:   #1c2330;
    --bg-hover:      #21293a;

    --border:        #2a3447;
    --border-light:  #1e2839;

    --gold:          #c9a84c;
    --gold-light:    #e2c47a;
    --gold-dim:      rgba(201,168,76,0.15);

    --text-primary:  #e8edf3;
    --text-secondary:#8b97a8;
    --text-muted:    #4e5d6e;
    --text-inverse:  #0d1117;

    --green:         #2ea84e;
    --green-dim:     rgba(46,168,78,0.15);
    --red:           #e05252;
    --red-dim:       rgba(224,82,82,0.15);
    --blue:          #4a9eed;
    --blue-dim:      rgba(74,158,237,0.15);

    --sidebar-w:     240px;
    --topbar-h:      60px;
    --radius:        8px;
    --radius-lg:     14px;

    --font-display:  'Playfair Display', Georgia, serif;
    --font-body:     'DM Sans', system-ui, sans-serif;
    --font-mono:     'DM Mono', 'Courier New', monospace;

    --shadow-sm:     0 1px 4px rgba(0,0,0,0.4);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.5);
    --shadow-gold:   0 0 24px rgba(201,168,76,0.12);
}

/* --- RESET ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: var(--font-body);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }

/* --- APP SHELL -------------------------------------------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR ---------------------------------------------- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px 20px;
    border-bottom: 1px solid var(--border);
}
.brand-mark {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gold);
    background: var(--gold-dim);
    border: 1px solid var(--gold);
    padding: 4px 8px;
    border-radius: 4px;
    letter-spacing: 0.05em;
}
.brand-full {
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.4;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.nav-section {
    flex: 1;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.nav-item.active {
    background: var(--gold-dim);
    color: var(--gold-light);
    border: 1px solid rgba(201,168,76,0.25);
}
.nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.nav-label { flex: 1; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.sidebar-role-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
    background: var(--gold-dim);
    border: 1px solid rgba(201,168,76,0.3);
    padding: 2px 8px;
    border-radius: 20px;
}
.sidebar-context {
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
}

/* --- MAIN AREA -------------------------------------------- */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- TOPBAR ----------------------------------------------- */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.page-heading {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    padding: 4px;
}
.sidebar-toggle span {
    display: block;
    width: 20px; height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: 0.2s;
}

.business-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
}
.badge-label { color: var(--text-muted); }
.badge-name { color: var(--gold-light); font-weight: 500; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--gold-dim);
    border: 1px solid var(--gold);
    color: var(--gold-light);
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.logout-btn {
    color: var(--text-muted);
    font-size: 1.1rem;
    padding: 2px 4px;
    transition: color 0.15s;
}
.logout-btn:hover { color: var(--red); }

/* --- FLASH MESSAGES --------------------------------------- */
.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    font-size: 0.88rem;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    animation: flashIn 0.3s ease;
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.flash--success { background: var(--green-dim); color: #6ed48a; border-color: rgba(46,168,78,0.3); }
.flash--error   { background: var(--red-dim);   color: #f08080; border-color: rgba(224,82,82,0.3); }
.flash--info    { background: var(--blue-dim);   color: #80bbf0; border-color: rgba(74,158,237,0.3); }
.flash-close {
    background: none; border: none;
    color: inherit; opacity: 0.6;
    font-size: 0.9rem; padding: 0 4px;
}
.flash-close:hover { opacity: 1; }

/* --- CONTENT AREA ----------------------------------------- */
.content {
    flex: 1;
    padding: 28px 28px;
    max-width: 1400px;
    width: 100%;
}

/* --- CARDS ------------------------------------------------ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 18px 22px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}
.card-body { padding: 22px; }

/* --- STAT CARDS ------------------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gold);
    opacity: 0;
    transition: opacity 0.2s;
}
.stat-card:hover { border-color: var(--gold); box-shadow: var(--shadow-gold); }
.stat-card:hover::before { opacity: 1; }
.stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.stat-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}
.stat-value.gold  { color: var(--gold-light); }
.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-sub {
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- TABLES ----------------------------------------------- */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
thead th {
    padding: 11px 14px;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr {
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
td {
    padding: 12px 14px;
    color: var(--text-primary);
    vertical-align: middle;
}
td.mono { font-family: var(--font-mono); font-size: 0.82rem; }
td.muted { color: var(--text-muted); font-size: 0.82rem; }
.empty-row td {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-style: italic;
}

/* --- BADGES ----------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.badge-gold    { background: var(--gold-dim);  color: var(--gold-light); border: 1px solid rgba(201,168,76,0.3); }
.badge-green   { background: var(--green-dim); color: #6ed48a;           border: 1px solid rgba(46,168,78,0.3); }
.badge-red     { background: var(--red-dim);   color: #f08080;           border: 1px solid rgba(224,82,82,0.3); }
.badge-blue    { background: var(--blue-dim);  color: #80bbf0;           border: 1px solid rgba(74,158,237,0.3); }
.badge-neutral { background: var(--bg-hover);  color: var(--text-secondary); border: 1px solid var(--border); }

/* --- BUTTONS ---------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 18px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: all 0.15s;
    cursor: pointer;
    white-space: nowrap;
}
.btn-primary {
    background: var(--gold);
    color: var(--text-inverse);
    border-color: var(--gold);
}
.btn-primary:hover {
    background: var(--gold-light);
    border-color: var(--gold-light);
    color: var(--text-inverse);
}
.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-outline:hover {
    border-color: var(--gold);
    color: var(--gold-light);
}
.btn-danger {
    background: var(--red-dim);
    color: var(--red);
    border-color: rgba(224,82,82,0.3);
}
.btn-danger:hover {
    background: var(--red);
    color: #fff;
}
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-icon { padding: 7px 10px; }

/* --- FORMS ------------------------------------------------ */
.form-group { margin-bottom: 20px; }
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 7px;
}
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select, textarea {
    width: 100%;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: 0.88rem;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    appearance: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201,168,76,0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%234e5d6e'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}
textarea { resize: vertical; min-height: 90px; }
.form-hint {
    margin-top: 5px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.form-error {
    margin-top: 5px;
    font-size: 0.75rem;
    color: var(--red);
}
.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 8px;
}

/* --- AUTH PAGES ------------------------------------------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    padding: 24px;
}
.auth-box {
    width: 100%;
    max-width: 420px;
}
.auth-brand {
    text-align: center;
    margin-bottom: 32px;
}
.auth-brand-mark {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.05em;
}
.auth-brand-name {
    margin-top: 4px;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: var(--shadow-md);
}
.auth-title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 6px;
}
.auth-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 28px;
}
.auth-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* --- BUSINESS SWITCHER ------------------------------------ */
.business-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.business-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    text-decoration: none;
    color: inherit;
}
.business-card:hover {
    border-color: var(--gold);
    box-shadow: var(--shadow-gold);
    transform: translateY(-2px);
    color: inherit;
}
.business-card.active {
    border-color: var(--gold);
    background: var(--gold-dim);
}
.business-logo {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--gold);
    overflow: hidden;
}
.business-logo img { width: 100%; height: 100%; object-fit: cover; }
.business-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.business-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- PAGINATION ------------------------------------------- */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    padding: 16px 0 4px;
}
.page-btn {
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 0.82rem;
    transition: all 0.15s;
}
.page-btn:hover { border-color: var(--gold); color: var(--gold-light); }
.page-btn.active {
    background: var(--gold-dim);
    border-color: var(--gold);
    color: var(--gold-light);
}

/* --- SECTION HEADER --------------------------------------- */
.section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}
.section-title {
    font-family: var(--font-display);
    font-size: 1.15rem;
    color: var(--text-primary);
}
.section-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* --- DIVIDER ---------------------------------------------- */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* --- APP FOOTER ------------------------------------------- */
.app-footer {
    padding: 14px 28px;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* --- RESPONSIVE ------------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-md);
    }
    .sidebar-overlay.open { display: block; }
    .sidebar-toggle { display: flex; }
    .main-area { margin-left: 0; }
    .content { padding: 20px 16px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .topbar { padding: 0 16px; }
    .auth-card { padding: 28px 20px; }
}
@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}
