/* ธีมตรงกับแอป MAUI (Colors.xaml): Primary #006199, พื้น #F1F5F9 / #0B1220, ฟอนต์ Google Fonts Sarabun */
:root {
    --ecc-font-family: 'Sarabun', sans-serif;
    --mud-typography-default-family: 'Sarabun', sans-serif;
    --primary: #006199;
    --accent: #2563EB;
    --bg: #F1F5F9;
    --card: #FFFFFF;
    --border: #E2E8F0;
    --text: #0F172A;
    --text-2: #334155;
    --text-3: #64748B;
    --text-4: #94A3B8;
    --info-bg: #EFF6FF;
    --info-border: #BFDBFE;
    --info-text: #1E3A8A;
    --warn-bg: #FEF3C7;
    --ok-bg: #F0FDF4;
    --bad-bg: #FEE2E2;
    --bad-text: #B91C1C;
    --err-bg: #FEF2F2;
    --err-border: #FECACA;
    --ok: #16A34A;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #4FA3D1;
        --accent: #60A5FA;
        --bg: #0B1220;
        --card: #172033;
        --border: #334155;
        --text: #E2E8F0;
        --text-2: #CBD5E1;
        --text-3: #94A3B8;
        --text-4: #64748B;
        --info-bg: #14233F;
        --info-border: #1E3A8A;
        --info-text: #BFDBFE;
        --warn-bg: #3A2A0A;
        --ok-bg: #10281A;
        --bad-bg: #4A1D22;
        --bad-text: #FCA5A5;
        --err-bg: #3B1519;
        --err-border: #7F1D1D;
    }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--ecc-font-family);
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, h5, h6 { font-family: var(--ecc-font-family); font-weight: 700; margin: 0; }

.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 12px; color: var(--text-3); }
.boot img { width: 72px; height: 72px; border-radius: 16px; }

/* ===== โครงหน้า: หัวเรื่อง + เนื้อหาเลื่อน + แถบเมนูล่าง ===== */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto; }
.app-header {
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
}
.app-header .title { flex: 1; min-width: 0; }
.app-header h1 { font-size: 20px; }
.app-header .sub { font-size: 12px; color: var(--accent); }
.app-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 20px; }

.tabbar {
    display: flex; background: var(--card); border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
}
.tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 4px 6px; text-decoration: none; color: var(--text-3); font-size: 11px; position: relative; min-height: 52px;
}
.tabbar a.active { color: var(--primary); font-weight: 700; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
    position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; background: #DC2626; color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ===== การ์ด / ปุ่ม / ฟอร์ม ===== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.card.unread { border-color: var(--primary); }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.section-title { font-family: "Sarabun", sans-serif; font-weight: 700; font-size: 16px; margin: 14px 0 8px; }
.muted { color: var(--text-3); font-size: 12px; }
.small { font-size: 13px; color: var(--text-2); }

.btn {
    appearance: none; border: 0; border-radius: 12px; min-height: 44px; padding: 0 16px;
    font: inherit; font-weight: 700; cursor: pointer; background: var(--primary); color: #fff; width: 100%;
}
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--bad-bg); color: var(--bad-text); }
.btn.ok { background: var(--ok); }
.btn.small { min-height: 36px; width: auto; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .55; }

.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 700; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
    width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
    background: var(--card); color: var(--text); font: inherit; font-size: 16px; /* 16px กัน iOS ซูมเองตอนแตะช่อง */
}
.field textarea { min-height: 84px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin-bottom: 8px; }

.quota-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quota-grid .card { margin: 0; }
.quota-name { font-weight: 700; font-size: 13px; color: var(--text-2); }
.quota-left { font-family: "Sarabun", sans-serif; font-weight: 700; font-size: 18px; color: var(--accent); }

.pill { display: inline-block; border-radius: 8px; padding: 2px 8px; font-size: 11px; font-weight: 700; background: var(--info-bg); color: var(--text-2); }
.pill.APPROVED, .pill.SUCCESS { background: var(--ok-bg); }
.pill.REJECTED, .pill.CRITICAL { background: var(--bad-bg); }
.pill.PENDING, .pill.WARNING, .pill.APPROVAL { background: var(--warn-bg); }

.day-row { display: flex; justify-content: space-between; align-items: center; min-height: 40px; font-size: 12px; color: var(--text-2); border-top: 1px dashed var(--border); }
.day-row.cancelled { opacity: .5; text-decoration: line-through; }
.day-row button { background: none; border: 0; color: var(--bad-text); font: inherit; font-size: 12px; font-weight: 700; padding: 8px 0 8px 12px; }

.banner { border: 1px solid var(--info-border); background: var(--info-bg); color: var(--info-text); border-radius: 12px; padding: 10px 12px; font-size: 13px; white-space: pre-line; margin-bottom: 12px; }
.banner.error { border-color: var(--err-border); background: var(--err-bg); color: var(--bad-text); }
.empty { text-align: center; color: var(--text-3); padding: 40px 16px; }
.empty b { display: block; font-family: "Sarabun", sans-serif; font-size: 18px; color: var(--text-2); margin-bottom: 4px; }
.spinner { width: 28px; height: 28px; margin: 24px auto; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== กล่องโต้ตอบ ===== */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50; }
.dialog { background: var(--card); border-radius: 16px; padding: 18px; width: 100%; max-width: 380px; }
.dialog h3 { font-size: 17px; margin-bottom: 8px; }
.dialog p { margin: 0 0 12px; white-space: pre-line; color: var(--text-2); font-size: 14px; }
.dialog input { width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; margin-bottom: 12px; }
.dialog .actions { display: flex; gap: 8px; }

/* ===== เข้าสู่ระบบ ===== */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { max-width: 400px; width: 100%; padding: 24px 22px; }
.login .brand { text-align: center; margin-bottom: 18px; }
.login .brand img { width: 72px; height: 72px; border-radius: 16px; }
.login .brand h1 { color: var(--primary); font-size: 26px; margin-top: 8px; }

#blazor-error-ui {
    background: #FEF3C7; color: #78350F; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0;
    padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* ===== Modern Enterprise 2026 Shell & Dashboard ===== */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.28); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.48); }

.ecc-appbar {
    box-sizing: border-box;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    backdrop-filter: blur(10px);
}

.ecc-brand-badge {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #006199 0%, #0284C7 100%);
    color: #FFFFFF;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 2px 6px rgba(0, 97, 153, 0.25);
}

.ecc-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--mud-palette-lines-default);
    background: var(--mud-palette-background);
    color: var(--mud-palette-text-secondary);
}

.ecc-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ecc-status-dot.online { background: #16A34A; box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2); }
.ecc-status-dot.offline { background: #DC2626; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2); }

/* Sidebar Navigation */
.ecc-drawer {
    border-right: 1px solid var(--mud-palette-lines-default);
}

.ecc-drawer .mud-nav-link {
    border-radius: 8px;
    margin: 2px 10px;
    padding: 7px 12px;
    width: calc(100% - 20px);
    font-size: 13.5px;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.ecc-drawer .mud-nav-link.active:not(.mud-nav-link-disabled) {
    background-color: rgba(0, 97, 153, 0.10);
    color: var(--mud-palette-primary);
    font-weight: 700;
}

.ecc-drawer .mud-nav-link.active:not(.mud-nav-link-disabled) .mud-nav-link-icon {
    color: var(--mud-palette-primary);
}

.ecc-drawer .mud-nav-group > .mud-nav-link {
    font-weight: 600;
    font-size: 13px;
    color: var(--mud-palette-text-secondary);
}

.ecc-drawer .mud-nav-group-items .mud-nav-link {
    padding-left: 16px;
}

.ecc-nav-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--mud-palette-text-secondary);
    opacity: 0.75;
    padding: 12px 18px 4px;
    text-transform: uppercase;
}

/* Dashboard Hero */
.ecc-hero {
    background: linear-gradient(135deg, #006199 0%, #004E7C 58%, #00395B 100%);
    color: #FFFFFF;
    border-radius: 14px;
    padding: 22px 26px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 24px -6px rgba(0, 97, 153, 0.30);
}

.ecc-hero::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -80px;
    width: 260px;
    height: 260px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0) 70%);
    pointer-events: none;
}

.ecc-hero-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.20);
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 500;
}

/* Modern Feature Tiles */
.ecc-tile {
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 12px;
    padding: 15px 16px;
    min-height: 78px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
    height: 100%;
    text-align: left;
}

.ecc-tile:hover {
    transform: translateY(-2px);
    border-color: var(--mud-palette-primary);
    box-shadow: 0 8px 20px -8px rgba(0, 97, 153, 0.22);
}

.ecc-tile.featured {
    border-color: rgba(0, 97, 153, 0.45);
    background: linear-gradient(135deg, rgba(0, 97, 153, 0.06) 0%, var(--mud-palette-surface) 70%);
}

.ecc-tile-icon {
    width: 44px;
    height: 44px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ecc-tile-icon.blue { background: rgba(0, 97, 153, 0.12); color: #006199; }
.ecc-tile-icon.green { background: rgba(22, 163, 74, 0.12); color: #16A34A; }
.ecc-tile-icon.amber { background: rgba(217, 119, 6, 0.13); color: #D97706; }
.ecc-tile-icon.red { background: rgba(220, 38, 38, 0.12); color: #DC2626; }
.ecc-tile-icon.sky { background: rgba(2, 132, 199, 0.12); color: #0284C7; }
.ecc-tile-icon.slate { background: rgba(71, 85, 105, 0.12); color: #475569; }

.ecc-tile-arrow {
    margin-left: auto;
    color: var(--mud-palette-text-secondary);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.ecc-tile:hover .ecc-tile-arrow {
    opacity: 0.9;
    transform: translateX(0);
    color: var(--mud-palette-primary);
}

/* Modern Login Backdrop */
.ecc-login-bg {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 15%, rgba(0, 97, 153, 0.12) 0%, transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(2, 132, 199, 0.10) 0%, transparent 45%),
        var(--mud-palette-background);
}

.ecc-login-card {
    width: 100%;
    max-width: 430px;
    border-radius: 16px;
    border: 1px solid var(--mud-palette-lines-default);
    box-shadow: 0 20px 40px -15px rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.ecc-login-topbar {
    height: 4px;
    background: linear-gradient(90deg, #006199 0%, #0284C7 55%, #38BDF8 100%);
}

/* Tabular numerals for ERP numbers */
.ecc-num, .mud-table-cell {
    font-variant-numeric: tabular-nums;
}

/* ===== Gmail-style framed shell: tinted shell (appbar + drawer) and one framed work panel ===== */
:root { --ecc-shell: color-mix(in srgb, var(--mud-palette-primary) 7%, var(--mud-palette-background)); }
.ecc-appbar.mud-appbar { background-color: var(--ecc-shell) !important; border-bottom: 0; backdrop-filter: none; }
.ecc-drawer.mud-drawer { background-color: var(--ecc-shell) !important; border-right: 0; }
.ecc-main.mud-main-content { background-color: var(--ecc-shell); padding-right: 12px; padding-bottom: 12px; }
.ecc-frame {
    box-sizing: border-box;
    height: calc(100vh - var(--mud-appbar-height) - 12px);
    overflow: auto;
    padding: 16px 20px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    border-radius: 16px;
    border: 1px solid var(--mud-palette-lines-default);
}

/* Preview/kit pages: tabs fill the remaining frame height so only the table scrolls */
.ecc-tabs-fill.mud-tabs { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ecc-tabs-fill .mud-tabs-panels { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ecc-tabs-fill .mud-tabs-panels > * { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ecc-tabs-fill__panel { padding-top: 8px; }
.ecc-tabs-fill .mud-tabs-tabbar { background: transparent; color: var(--mud-palette-text-secondary); border-bottom: 1px solid var(--mud-palette-lines-default); min-height: 40px; }
.ecc-tabs-fill .mud-tabs-tabbar .mud-tab { min-height: 40px; text-transform: none; font-weight: 500; color: var(--mud-palette-text-secondary); }
.ecc-tabs-fill .mud-tabs-tabbar .mud-tab.mud-tab-active { color: var(--mud-palette-primary); font-weight: 600; }
.ecc-tabs-fill .mud-tab-slider { background-color: var(--mud-palette-primary); }
