:root {
    /* Advance Digital brand — same palette as the ERP (light, orange accents) */
    --primary: #ff5900;
    --primary-dark: #d24a00;
    --primary-light: #ff7a33;
    --primary-glow: rgba(255, 89, 0, 0.22);
    --ink: #0f172a;
    --ink-soft: #334155;
    --muted: #64748b;
    --line: #e5e8ee;
    --bg: #f5f6fa;
    --card: #ffffff;
    --radius: 14px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

html, body {
    font-family: 'Inter', 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
h1:focus { outline: none; }

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); }

/* ===== Buttons ===== */
.btn { border-radius: 9px; font-weight: 600; }

.btn-primary {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

/* Bootstrap's own blue would leak through outline buttons, checkboxes and pagers — keep them on brand. */
.btn-outline-primary { color: var(--primary-dark); border-color: var(--primary); background: #fff; }
.btn-outline-primary:hover, .btn-outline-primary:focus, .btn-outline-primary.active, .btn-check:checked + .btn-outline-primary {
    color: #fff; background: var(--primary); border-color: var(--primary);
}
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.page-link { color: var(--primary-dark); }
.active > .page-link, .page-link.active { background-color: var(--primary); border-color: var(--primary); color: #fff; }
.nav-pills .nav-link.active { background-color: var(--primary); }
.nav-tabs .nav-link { color: var(--ink-soft); }
.btn-link { color: var(--primary-dark); }
.btn-link:hover { color: var(--primary); }
.nav-tabs .nav-link.active { color: var(--primary-dark); }
.text-primary { color: var(--primary-dark) !important; }
.bg-primary { background-color: var(--primary) !important; }

.btn:focus, .btn:active:focus, .form-control:focus, .form-select:focus {
    box-shadow: 0 0 0 0.2rem var(--primary-glow);
    border-color: var(--primary-light);
}

.btn-outline-secondary { border-color: var(--line); color: var(--ink-soft); }
.btn-outline-secondary:hover { background: #f1f5f9; color: var(--ink); border-color: var(--line); }

/* ===== Cards ===== */
.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--card);
}

/* ===== Tables ===== */
.table {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line);
    margin-bottom: 0;
}
.table > thead > tr > th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--line);
    padding: 0.75rem 1rem;
}
.table > tbody > tr > td { padding: 0.75rem 1rem; border-color: #eef1f6; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { background: #f8faff; }

/* ===== Forms ===== */
.form-label { font-weight: 600; font-size: 0.88rem; color: var(--ink-soft); margin-bottom: 0.3rem; }
.form-control, .form-select { border-radius: 9px; border-color: var(--line); padding: 0.5rem 0.75rem; }

/* ===== Badges ===== */
.badge { font-weight: 600; padding: 0.4em 0.7em; border-radius: 6px; }

/* ===== Validation ===== */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; font-size: 0.85rem; }

/* ===== Dashboard stat cards ===== */
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
    height: 100%;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-num { font-size: 1.9rem; font-weight: 800; line-height: 1; color: var(--ink); }
.stat-label { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.stat-accent { background: linear-gradient(120deg, var(--primary-light), var(--primary-dark)); border: none; }
.stat-accent .stat-num, .stat-accent .stat-label { color: #fff; }

/* ===== Page header ===== */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

/* ===== Search + pager ===== */
.toolbar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.search-box { max-width: 340px; }

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    color: var(--muted);
    font-size: 0.9rem;
}
.pager .pages { display: flex; gap: 0.25rem; }
.pager button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    min-width: 36px;
    height: 36px;
    padding: 0 0.6rem;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
}
.pager button:hover:not(:disabled) { background: #f1f5f9; }
.pager button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager button:disabled { opacity: 0.45; cursor: not-allowed; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}
.blazor-error-boundary::after { content: "An error has occurred."; }

/* ===== Topbar user ===== */
.topbar-user { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; color: var(--ink-soft); font-size: 0.9rem; }
.topbar-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--primary); color: #fff; font-weight: 700; font-size: 0.85rem;
}

/* ===== Auth / login ===== */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(900px 520px at 85% 0%, rgba(255, 89, 0, 0.10), rgba(255, 89, 0, 0) 70%), #f5f6fa;
    padding: 1.5rem;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 18px;
    padding: 2.25rem 2rem;
    border: 1px solid var(--line);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.10);
}
.login-brand { font-weight: 800; font-size: 1.1rem; color: var(--primary); margin-bottom: 1rem; }
.login-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 1.25rem; }
.login-hint { margin-top: 1.25rem; font-size: 0.82rem; color: var(--muted); text-align: center; }
.login-hint code { color: var(--primary-dark); }

/* ===== Tags ===== */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    line-height: 1.4;
}
.tag-chip .tag-x {
    border: none;
    background: rgba(255,255,255,0.25);
    color: #fff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    line-height: 1;
    font-size: 0.65rem;
    cursor: pointer;
    padding: 0;
}
.tag-chip .tag-x:hover { background: rgba(255,255,255,0.45); }
.tag-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.tag-picker .tag-add { width: auto; min-width: 140px; }

/* ===== Settings hub grid ===== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.settings-card {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    box-shadow: var(--shadow-sm);
    color: var(--ink);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.settings-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: var(--ink); }
.settings-card .sc-ico { font-size: 1.5rem; }
.settings-card .sc-title { font-weight: 700; margin-top: 0.4rem; }
.settings-card .sc-desc { font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }

/* ===== Document totals box ===== */
.totals-box { max-width: 320px; margin-left: auto; }
.totals-box .row-line { display: flex; justify-content: space-between; padding: 0.25rem 0; }
.totals-box .grand { border-top: 2px solid var(--line); margin-top: 0.35rem; padding-top: 0.5rem; font-weight: 800; font-size: 1.1rem; }

/* ===== Status pills ===== */
.pill { font-size: 0.75rem; font-weight: 700; padding: 0.25em 0.7em; border-radius: 999px; }
.pill-draft { background: #f1f5f9; color: #334155; }
.pill-confirmed { background: #ecfeff; color: #0e7490; }
.pill-done { background: #ecfdf5; color: #047857; }
.pill-cancelled { background: #fef2f2; color: #b91c1c; }

.nav-sub { padding-left: 0.5rem; }

/* ===== Login divider ===== */
.login-or { display:flex; align-items:center; text-align:center; color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0 1rem; }
.login-or::before, .login-or::after { content:""; flex:1; border-bottom:1px solid var(--line); }
.login-or span { padding: 0 0.75rem; }

/* ===== Report bar charts (pure CSS, no JS) ===== */
.bars { display: flex; flex-direction: column; gap: 0.5rem; }
.bar-row { display: grid; grid-template-columns: 140px 1fr auto; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.bar-row .bar-label { color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: #eef1f6; border-radius: 6px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary-light), var(--primary)); border-radius: 6px; min-width: 2px; }
.bar-fill.alt { background: linear-gradient(90deg, #f59e0b, #d97706); }
.bar-val { font-weight: 600; color: var(--ink); white-space: nowrap; }

/* Column chart (dashboard sales vs purchases) */
.cols { display: flex; align-items: flex-end; gap: 1rem; height: 180px; padding-top: 10px; }
.col-group { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; height: 100%; justify-content: flex-end; }
.col-pair { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.col { width: 26px; border-radius: 4px 4px 0 0; min-height: 2px; }
.col.sales { background: linear-gradient(180deg, var(--primary-light), var(--primary)); }
.col.purch { background: linear-gradient(180deg, #f59e0b, #d97706); }
.col-label { font-size: 0.72rem; color: var(--muted); }
.legend { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.5rem; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
.legend .dot.sales { background: var(--primary); }
.legend .dot.purch { background: #d97706; }

/* ===== Public register / policy ===== */
.register-card { width: 100%; max-width: 520px; background:#fff; border-radius:18px; padding:2.25rem 2rem; box-shadow:0 24px 60px rgba(0,0,0,.3); margin: 1rem auto; }
.contact-row { display:flex; flex-wrap:wrap; gap:.6rem; margin-top:1rem; }
.contact-chip { display:inline-flex; align-items:center; gap:.35rem; background:#f1f5f9; border:1px solid var(--line); border-radius:999px; padding:.45rem .9rem; font-weight:600; color:var(--ink-soft); }
.contact-chip:hover { background:#e2e8f0; color:var(--ink); }
.chip-check { display:inline-flex; align-items:center; gap:.4rem; border:1px solid var(--line); border-radius:999px; padding:.35rem .8rem; font-size:.88rem; cursor:pointer; }
.policy { font-size:.92rem; color:var(--ink-soft); }
.policy h2 { color:var(--ink); }

/* ===== Client portal ===== */
.portal-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.portal-topbar {
    background: var(--card); border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm); position: sticky; top: 0; z-index: 10;
}
.portal-top {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
    max-width: 960px; margin: 0 auto; padding: .7rem 1.5rem .4rem;
}
.portal-brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--ink); letter-spacing: -0.01em; text-decoration: none; }
.portal-logo { height: 1.75rem; width: auto; }
.portal-brand span { color: var(--muted); font-weight: 600; font-size: .85rem; padding-left: .5rem; border-left: 1px solid var(--line); }
.portal-account { display: flex; align-items: center; gap: .75rem; font-size: .85rem; }
.portal-user { color: var(--ink-soft); font-weight: 600; }
.portal-role { margin-left: .35rem; padding: .1rem .5rem; border-radius: 999px; background: #fff1e8; color: var(--primary-dark); font-size: .75rem; font-weight: 600; white-space: nowrap; }
.portal-account-link { color: var(--muted); text-decoration: none; white-space: nowrap; }
.portal-account-link:hover { color: var(--primary-dark); }
.portal-nav {
    display: flex; gap: .25rem; max-width: 960px; margin: 0 auto; padding: 0 1.25rem;
    overflow-x: auto; scrollbar-width: none;
}
.portal-nav-link {
    padding: .55rem .8rem; font-weight: 600; font-size: .92rem; color: var(--ink-soft); white-space: nowrap;
    border-bottom: 2px solid transparent; text-decoration: none;
}
.portal-nav-link:hover { color: var(--ink); }
.portal-nav-link.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.portal-main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 1.5rem; }
.portal-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

/* Blazor's error bar — hidden until Blazor shows it. Global (not only MainLayout's scoped CSS) so the
   login / change-password pages on EmptyLayout do not show it permanently. */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ===== Dashboard app grid + task launcher (same look as the ERP dashboard) ===== */
.appgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 8px; }
.appgrid .app { display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; color: inherit; }
.appgrid .app-ico { position: relative; width: 64px; height: 64px; border-radius: 16px; display: flex; align-items: center;
                    justify-content: center; font-size: 2rem; box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .12s; }
.appgrid .app:hover .app-ico { transform: scale(1.08); }
.appgrid .app-name { font-size: .82rem; text-align: center; line-height: 1.2; color: var(--ink-soft); }
.appgrid .app-badge { position: absolute; top: -6px; right: -6px; background: #dc2626; color: #fff; font-size: .68rem; font-weight: 700;
                      border-radius: 999px; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
                      padding: 0 5px; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.launcher { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.launcher .go { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
                text-decoration: none; color: inherit; transition: box-shadow .12s, border-color .12s; background: #fff; }
.launcher .go:hover { border-color: var(--primary-light); box-shadow: 0 2px 10px var(--primary-glow); }
.launcher .go-ico { font-size: 1.5rem; }
.launcher b { display: block; font-size: .95rem; color: var(--ink); }
.launcher small { color: var(--muted); display: block; line-height: 1.25; }

/* ===== AD logo loader (AD.Brand) — replaces bare "กำลังโหลด…" text ===== */
.ad-loader { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 0; }
.ad-loader-mark { position: relative; width: var(--ad-size); height: var(--ad-size); }
.ad-loader-text { font-size: 0.9rem; color: #6b7280; letter-spacing: .02em; }
.ad-mark { position: absolute; inset: 0; -webkit-mask: url(/ad-logo.png) center / contain no-repeat; mask: url(/ad-logo.png) center / contain no-repeat; background: #E8491D; }
.ad-mark-ghost { opacity: .16; }
.ad-mark-fill { clip-path: inset(100% 0 0 0); animation: ad-rise 2.2s cubic-bezier(.4,0,.2,1) infinite; }
.ad-mark-sheen { background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.55) 50%, transparent 65%); background-size: 250% 100%; opacity: 0; animation: ad-sheen 2.2s ease-in-out infinite; }
@keyframes ad-rise { 0% { clip-path: inset(100% 0 0 0); opacity: 1 } 55% { clip-path: inset(0 0 0 0); opacity: 1 } 85% { clip-path: inset(0 0 0 0); opacity: 1 } 100% { clip-path: inset(0 0 0 0); opacity: 0 } }
@keyframes ad-sheen { 0%,55% { background-position: 120% 0; opacity: 0 } 60% { opacity: 1 } 80% { background-position: -20% 0; opacity: 1 } 85%,100% { background-position: -20% 0; opacity: 0 } }
@media (prefers-reduced-motion: reduce) { .ad-mark-fill { animation: none; clip-path: none; opacity: 1; } .ad-mark-sheen { display: none; } }

/* Page subtitles under a title stay quiet */
.page-head .text-muted.small { display: block; max-width: 760px; margin-top: .15rem; }

/* Client sub-navigation (บัญชี — ลูกค้า): quiet underline tabs like the ERP, instead of Bootstrap's blue pills. */
.client-tabs { display: flex; flex-wrap: wrap; gap: .1rem .25rem; border-bottom: 1px solid var(--line); }
.client-tabs .nav-link {
    padding: .5rem .75rem; color: var(--ink-soft); font-weight: 600; font-size: .92rem; white-space: nowrap;
    border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 0;
}
.client-tabs .nav-link:hover { color: var(--ink); }
.client-tabs .nav-link.active { color: var(--primary-dark); border-bottom-color: var(--primary); background: none; }
