/* =====================================================================
   Online Business TMI - application styles (Bootstrap 5 companion)
   ===================================================================== */

:root {
    --tmi-primary: #4f46e5;
    --tmi-primary-hover: #4338ca;
    --tmi-primary-soft: #eef2ff;
    --tmi-sidebar-bg: #0f172a;
    --tmi-sidebar-text: #cbd5e1;
    --tmi-sidebar-muted: #64748b;
    --tmi-sidebar-hover: rgba(255, 255, 255, .06);
    --tmi-sidebar-active: rgba(99, 102, 241, .18);
    --tmi-body-bg: #f4f6fb;
    --tmi-surface: #ffffff;
    --tmi-border: #e5e7eb;
    --tmi-text: #0f172a;
    --tmi-muted: #64748b;
    --tmi-success: #059669;
    --tmi-danger: #dc2626;
    --tmi-warning: #d97706;
    --tmi-info: #0284c7;
    --tmi-radius: .75rem;
    --tmi-sidebar-width: 260px;
    --tmi-topbar-height: 64px;

    --bs-primary: var(--tmi-primary);
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: var(--tmi-primary);
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color: var(--tmi-primary-hover);
    --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-body-color: var(--tmi-text);
    --bs-border-color: var(--tmi-border);
}

body.app-body {
    background: var(--tmi-body-bg);
    font-size: .9rem;
}

/* ---------- Buttons ---------- */
.btn-primary {
    --bs-btn-bg: var(--tmi-primary);
    --bs-btn-border-color: var(--tmi-primary);
    --bs-btn-hover-bg: var(--tmi-primary-hover);
    --bs-btn-hover-border-color: var(--tmi-primary-hover);
    --bs-btn-active-bg: var(--tmi-primary-hover);
    --bs-btn-active-border-color: var(--tmi-primary-hover);
    --bs-btn-disabled-bg: var(--tmi-primary);
    --bs-btn-disabled-border-color: var(--tmi-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--tmi-primary);
    --bs-btn-border-color: var(--tmi-primary);
    --bs-btn-hover-bg: var(--tmi-primary);
    --bs-btn-hover-border-color: var(--tmi-primary);
    --bs-btn-active-bg: var(--tmi-primary);
}
.btn { border-radius: .5rem; font-weight: 500; }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem; }
.form-control, .form-select { border-radius: .5rem; }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }
.form-label { font-weight: 500; font-size: .85rem; }
.pagination { --bs-pagination-active-bg: var(--tmi-primary); --bs-pagination-active-border-color: var(--tmi-primary); --bs-pagination-color: var(--tmi-text); }

/* ---------- Shell ---------- */
.app-shell { min-height: 100vh; }

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--tmi-sidebar-width);
    background: var(--tmi-sidebar-bg);
    color: var(--tmi-sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .2s ease;
}
.sidebar-brand {
    height: var(--tmi-topbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    flex-shrink: 0;
}
.brand-link { display: flex; align-items: center; gap: .65rem; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-weight: 700;
    font-size: .75rem;
    letter-spacing: .04em;
    border-radius: .5rem;
    padding: .45rem .5rem;
    flex-shrink: 0;
}
.brand-text { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { color: var(--tmi-sidebar-text); margin-left: auto; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .75rem 1rem; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 3px; }
.nav-section-title {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--tmi-sidebar-muted);
    padding: 1rem .75rem .35rem;
}
.nav-item-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .75rem;
    border-radius: .5rem;
    color: var(--tmi-sidebar-text);
    text-decoration: none;
    font-size: .875rem;
    margin-bottom: 2px;
}
.nav-item-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .85; flex-shrink: 0; }
.nav-item-link > span:not(.badge) { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item-link:hover { background: var(--tmi-sidebar-hover); color: #fff; }
.nav-item-link.active { background: var(--tmi-sidebar-active); color: #fff; font-weight: 500; box-shadow: inset 3px 0 0 #818cf8; }
.nav-item-link.disabled { opacity: .45; cursor: default; }
.nav-item-link.disabled:hover { background: none; color: var(--tmi-sidebar-text); }
.nav-soon { margin-left: auto; background: rgba(255, 255, 255, .08); color: var(--tmi-sidebar-text); font-weight: 500; font-size: .62rem; }
.sidebar-footer { padding: .75rem 1.25rem; font-size: .72rem; color: var(--tmi-sidebar-muted); border-top: 1px solid rgba(255, 255, 255, .06); }

.app-main { margin-left: var(--tmi-sidebar-width); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
    height: var(--tmi-topbar-height);
    background: var(--tmi-surface);
    border-bottom: 1px solid var(--tmi-border);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.topbar-title { font-weight: 600; font-size: 1rem; }
.topbar-date { font-size: .8rem; color: var(--tmi-muted); }
.user-menu-btn { display: flex; align-items: center; gap: .6rem; border: 0; padding: .25rem .5rem; }
.user-menu-btn:hover, .user-menu-btn.show { background: var(--tmi-body-bg); }
.avatar {
    width: 2.1rem; height: 2.1rem; border-radius: 50%;
    background: var(--tmi-primary-soft); color: var(--tmi-primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .78rem;
}
.app-content { padding: 1.5rem; flex: 1; width: 100%; max-width: 1680px; }

.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-main { margin-left: 0; }
    body.sidebar-open .app-sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1035;
    }
    .app-topbar { padding: 0 1rem; }
    .app-content { padding: 1rem; }
}

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.4rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-subtitle { color: var(--tmi-muted); margin: .25rem 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.breadcrumb { font-size: .78rem; --bs-breadcrumb-divider-color: var(--tmi-muted); }
.breadcrumb a { color: var(--tmi-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--tmi-primary); }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--tmi-border); border-radius: var(--tmi-radius); box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
.card-header { background: transparent; border-bottom: 1px solid var(--tmi-border); padding: .9rem 1.25rem; font-weight: 600; }
.card-header .card-header-sub { font-weight: 400; color: var(--tmi-muted); font-size: .8rem; }
.card-body { padding: 1.25rem; }

.kpi-card { height: 100%; }
.kpi-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.kpi-icon {
    width: 2.4rem; height: 2.4rem; border-radius: .6rem;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.15rem; flex-shrink: 0;
}
.kpi-label { color: var(--tmi-muted); font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; line-height: 1.35; padding-top: .15rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.015em; line-height: 1.2; margin-top: .5rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (min-width: 1400px) { .kpi-value { font-size: 1.35rem; } }
.kpi-meta { font-size: .78rem; color: var(--tmi-muted); margin-top: .2rem; }
.tone-primary { background: #eef2ff; color: #4f46e5; }
.tone-success { background: #ecfdf5; color: #059669; }
.tone-info    { background: #f0f9ff; color: #0284c7; }
.tone-warning { background: #fffbeb; color: #d97706; }
.tone-danger  { background: #fef2f2; color: #dc2626; }
.tone-violet  { background: #f5f3ff; color: #7c3aed; }
.text-profit { color: var(--tmi-success) !important; }
.text-loss { color: var(--tmi-danger) !important; }

/* ---------- Tables ---------- */
.table-app { margin: 0; font-size: .86rem; }
.table-app > thead th {
    background: #f8fafc;
    color: var(--tmi-muted);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--tmi-border);
    white-space: nowrap;
    padding: .7rem 1rem;
}
.table-app > tbody td { padding: .7rem 1rem; vertical-align: middle; border-color: #f1f5f9; }
.table-app > tbody tr:hover > * { background: #fafbff; }
.table-app > tfoot td { padding: .7rem 1rem; font-weight: 600; background: #f8fafc; }
.table-app .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-app .actions { text-align: right; white-space: nowrap; }
.card > .table-responsive:last-child .table-app > tbody tr:last-child td { border-bottom: 0; }
.doc-link { font-weight: 600; text-decoration: none; }

.table-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; padding: .9rem 1.25rem; border-bottom: 1px solid var(--tmi-border); }
.table-toolbar .search-input { max-width: 320px; }
.table-footer { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; padding: .75rem 1.25rem; border-top: 1px solid var(--tmi-border); font-size: .8rem; color: var(--tmi-muted); }

/* ---------- Badges ---------- */
.badge { font-weight: 600; font-size: .7rem; padding: .35em .65em; border-radius: 999px; letter-spacing: .01em; }
.badge-soft-success   { background: #d1fae5; color: #047857; }
.badge-soft-danger    { background: #fee2e2; color: #b91c1c; }
.badge-soft-warning   { background: #fef3c7; color: #b45309; }
.badge-soft-info      { background: #e0f2fe; color: #0369a1; }
.badge-soft-primary   { background: #e0e7ff; color: #4338ca; }
.badge-soft-secondary { background: #f1f5f9; color: #475569; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 2.5rem 1rem; }
.empty-state-icon {
    width: 3.5rem; height: 3.5rem; border-radius: 50%;
    background: var(--tmi-primary-soft); color: var(--tmi-primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.5rem; margin-bottom: .75rem;
}

/* ---------- Forms ---------- */
.form-section-title { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--tmi-muted); margin-bottom: .75rem; }
.required::after { content: " *"; color: var(--tmi-danger); }
.permission-group { border: 1px solid var(--tmi-border); border-radius: .6rem; padding: .85rem 1rem; height: 100%; }
.permission-group-title { font-weight: 600; font-size: .82rem; text-transform: capitalize; margin-bottom: .5rem; }

/* ---------- Settings tabs ---------- */
.nav-tabs-app { border-bottom: 1px solid var(--tmi-border); gap: .25rem; flex-wrap: nowrap; overflow-x: auto; }
.nav-tabs-app .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--tmi-muted); font-weight: 500; white-space: nowrap; padding: .75rem 1rem; }
.nav-tabs-app .nav-link.active { color: var(--tmi-primary); border-bottom-color: var(--tmi-primary); background: none; }

/* ---------- Auth pages ---------- */
body.auth-body {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    background: radial-gradient(circle at 20% 10%, #e0e7ff 0, transparent 40%), radial-gradient(circle at 80% 90%, #ede9fe 0, transparent 40%), #f8fafc;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: .9rem;
}
.auth-card { width: 100%; max-width: 420px; border-radius: 1rem; }
.auth-brand { display: flex; align-items: center; gap: .65rem; justify-content: center; margin-bottom: 1.5rem; }
.auth-brand .brand-mark { font-size: .85rem; padding: .55rem .6rem; }

/* ---------- Documents ---------- */
.info-row { display: flex; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed #eef0f4; font-size: .86rem; }
.info-row:last-child { border-bottom: 0; }
.info-label { color: var(--tmi-muted); width: 42%; flex-shrink: 0; }
.info-value { font-weight: 500; min-width: 0; word-break: break-word; }
.summary-table { width: 100%; font-size: .88rem; }
.summary-table td { padding: .35rem 0; }
.summary-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary-table tr.total td { border-top: 1px solid var(--tmi-border); font-weight: 700; font-size: 1rem; padding-top: .6rem; }
.summary-table tr.muted td { color: var(--tmi-muted); }
.lines-table td { vertical-align: top !important; }
.lines-table .form-control, .lines-table .form-select { font-size: .86rem; }
.lines-table .ts-wrapper { min-width: 240px; }
.lines-table .col-product { min-width: 260px; }
.lines-table .col-num { width: 125px; min-width: 110px; }
.lines-table .col-total { width: 120px; text-align: right; padding-top: 1.05rem !important; font-weight: 600; white-space: nowrap; }
.lines-table .line-hint { font-size: .72rem; color: var(--tmi-muted); margin-top: .2rem; }
.ts-dropdown { font-size: .86rem; z-index: 1060; }
.ts-control { border-radius: .5rem; min-height: calc(1.5em + .75rem + 2px); }
.is-invalid + .ts-wrapper .ts-control, .ts-wrapper.is-invalid .ts-control { border-color: var(--bs-form-invalid-border-color); }
.status-banner { border-radius: var(--tmi-radius); padding: .85rem 1.1rem; display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; font-size: .88rem; }
.status-banner.cancelled { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.status-banner.draft { background: #f8fafc; color: #334155; border: 1px solid var(--tmi-border); }
.stat-inline { display: flex; flex-wrap: wrap; gap: 1.5rem; }
.stat-inline .stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--tmi-muted); font-weight: 600; }
.stat-inline .stat-value { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.report-card { transition: border-color .15s, box-shadow .15s; text-decoration: none; color: inherit; display: block; height: 100%; }
.report-card:hover { border-color: #c7d2fe; box-shadow: 0 4px 14px rgba(79, 70, 229, .08); color: inherit; }
.report-card .report-icon { width: 2.4rem; height: 2.4rem; border-radius: .6rem; display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem; }
.pl-table td { padding: .55rem 1rem; }
.pl-table tr.pl-subtotal td { font-weight: 700; border-top: 1px solid var(--tmi-border); background: #fafbff; }
.pl-table tr.pl-final td { font-weight: 800; font-size: 1.05rem; border-top: 2px solid var(--tmi-text); background: #f5f3ff; }
.pl-table td.indent { padding-left: 2rem; color: var(--tmi-muted); }

/* ---------- Print ---------- */
@media print {
    .app-sidebar, .app-topbar, .page-actions, .no-print, .alert, .table-toolbar form, .table-footer nav, .btn { display: none !important; }
    .app-main { margin: 0 !important; }
    .app-content { padding: 0 !important; max-width: none; }
    body.app-body { background: #fff; font-size: 11pt; }
    .card { border: 0; box-shadow: none; }
    .table-responsive { overflow: visible !important; }
    a { color: inherit !important; text-decoration: none !important; }
}

/* ---------- Misc ---------- */
.list-compact .list-group-item { padding: .7rem 1.25rem; border-color: #f1f5f9; }
.min-w-0 { min-width: 0; }
.fw-medium { font-weight: 500; }
code.doc-number { color: var(--tmi-text); background: #f1f5f9; padding: .1rem .4rem; border-radius: .3rem; font-size: .8rem; white-space: nowrap; }
