/* TQM Books — app shell styles (layered on top of Bootstrap 5) */
:root {
    --tb-bg: #f4f6fb;
    --tb-sidebar: #0f172a;
    --tb-sidebar-muted: #64748b;
    --tb-sidebar-text: #cbd5e1;
    --tb-accent: #2563eb;
    --tb-accent-2: #4f46e5;
    --tb-card: #ffffff;
    --tb-border: #e5e9f2;
    --tb-text: #1e293b;
    --tb-radius: 14px;
    --tb-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
}

html[data-theme="dark"] {
    --tb-bg: #0b1220;
    --tb-card: #131c2e;
    --tb-border: #24314a;
    --tb-text: #e2e8f0;
}
html[data-theme="dark"] body { background: #0b1220; color: var(--tb-text); }
html[data-theme="dark"] .topbar { background: #131c2e; }
html[data-theme="dark"] .kpi-card, html[data-theme="dark"] .panel,
html[data-theme="dark"] .perm-group, html[data-theme="dark"] .qa { background: var(--tb-card); }
html[data-theme="dark"] .kpi-hint, html[data-theme="dark"] .text-muted { color: #94a3b8 !important; }
html[data-theme="dark"] .table { --bs-table-color: var(--tb-text); --bs-table-bg: transparent; }
html[data-theme="dark"] .ai-answer .ai-a { background: #0b1220; }
html[data-theme="dark"] .qa:hover { background: #0b1220; }

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--tb-bg);
    color: var(--tb-text);
}

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

.sidebar {
    width: 244px;
    flex: 0 0 244px;
    background: var(--tb-sidebar);
    color: var(--tb-sidebar-text);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--tb-accent), var(--tb-accent-2));
    color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.brand-mark.lg { width: 52px; height: 52px; font-size: 20px; border-radius: 14px; }
.brand-name { font-weight: 600; color: #fff; font-size: 15px; }

.nav-group-title {
    font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--tb-sidebar-muted); margin: 16px 8px 6px;
}
.nav-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 12px; margin: 2px 0; border-radius: 9px;
    color: var(--tb-sidebar-text); text-decoration: none; font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
    background: linear-gradient(135deg, var(--tb-accent), var(--tb-accent-2));
    color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, .35);
}
.nav-item.disabled { opacity: .5; pointer-events: none; }
.nav-item .soon {
    font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
    background: rgba(255,255,255,.1); color: var(--tb-sidebar-muted);
    padding: 1px 6px; border-radius: 20px;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--tb-border);
    position: sticky; top: 0; z-index: 10;
}
.menu-toggle { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; }
.page-title { font-weight: 600; font-size: 16px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user-avatar {
    display: inline-grid; place-items: center; width: 30px; height: 30px;
    border-radius: 50%; background: var(--tb-accent); color: #fff; font-weight: 600; font-size: 13px;
}
.logout-form { margin: 0; }

.content { padding: 26px 24px; }
.welcome h2 { font-size: 22px; margin: 0 0 4px; }

/* ---------- KPI cards ---------- */
.kpi-grid {
    display: grid; gap: 16px; margin-top: 20px;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.kpi-card {
    background: var(--tb-card); border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius); padding: 18px; box-shadow: var(--tb-shadow);
}
.kpi-label { font-size: 13px; color: #64748b; }
.kpi-value { font-size: 26px; font-weight: 700; margin: 6px 0 2px; }
.kpi-hint { font-size: 12px; color: #94a3b8; }

.panel {
    background: var(--tb-card); border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius); padding: 20px 22px; box-shadow: var(--tb-shadow);
}
.panel h3 { font-size: 15px; margin: 0 0 12px; }
.build-list { list-style: none; margin: 0; padding: 0; }
.build-list li { padding: 6px 0; font-size: 14px; color: #475569; }
.build-list .done { color: #16a34a; font-weight: 700; margin-right: 8px; }
.build-list .todo { color: #cbd5e1; font-weight: 700; margin-right: 8px; }
.build-list em { color: var(--tb-accent); font-style: normal; font-size: 12px; }

/* ---------- Guest / auth ---------- */
body.guest {
    display: grid; place-items: center; min-height: 100vh;
    background: radial-gradient(1200px 600px at 20% -10%, #dbeafe, transparent),
                radial-gradient(1000px 500px at 100% 0%, #e0e7ff, transparent), var(--tb-bg);
}
.guest-wrap { width: 100%; max-width: 400px; padding: 20px; text-align: center; }
.auth-card {
    background: rgba(255,255,255,.85); backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,.6); border-radius: 18px;
    padding: 32px 28px; box-shadow: 0 20px 60px rgba(15, 23, 42, .12); text-align: left;
}
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .brand-mark { margin: 0 auto 12px; }
.auth-head h1 { font-size: 20px; margin: 0 0 2px; }
.auth-head p { color: #64748b; margin: 0; font-size: 14px; }
.auth-card .form-label { font-size: 13px; font-weight: 500; }
.auth-hint { font-size: 12px; color: #94a3b8; text-align: center; margin: 16px 0 0; }
.auth-hint code { color: #475569; }
.guest-foot { color: #94a3b8; font-size: 12px; margin-top: 18px; }
.error-card { text-align: center; }
.error-card h1 { font-size: 56px; margin: 0 0 8px; color: var(--tb-accent); }
.err-detail { text-align: left; font-size: 12px; background: #f1f5f9; padding: 10px; border-radius: 8px; overflow: auto; }

/* ---------- Phase 1: pages, forms, tables ---------- */
.page-head { margin-bottom: 6px; }
.page-head h2 { font-size: 22px; margin: 0 0 2px; }
.page-head.with-action { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-sub { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: #334155; }

.form-panel .form-label { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.table-panel { padding: 6px 6px 2px; overflow-x: auto; }
.table-panel table { font-size: 14px; }
.table-panel thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }

.link-card { text-decoration: none; color: inherit; transition: transform .12s, box-shadow .12s; display: block; }
.link-card:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(15,23,42,.10); }
.link-card .link-title { font-size: 16px; font-weight: 600; margin: 6px 0 2px; }

.check-grid { display: grid; gap: 6px 18px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.form-check { display: flex; align-items: center; gap: 8px; margin: 0; }
.form-check-input { margin: 0; }

.perm-groups { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.perm-group { border: 1px solid var(--tb-border); border-radius: 10px; padding: 12px 14px; }
.perm-module { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: #64748b; margin-bottom: 8px; }
.perm-group .form-check { align-items: flex-start; margin-bottom: 6px; }
.perm-code { font-size: 11px; color: #94a3b8; display: block; }

.qr-box { display: inline-block; padding: 10px; background: #fff; border: 1px solid var(--tb-border); border-radius: 10px; margin: 6px 0 10px; }

/* ---------- Phase 2: filters, pagination, dashboard, masters ---------- */
.filter-bar { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.filter-bar .form-control, .filter-bar .form-select { max-width: 360px; }
.pagination-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }

.dash-cols { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; }
.dash-cols .panel h3 { font-size: 15px; margin: 0 0 12px; }
@media (max-width: 900px) { .dash-cols { grid-template-columns: 1fr; } }
.quick-actions { display: grid; gap: 8px; }
.qa { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--tb-border);
      border-radius: 10px; text-decoration: none; color: var(--tb-text); font-size: 14px; transition: background .12s; }
.qa:hover { background: #f8fafc; }
.qa span { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
           background: #eef2ff; color: var(--tb-accent); font-weight: 700; }

.masters-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.master-list { list-style: none; margin: 0 0 12px; padding: 0; }
.master-list li { padding: 5px 0; font-size: 14px; border-bottom: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; }
.master-add { display: flex; gap: 8px; }

.img-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.img-thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--tb-border); }

.install-banner { display: flex; align-items: center; gap: 12px; background: #eef2ff; border: 1px solid #c7d2fe;
    border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.install-banner span { flex: 1; }

.line-table td { vertical-align: middle; }
.totals-table td { padding: 4px 8px; }
.ai-answer { border: 1px solid var(--tb-border); border-radius: 10px; overflow: hidden; }
.ai-answer .ai-q { padding: 10px 14px; background: #eef2ff; font-size: 14px; }
.ai-answer .ai-a { padding: 14px; background: #f8fafc; line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .sidebar {
        position: fixed; z-index: 40; left: -260px; transition: left .2s ease;
        box-shadow: 0 0 40px rgba(0,0,0,.3);
    }
    .sidebar.open { left: 0; }
    .menu-toggle { display: block; }
}
