/* CRUD Lab - layout and look. Bootstrap 5 does the grid and components; this file adds the theme. */
:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --bg: #f5f7fb;
    --card: #ffffff;
    --side-bg: #0f172a;
    --side-ink: #cbd5e1;
    --side-w: 264px;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
    --bs-primary: var(--brand);
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 79, 70, 229;
    --bs-body-font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Thai", sans-serif;
}

body { background: var(--bg); color: var(--ink); font-size: .935rem; }
a { text-decoration: none; }
code, pre, .font-mono { font-family: "Cascadia Code", "JetBrains Mono", Consolas, monospace; }

.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-dark); --bs-btn-disabled-bg: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: #c7d2fe; --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand-dark); }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--side-w); flex: 0 0 var(--side-w); background: var(--side-bg); color: var(--side-ink);
    padding: 1.1rem .9rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    background-image: radial-gradient(circle at 0 0, rgba(99, 102, 241, .25), transparent 45%);
}
.brand { display: flex; align-items: center; gap: .7rem; color: #fff; padding: .2rem .4rem 1.1rem; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem;
    background: linear-gradient(135deg, #6366f1, #06b6d4); box-shadow: 0 6px 18px rgba(99, 102, 241, .45); }
.brand-name { display: block; font-weight: 700; font-size: 1.08rem; letter-spacing: .2px; }
.brand-sub { display: block; font-size: .72rem; color: #94a3b8; }
.btn-new { background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; border: 0; border-radius: 10px;
    padding: .55rem; font-weight: 600; box-shadow: 0 6px 18px rgba(79, 70, 229, .35); }
.btn-new:hover { color: #fff; filter: brightness(1.08); }
.side-label { text-transform: uppercase; font-size: .68rem; letter-spacing: .09em; color: #64748b; margin: 1rem .6rem .35rem; font-weight: 600; }
.side-link { display: flex; align-items: center; gap: .65rem; color: var(--side-ink); padding: .45rem .65rem; border-radius: 9px; font-size: .9rem; }
.side-link i:first-child { font-size: 1rem; width: 1.1rem; text-align: center; opacity: .85; }
.side-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-link.active { background: rgba(99, 102, 241, .22); color: #fff; box-shadow: inset 3px 0 0 #818cf8; }
.side-count { margin-left: auto; font-size: .72rem; background: rgba(255, 255, 255, .08); padding: .08rem .5rem; border-radius: 99px; color: #e2e8f0; }
.side-link.active .side-count { background: #6366f1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 1rem; padding: .7rem 1.6rem;
    background: rgba(245, 247, 251, .85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-search { position: relative; flex: 0 1 420px; }
.top-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.top-search input { padding-left: 2.3rem; border-radius: 10px; background: #fff; }
.db-chip { font-size: .78rem; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: .3rem .7rem; }
.btn-sql { background: #0f172a; color: #e2e8f0; border-radius: 10px; font-size: .85rem; padding: .35rem .75rem; }
.btn-sql:hover { background: #1e293b; color: #fff; }
.btn-sql .badge { background: #22d3ee; color: #0f172a; }
.btn-icon { border: 1px solid var(--line); background: #fff; }

.flash-stack { padding: 1rem 1.6rem 0; }
.flash-stack .alert { border: 0; border-radius: 12px; margin-bottom: .5rem; }
.page { padding: 1.3rem 1.6rem 3rem; }

/* ---------- headings, cards ---------- */
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-title { font-weight: 700; font-size: 1.55rem; margin: 0; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin: .2rem 0 0; }
.cardx { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.cardx-pad { padding: 1.2rem 1.3rem; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-bottom: .7rem; }
.feature-hint { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; color: var(--brand); background: var(--brand-soft);
    padding: .2rem .6rem; border-radius: 99px; font-weight: 600; }

/* ---------- filters + bulk bar ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.filters .form-select, .filters .form-control { width: auto; min-width: 150px; border-radius: 9px; font-size: .88rem; }
.bulk-bar { display: none; align-items: center; flex-wrap: wrap; gap: .4rem; padding: .65rem 1rem; background: #eef2ff;
    border-bottom: 1px solid #c7d2fe; position: sticky; top: 58px; z-index: 5; }
.bulk-bar.show { display: flex; }
.bulk-bar .btn { font-size: .82rem; border-radius: 8px; }
.bulk-count { font-weight: 700; color: var(--brand-dark); margin-right: .4rem; }

/* ---------- article table ---------- */
.table-articles { margin: 0; }
.table-articles th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600;
    background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; padding: .65rem .6rem; }
.table-articles td { vertical-align: middle; padding: .7rem .6rem; border-color: #eef2f7; }
.table-articles tbody tr:hover { background: #fafbff; }
.table-articles tr.is-pinned { background: #fffdf5; }
.table-articles tr.is-selected { background: #eef2ff !important; }
.t-title { font-weight: 600; color: var(--ink); }
.t-title:hover { color: var(--brand); }
tr.is-unread .t-title { font-weight: 800; }
.unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3b82f6; margin-right: .4rem; vertical-align: middle; }
.t-summary { color: var(--muted); font-size: .82rem; max-width: 520px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-chip { font-family: "Cascadia Code", Consolas, monospace; font-size: .78rem; background: #f1f5f9; color: #334155; padding: .15rem .45rem; border-radius: 6px; white-space: nowrap; }
.tag { display: inline-block; font-size: .7rem; color: #475569; background: #f1f5f9; border-radius: 6px; padding: .05rem .4rem; margin: .15rem .2rem 0 0; }
.cat { display: inline-block; font-size: .75rem; font-weight: 600; padding: .18rem .55rem; border-radius: 99px; background: #ecfeff; color: #0e7490; white-space: nowrap; }
.toggle-btn { border: 0; background: transparent; padding: .15rem .25rem; font-size: 1.05rem; color: #cbd5e1; line-height: 1; border-radius: 6px; }
.toggle-btn:hover { background: #f1f5f9; color: #94a3b8; }
.toggle-btn.on-pin { color: #f59e0b; }
.toggle-btn.on-star { color: #eab308; }
.flag-icons i { margin-right: .25rem; color: #94a3b8; }
.flag-icons .bi-lock-fill { color: #dc2626; }
.flag-icons .bi-archive-fill { color: #7c3aed; }

.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .74rem; font-weight: 600; padding: .2rem .6rem; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-DRAFT { background: #f1f5f9; color: #475569; }
.pill-PUBLISHED { background: #dcfce7; color: #15803d; }
.pill-UNPUBLISHED { background: #fef3c7; color: #b45309; }
.prio { font-size: .74rem; font-weight: 600; }
.prio-HIGH { color: #dc2626; }
.prio-NORMAL { color: #64748b; }
.prio-LOW { color: #94a3b8; }

.dropdown-menu { border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(15, 23, 42, .14); padding: .35rem; font-size: .88rem; }
.dropdown-item { border-radius: 8px; padding: .4rem .7rem; }
.dropdown-item i { width: 1.2rem; display: inline-block; color: #64748b; }
.dropdown-item.text-danger i { color: inherit; }
.dropdown-header { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }

.empty { text-align: center; padding: 3.5rem 1rem; color: var(--muted); }
.empty i { font-size: 2.6rem; color: #c7d2fe; }
.pager { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; padding: .8rem 1rem; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.pagination { margin: 0; --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-border-radius: 8px; }

/* ---------- article view ---------- */
.article-body { white-space: pre-wrap; line-height: 1.75; font-size: .98rem; }
.meta-list { list-style: none; padding: 0; margin: 0; font-size: .86rem; }
.meta-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.meta-list li span:first-child { color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; font-size: .85rem; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.lock-banner { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; border-radius: 12px; padding: .8rem 1rem; }
.state-banner { background: #f5f3ff; color: #5b21b6; border: 1px solid #ddd6fe; border-radius: 12px; padding: .8rem 1rem; }
.action-bar { display: flex; flex-wrap: wrap; gap: .4rem; }
.action-bar .btn { border-radius: 9px; font-size: .85rem; }

/* ---------- forms ---------- */
.form-label { font-weight: 600; font-size: .85rem; color: #334155; }
.form-hint { font-size: .78rem; color: var(--muted); }
.prio-switch .btn { font-size: .85rem; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
    padding: .8rem 1.3rem; border-radius: 0 0 var(--radius) var(--radius); display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- code blocks ---------- */
.codebox { background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: .9rem 1rem; font-size: .8rem; line-height: 1.55; margin: 0; white-space: pre-wrap; word-break: break-word; }
.codebox .kw { color: #93c5fd; }
.label-java, .label-sql { font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: .1rem .45rem; border-radius: 5px; }
.label-java { background: #fff7ed; color: #c2410c; }
.label-sql { background: #ecfeff; color: #0e7490; }

/* ---------- learn page ---------- */
.hero { border-radius: 20px; padding: 2rem 2.2rem; color: #fff; position: relative; overflow: hidden;
    background: linear-gradient(120deg, #312e81 0%, #4f46e5 45%, #0891b2 100%); box-shadow: 0 18px 40px rgba(79, 70, 229, .28); }
.hero::after { content: ""; position: absolute; right: -80px; top: -80px; width: 320px; height: 320px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.hero h1 { font-weight: 800; font-size: 2rem; letter-spacing: -.02em; }
.hero p { color: #e0e7ff; max-width: 760px; }
.stack-chip { display: inline-flex; align-items: center; gap: .4rem; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22);
    padding: .3rem .75rem; border-radius: 99px; font-size: .8rem; margin: .2rem .3rem 0 0; }
.feature-card { height: 100%; display: flex; flex-direction: column; transition: transform .15s ease, box-shadow .15s ease; }
.feature-card:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(15, 23, 42, .1); }
.feature-no { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: .85rem;
    background: var(--brand-soft); color: var(--brand); flex: 0 0 34px; }
.feature-icon { font-size: 1.3rem; color: #0891b2; }
.feature-card h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.feature-card p { color: #475569; font-size: .86rem; }
.group-title { font-weight: 700; font-size: 1.05rem; margin: 2rem 0 .8rem; display: flex; align-items: center; gap: .6rem; }
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tree { font-size: .8rem; }

/* ---------- activity ---------- */
.act { font-size: .7rem; font-weight: 700; letter-spacing: .04em; padding: .2rem .5rem; border-radius: 6px; background: #f1f5f9; color: #475569; white-space: nowrap; }
.act-CREATE, .act-BATCH_INSERT, .act-SEED, .act-DUPLICATE { background: #dcfce7; color: #15803d; }
.act-UPDATE, .act-BATCH_UPDATE, .act-UPSERT, .act-MERGE { background: #e0e7ff; color: #4338ca; }
.act-HARD_DELETE, .act-BATCH_HARD_DELETE, .act-EMPTY_TRASH { background: #fee2e2; color: #b91c1c; }
.act-SOFT_DELETE, .act-BATCH_SOFT_DELETE { background: #ffedd5; color: #c2410c; }
.act-LOCK { background: #fecaca; color: #991b1b; }
.act-PUBLISH { background: #d1fae5; color: #047857; }
.act-ARCHIVE { background: #ede9fe; color: #6d28d9; }

/* ---------- SQL panel ---------- */
.sql-panel { background: #0b1120; color: #e2e8f0; width: 560px !important; max-width: 100vw; }
.sql-panel .offcanvas-header { border-bottom: 1px solid #1e293b; }
.sql-panel code { color: #67e8f9; }
.sql-head { font-size: .72rem; letter-spacing: .08em; color: #a5b4fc; font-weight: 700; margin: 1rem 0 .5rem; }
.sql-item { display: flex; gap: .6rem; margin-bottom: .5rem; }
.sql-no { flex: 0 0 24px; height: 24px; border-radius: 6px; background: #1e293b; color: #94a3b8; display: grid; place-items: center; font-size: .72rem; }
.sql-item pre { flex: 1; margin: 0; background: #111827; border: 1px solid #1f2937; color: #e5e7eb; padding: .55rem .7rem; border-radius: 8px;
    font-size: .76rem; white-space: pre-wrap; word-break: break-word; }

/* ---------- responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { position: fixed; left: 0; z-index: 1040; transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
    .topbar, .page, .flash-stack { padding-left: 1rem; padding-right: 1rem; }
    .db-chip { display: none; }
    .hero { padding: 1.5rem; }
}
