:root {
    --app-bg: #eef2f6;
    --app-surface: #ffffff;
    --app-ink: #0f172a;
    --app-muted: #64748b;
    --app-line: #e2e8f0;
    --app-primary: #1d4ed8;
    --app-primary-soft: #eff6ff;
    --app-success: #059669;
    --app-success-soft: #ecfdf5;
    --app-warning: #d97706;
    --app-warning-soft: #fff7ed;
    --app-danger: #dc2626;
    --app-radius: 14px;
    --app-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    background:
        radial-gradient(1200px 400px at 50% -120px, rgba(29, 78, 216, 0.08), transparent 60%),
        var(--app-bg);
    color: var(--app-ink);
    font-family: 'Kanit', 'kanit', sans-serif;
    min-height: 100vh;
}

.app-page {
    padding-bottom: 3rem;
}

/* Navbar */
.app-navbar {
    position: sticky;
    top: 0;
    z-index: 1040;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--app-line);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.app-navbar .navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--app-ink);
    letter-spacing: -0.02em;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--app-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
}

.app-navbar .nav-link {
    color: #475569;
    font-weight: 500;
    border-radius: 8px;
    padding: 0.42rem 0.75rem;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
    color: var(--app-primary);
    background: var(--app-primary-soft);
}

.app-navbar .dropdown-menu {
    border: 1px solid var(--app-line);
    border-radius: 12px;
    box-shadow: var(--app-shadow);
    padding: 0.45rem;
    min-width: 210px;
}

.app-navbar .dropdown-item {
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    color: #334155;
}

.app-navbar .dropdown-item.active,
.app-navbar .dropdown-item:active {
    background: var(--app-primary-soft);
    color: var(--app-primary);
}

.navbar-user {
    color: #000;
    font-size: 0.9rem;
}

/* Headings */
.page-heading {
    margin-bottom: 1.25rem;
}

.page-heading h1,
.page-heading h2,
h2 {
    font-size: 1.55rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0;
}

.page-heading p {
    margin: 0.3rem 0 0;
    color: var(--app-muted);
}

/* Surfaces */
.app-panel,
.filter-panel,
.table-wrap {
    background: var(--app-surface);
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
}

.app-panel,
.filter-panel {
    padding: 1.35rem 1.45rem;
}

.form-section + .form-section {
    margin-top: 1.15rem;
    padding-top: 1.15rem;
    border-top: 1px solid var(--app-line);
}

.form-section-title {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--app-muted);
    margin-bottom: 0.85rem;
}

.option-box {
    background: #f8fafc;
    border: 1px solid var(--app-line);
    border-radius: 10px;
    padding: 0.75rem 0.85rem;
}

/* Forms */
.form-label {
    font-weight: 500;
    color: #334155;
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border-color: #dbe3ec;
    border-radius: 10px;
    min-height: 42px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

.form-control[readonly] {
    background-color: #f8fafc;
}

.btn {
    border-radius: 10px;
    font-weight: 500;
    padding: 0.5rem 0.95rem;
}

.btn-sm {
    border-radius: 8px;
}

.field-price {
    background-color: #f5c451 !important;
    color: #1f2937 !important;
    font-weight: 600;
}

.field-net {
    background-color: #5dd68a !important;
    color: #ffffff !important;
    font-weight: 600;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.35rem;
}

/* Suggestions */
.suggestion-box,
#customerSuggestions {
    position: absolute;
    z-index: 1000;
    width: 100%;
    background: #fff;
    border: 1px solid var(--app-line);
    border-radius: 10px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: var(--app-shadow);
}

#customerSuggestions {
    display: none;
}

.suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
}

.suggestion-item:hover,
.suggestion-item.active {
    background-color: var(--app-primary-soft);
}

.highlight {
    font-weight: 600;
    color: var(--app-primary);
}

.suggestion-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
}

.suggestion-type,
.suggestion-secondary,
.suggestion-inline-meta {
    font-size: 12px;
    color: #6c757d;
}

.suggestion-type {
    text-align: right;
    white-space: nowrap;
}

.suggestion-broker {
    color: #495057;
    font-weight: 500;
}

.suggestion-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.suggestion-inline-meta {
    white-space: nowrap;
    margin-left: auto;
}

.text-small {
    font-size: 15px;
}

/* Notes */
.note-card {
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    overflow: hidden;
    height: auto;
    box-shadow: var(--app-shadow);
}

.note-card .card-body {
    position: relative;
}

.note-card.is-pending .card-body {
    background: linear-gradient(180deg, #fffaf0 0%, #fff7e6 100%);
    border-left: 4px solid #f59e0b;
}

.note-card.is-done .card-body {
    background: linear-gradient(180deg, #f0fdf4 0%, #e8f8ef 100%);
    border-left: 4px solid #16a34a;
}

.note-card-title {
    font-size: 1.25rem;
    font-weight: 400;
    margin-bottom: 0.25rem;
}

.note-card .card-text {
    margin-bottom: 0.42rem;
}

.note-card .card-actions {
    margin-top: 0.75rem;
    padding-top: 0.7rem;
    border-top: 1px dashed rgba(15, 23, 42, 0.1);
}

.note-actor {
    padding: 0 0.15rem;
    font-size: 0.78rem;
    line-height: 1.4;
}

.note-actor-sep {
    margin: 0 0.15rem;
}

.empty-state {
    background: var(--app-surface);
    border: 1px dashed #cbd5e1;
    border-radius: var(--app-radius);
    color: var(--app-muted);
    padding: 1.25rem;
    text-align: center;
}

/* Tables */
.table-wrap {
    overflow: hidden;
}

.table-wrap .table {
    margin-bottom: 0;
}

.table thead th,
.table .table-dark td {
    font-weight: 500;
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(800px 320px at 20% 0%, rgba(29, 78, 216, 0.16), transparent 55%),
        var(--app-bg);
}

.login-shell {
    width: 100%;
    max-width: 860px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--app-surface);
    border: 1px solid var(--app-line);
    border-radius: 20px;
    box-shadow: var(--app-shadow);
    overflow: hidden;
}

.login-aside {
    background: linear-gradient(180deg, #1e3a8a 0%, #1d4ed8 100%);
    color: #fff;
    padding: 2.4rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.login-aside h2 {
    color: #fff;
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.login-aside p {
    color: rgba(255, 255, 255, 0.82);
    margin: 0;
}

.login-aside-meta {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.72);
}

.login-form {
    padding: 2.2rem 2rem;
}

.login-mark {
    width: 44px;
    height: 44px;
    border-radius: 11px;
    background: #fff;
    color: var(--app-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* Modals */
.modal-content {
    border: 0;
    border-radius: 14px;
    box-shadow: var(--app-shadow);
}

.modal-header {
    border-bottom-color: var(--app-line);
}

/* Motion */
.fade-slide-up {
    align-self: flex-start;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease-out;
}

.fade-slide-up.show {
    opacity: 1;
    transform: translateY(0);
}

.slide-up {
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

.slide-up.show {
    transform: translateY(0);
    opacity: 1;
}

html {
    scroll-behavior: auto !important;
}

@media (max-width: 767.98px) {
    .login-shell {
        grid-template-columns: 1fr;
    }

    .login-aside {
        padding: 1.5rem 1.35rem;
        min-height: auto;
    }

    .app-panel,
    .filter-panel {
        padding: 1rem;
    }

    .page-heading h1,
    .page-heading h2,
    h2 {
        font-size: 1.35rem;
    }
}

/* Dashboard */
.dash-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.9rem;
    margin-bottom: 1.25rem;
}

.dash-summary-card {
    background: var(--app-surface);
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    padding: 1rem 1.15rem;
}

.dash-summary-card .dash-kicker {
    font-size: 0.78rem;
    color: var(--app-muted);
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.dash-summary-card .dash-value {
    font-size: 1.45rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.dash-panel {
    height: 100%;
}

.dash-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.dash-panel-head h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
}

.dash-panel-head p {
    margin: 0.2rem 0 0;
    color: var(--app-muted);
    font-size: 0.82rem;
}

.dash-chart-wrap {
    position: relative;
    height: 230px;
    margin-bottom: 0.75rem;
}

.dash-panel .table-wrap {
    overflow: auto;
}

.dash-panel .table th,
.dash-panel .table td {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
}

.dash-panel .table th:last-child,
.dash-panel .table td:last-child {
    white-space: nowrap;
}

.dash-rank {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 600;
    background: #f1f5f9;
    color: #334155;
}

.dash-rank.is-1 {
    background: #fef3c7;
    color: #b45309;
}

.dash-rank.is-2 {
    background: #e2e8f0;
    color: #475569;
}

.dash-rank.is-3 {
    background: #ffedd5;
    color: #c2410c;
}

.dash-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--app-muted);
}

.dash-type {
    font-size: 0.72rem;
    color: #64748b;
    background: #f8fafc;
    border: 1px solid var(--app-line);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    white-space: nowrap;
}

.dash-empty {
    padding: 1.5rem 0.5rem;
}

.dash-section {
    margin-top: 1.35rem;
}

.dash-section-title {
    font-size: 1.12rem;
    font-weight: 600;
    margin: 0 0 0.85rem;
}

.dash-region-grid,
.dash-broker-grid {
    display: grid;
    gap: 0.9rem;
}

.dash-region-grid {
    grid-template-columns: repeat(4, 1fr);
}

.dash-broker-grid {
    grid-template-columns: repeat(2, 1fr);
}

.dash-stat-value {
    font-size: 1.7rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.dash-stat-unit {
    font-size: 0.82rem;
    color: var(--app-muted);
    font-weight: 500;
}

.dash-mini-list {
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--app-line);
}

.dash-mini-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.86rem;
    padding: 0.18rem 0;
}

.dash-mini-row span:last-child {
    color: var(--app-muted);
    white-space: nowrap;
}

.dash-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}

.dash-split h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--app-muted);
    margin: 0 0 0.45rem;
}

.dash-date-muted {
    color: var(--app-muted);
    font-size: 0.82rem;
    white-space: nowrap;
}

.dash-filter .form-label {
    font-size: 0.82rem;
}

.dash-preset {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.dash-preset .btn {
    padding: 0.28rem 0.7rem;
}

.dash-modal-block + .dash-modal-block {
    margin-top: 1.25rem;
}

.dash-modal-block h6 {
    font-weight: 600;
    margin-bottom: 0.65rem;
}

@media (max-width: 1199.98px) {
    .dash-region-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767.98px) {
    .dash-summary,
    .dash-region-grid,
    .dash-broker-grid,
    .dash-split {
        grid-template-columns: 1fr;
    }

    .dash-chart-wrap {
        height: 210px;
    }
}
