/* =========================================================================
   GST Brokerage Manager — application styles
   Modern admin dashboard · responsive · light + dark mode
   ========================================================================= */

:root {
    --sidebar-w: 256px;
    --topbar-h: 64px;
    --radius: 14px;
    --radius-sm: 10px;
    --teal: #0d9488;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
    --shadow: 0 4px 16px rgba(15, 23, 42, .08);
}

[data-bs-theme="light"] {
    --bs-body-bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --sidebar-bg: #0f172a;
    --sidebar-fg: #cbd5e1;
    --sidebar-active: #1d4ed8;
}
[data-bs-theme="dark"] {
    --bs-body-bg: #0b1120;
    --surface: #131c31;
    --surface-2: #0f172a;
    --border: #24304a;
    --sidebar-bg: #0a0f1d;
    --sidebar-fg: #94a3b8;
    --sidebar-active: #2563eb;
}

* { scrollbar-width: thin; }
body {
    background: var(--bs-body-bg);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.text-teal { color: var(--teal) !important; }
.letter-spacing-2 { letter-spacing: .4em; }

/* ---------------------------- App shell ------------------------------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main {
    flex: 1; min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
    transition: margin .2s ease;
}
.app-content { flex: 1; padding: 22px clamp(14px, 3vw, 32px); }
.app-footer { padding: 14px 32px; border-top: 1px solid var(--border); }

/* ---------------------------- Sidebar --------------------------------- */
.app-sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex; flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 20px; height: var(--topbar-h);
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff; font-size: 1.2rem;
}
.brand-mark.lg { width: 60px; height: 60px; font-size: 1.8rem; margin: 0 auto 12px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { color: #fff; font-size: 1.05rem; }
.brand-text small { color: #64748b; font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: #475569; padding: 16px 12px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 13px; margin-bottom: 3px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-fg); text-decoration: none;
    font-size: .92rem; font-weight: 500;
    transition: all .15s ease;
}
.nav-item i { font-size: 1.1rem; width: 22px; text-align: center; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, .4); }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .06); }

.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(2, 6, 23, .5);
    z-index: 1035; display: none;
}
body.sidebar-open .sidebar-backdrop { display: block; }

/* ---------------------------- Topbar ---------------------------------- */
.app-topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 14px;
    padding: 0 clamp(14px, 3vw, 28px);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-search { position: relative; flex: 1; max-width: 460px; }
.topbar-search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.topbar-search .form-control { padding-left: 40px; border-radius: 30px; background: var(--surface-2); }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.btn-icon {
    width: 40px; height: 40px; border-radius: 11px;
    display: inline-grid; place-items: center; padding: 0;
    border: 1px solid transparent; color: var(--bs-body-color); background: transparent;
}
.btn-icon:hover { background: var(--surface-2); }
table .btn-icon { width: 32px; height: 32px; border-radius: 8px; }

#themeToggle .theme-light-icon { display: none; }
[data-bs-theme="dark"] #themeToggle .theme-dark-icon { display: none; }
[data-bs-theme="dark"] #themeToggle .theme-light-icon { display: inline; }

.user-chip {
    display: flex; align-items: center; gap: 9px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 30px; padding: 5px 12px 5px 5px; cursor: pointer;
}
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #0ea5e9); color: #fff;
    display: grid; place-items: center; font-weight: 600; font-size: .85rem;
}

/* ---------------------------- Page head ------------------------------- */
.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-sub { color: var(--bs-secondary-color); margin: 2px 0 0; font-size: .9rem; }

/* ---------------------------- Panels / cards -------------------------- */
.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.panel-title { font-size: .98rem; font-weight: 650; margin: 0; }
.panel-body { padding: 18px; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.filter-bar .input-group { flex: 1; min-width: 220px; }

/* ---------------------------- Stat grid ------------------------------- */
.stat-grid {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.stat-card {
    display: flex; align-items: center; gap: 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm);
}
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; flex-shrink: 0; }
.stat-body { display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: .78rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; }
.bg-teal-subtle { background: rgba(13, 148, 136, .14); }
.text-teal { color: var(--teal) !important; }

/* ---------------------------- Tables ---------------------------------- */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td, .table th { padding: 12px 14px; vertical-align: middle; }
.sort-link { text-decoration: none; color: inherit; white-space: nowrap; }
.sort-link i { font-size: .7rem; opacity: .5; }

/* ---------------------------- Detail rows ----------------------------- */
.detail-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-row span { color: var(--bs-secondary-color); }
.detail-row.total { color: var(--bs-primary); }
.detail-row.balance { color: #d97706; }
.profit-banner {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 14px; padding: 14px 16px; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #16a34a, #15803d); color: #fff; font-weight: 600;
}
.profit-banner b { font-size: 1.2rem; }
.sig-hash { font-size: .78rem; color: var(--bs-secondary-color); }
.sig-hash code { color: var(--bs-primary); }

/* ---------------------------- Live calc panel ------------------------- */
.calc-panel { position: sticky; top: calc(var(--topbar-h) + 18px); }
.calc-list { list-style: none; margin: 0; padding: 0; }
.calc-list li { display: flex; justify-content: space-between; padding: 11px 2px; border-bottom: 1px dashed var(--border); font-size: .95rem; }
.calc-list li span { color: var(--bs-secondary-color); }
.calc-list li b { font-variant-numeric: tabular-nums; }
.calc-list li.total b { color: var(--bs-primary); font-size: 1.05rem; }
.calc-list li.balance b { color: #d97706; }
.calc-list li.profit { margin-top: 8px; background: rgba(22, 163, 74, .12); border-radius: var(--radius-sm); border: none; padding: 13px; }
.calc-list li.profit span, .calc-list li.profit b { color: #16a34a; font-size: 1.1rem; font-weight: 700; }
.calc-list li.profit-round { border-bottom: none; padding-top: 6px; }
.calc-list li.profit-round span { color: var(--bs-secondary-color); }
.calc-list li.profit-round small { opacity: .8; }
.calc-list li.profit-round b { color: #16a34a; font-variant-numeric: tabular-nums; }

.profit-roundoff {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin-top: 8px; padding: 8px 13px;
    border: 1px dashed var(--border); border-radius: var(--radius-sm);
    color: var(--bs-secondary-color); font-size: .9rem;
}
.profit-roundoff small { opacity: .8; }
.profit-roundoff b { color: #16a34a; font-variant-numeric: tabular-nums; }

/* ---------------------------- Activity list --------------------------- */
.activity-list { list-style: none; margin: 0; padding: 8px 18px 18px; }
.activity-list li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.activity-list li:last-child { border-bottom: none; }
.act-icon { color: var(--bs-primary); font-size: 1.3rem; line-height: 1; }
.act-text { font-size: .9rem; }

.status-legend { display: flex; justify-content: space-around; flex-wrap: wrap; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); font-size: .82rem; }
.status-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

.twofa-steps { padding-left: 18px; }
.twofa-steps li { margin-bottom: 8px; }
.qr-img { border: 6px solid #fff; border-radius: 12px; background: #fff; box-shadow: var(--shadow); }

.empty-state i { opacity: .5; }

/* ---------------------------- File manager ---------------------------- */
.fm-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.fm-breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: .92rem; min-width: 0; }
.fm-breadcrumb .crumb { color: var(--bs-secondary-color); text-decoration: none; padding: 4px 8px; border-radius: 8px; }
.fm-breadcrumb a.crumb:hover { background: var(--surface-2); color: var(--bs-primary); }
.fm-breadcrumb .crumb.active { color: var(--bs-body-color); font-weight: 600; }
.fm-breadcrumb .sep { color: var(--bs-secondary-color); opacity: .5; }
.fm-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fm-search { min-width: 180px; }

.fm-dropzone {
    display: none; margin: 12px 18px 0; padding: 14px; text-align: center;
    border: 2px dashed var(--border); border-radius: var(--radius-sm);
    color: var(--bs-secondary-color); font-size: .9rem;
}
.fm-dropzone.active { display: block; border-color: var(--bs-primary); color: var(--bs-primary); background: rgba(37, 99, 235, .06); }

.fm-table .fm-row { cursor: grab; }
.fm-table .fm-row.dragging { opacity: .45; }
.fm-table .fm-name { font-weight: 500; }
.fm-table .fm-drop.drop-hover {
    outline: 2px dashed var(--bs-primary); outline-offset: -2px;
    background: rgba(37, 99, 235, .10) !important;
}
.fm-table .fm-folder .fm-name:hover { color: var(--bs-primary); }
.fm-table .fm-up td { background: var(--surface-2); }
.fm-table .fm-up a { color: var(--bs-secondary-color); }

@media (max-width: 575.98px) {
    .fm-toolbar { flex-direction: column; align-items: stretch; }
    .fm-actions { justify-content: space-between; }
}

/* ---------------------------- Auth screens ---------------------------- */
.auth-body {
    min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(1200px 600px at 20% -10%, #1e3a8a 0%, transparent 55%),
                radial-gradient(900px 500px at 100% 100%, #0e7490 0%, transparent 50%), #0b1120;
    padding: 20px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 1.3rem; font-weight: 700; margin: 0; }
.auth-foot { text-align: center; margin-top: 16px; }

/* ---------------------------- Flash ----------------------------------- */
.flash-stack { position: fixed; top: 78px; right: 20px; z-index: 1080; width: min(360px, calc(100vw - 40px)); }
.flash-stack .alert { box-shadow: var(--shadow); }

/* ---------------------------- Advances widget ------------------------- */
.advances-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.advance-item {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px 16px;
    display: flex; flex-direction: column; gap: 3px;
}
.advance-label { color: var(--bs-secondary-color); font-size: .85rem; font-weight: 600; }
.advance-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.advance-item.advance-total { background: rgba(37, 99, 235, .10); border-color: rgba(37, 99, 235, .25); }
.advance-item.advance-total .advance-value { color: var(--bs-primary); }

/* ---------------------------- Floating calculator --------------------- */
.calc-widget {
    position: fixed; right: 24px; bottom: 24px; z-index: 1080;
    width: 322px; max-width: calc(100vw - 16px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 18px 50px rgba(2, 6, 23, .35);
    overflow: hidden;
}
.calc-widget.is-dragging { opacity: .97; }
.calc-widget-head {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    background: var(--surface-2); border-bottom: 1px solid var(--border);
    cursor: move; touch-action: none; user-select: none;
}
.calc-widget-title { font-weight: 700; font-size: .92rem; white-space: nowrap; }
.calc-widget-tabs { display: flex; gap: 4px; margin-left: auto; }
.calc-tab { border: none; background: transparent; color: var(--bs-secondary-color); font-size: .8rem; font-weight: 600; padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.calc-tab.is-active { background: var(--bs-primary); color: #fff; }
.calc-widget-close { border: none; background: transparent; color: var(--bs-secondary-color); width: 28px; height: 28px; border-radius: 8px; cursor: pointer; }
.calc-widget-close:hover { background: rgba(148, 163, 184, .18); }

.calc-pane { padding: 12px; }
.calc-display { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; text-align: right; margin-bottom: 10px; }
.calc-expr { min-height: 18px; color: var(--bs-secondary-color); font-size: .82rem; font-variant-numeric: tabular-nums; }
.calc-screen { font-size: 1.8rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; word-break: break-all; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-key { border: 1px solid var(--border); background: var(--surface); color: var(--bs-body-color); border-radius: 10px; padding: 12px 0; font-size: 1.05rem; font-weight: 600; cursor: pointer; transition: transform .04s ease, background .15s ease; }
.calc-key:hover { background: var(--surface-2); }
.calc-key:active { transform: scale(.96); }
.calc-fn { color: var(--bs-secondary-color); }
.calc-op { color: var(--bs-primary); }
.calc-eq { background: var(--bs-primary); color: #fff; border-color: var(--bs-primary); }
.calc-eq:hover { filter: brightness(1.06); }

.calc-foot { display: flex; gap: 8px; margin-top: 10px; }
.calc-mini { flex: 1; border: 1px solid var(--border); background: var(--surface-2); color: var(--bs-body-color); border-radius: 8px; padding: 7px 8px; font-size: .8rem; font-weight: 600; cursor: pointer; }
.calc-mini:hover { background: var(--surface); }
.calc-mini.is-copied { color: #16a34a; border-color: rgba(22, 163, 74, .4); }

.calc-history { list-style: none; margin: 10px 0 0; padding: 0; max-height: 132px; overflow: auto; }
.calc-history li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: .82rem; }
.calc-history li:hover { background: var(--surface-2); }
.calc-h-expr { color: var(--bs-secondary-color); }
.calc-h-res { font-weight: 700; font-variant-numeric: tabular-nums; }

.calc-gst { display: flex; flex-direction: column; gap: 10px; }
.calc-gst-label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; font-weight: 600; color: var(--bs-secondary-color); }
.calc-gst-out { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 12px; }
.calc-gst-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.calc-gst-row:last-child { border-bottom: none; }
.calc-gst-row b { font-variant-numeric: tabular-nums; }
.calc-gst-total b { color: var(--bs-primary); font-size: 1.05rem; }
.calc-gst-hint { font-size: .75rem; color: var(--bs-secondary-color); margin: 0; }
.calc-gst-check { font-size: .82rem; display: flex; gap: 6px; align-items: center; cursor: pointer; }

/* Field highlight when the calculator pushes a value into a form input */
@keyframes fieldFlash {
    0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, .45); border-color: var(--bs-primary); }
    100% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); }
}
.field-flash { animation: fieldFlash .9s ease-out; border-color: var(--bs-primary) !important; }

/* ---------------------------- Responsive ------------------------------ */
@media (max-width: 991.98px) {
    .app-main { margin-left: 0; }
    .app-sidebar { transform: translateX(-100%); }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
}
@media (max-width: 575.98px) {
    .page-title { font-size: 1.25rem; }
    .app-content { padding: 16px 12px; }
    .flash-stack { top: auto; bottom: 16px; right: 12px; left: 12px; width: auto; }
    .calc-panel { position: static; }
    .calc-widget { left: 8px !important; right: 8px !important; top: auto !important; bottom: 8px !important; width: auto; }
}
