:root {
    --primary-blue: #0b3b79;
    --primary-light: #1262b5;
    --accent-blue: #0ea5a4;
    --bg-color: #f5f7fb;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #667085;
    --border-color: #dfe5ee;
    --success: #079669;
    --warning: #d97706;
    --danger: #dc2626;
    --surface-soft: #f8fafc;
    --surface-strong: #eef5ff;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.08);
    --radius: 8px;
    --font-sans: 'Noto Sans Thai', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-sans);
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--primary-blue);
    color: white;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.brand {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand .logo-icon {
    font-size: 24px;
    color: var(--accent-blue);
}

.nav-menu {
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    padding: 12px 24px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    border-left: 4px solid transparent;
}

.nav-item:hover, .nav-item.active {
    background-color: rgba(255,255,255,0.1);
    color: white;
    border-left-color: var(--accent-blue);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-header {
    height: 70px;
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-color);
    padding: 8px 16px;
    border-radius: 8px;
    width: 300px;
}

.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    padding-left: 8px;
    width: 100%;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.avatar {
    width: 36px;
    height: 36px;
    background-color: var(--primary-light);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.content-area {
    padding: 32px;
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.dashboard-alert-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding: 16px 18px;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    background: #eff6ff;
}

.dashboard-alert-panel h2 {
    margin: 0 0 4px;
    font-size: 18px;
    color: var(--primary-blue);
}

.dashboard-alert-panel p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.5;
}

.dashboard-referral-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding: 16px 18px;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    background: #f0fdf4;
}

.dashboard-referral-card h2 {
    margin: 0 0 4px;
    font-size: 18px;
    color: #047857;
}

.dashboard-referral-card p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.5;
}

.dashboard-referral-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dashboard-referral-actions span {
    padding: 10px 14px;
    border: 1px dashed #10b981;
    border-radius: 8px;
    background: #fff;
    color: #047857;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.onboarding-panel {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.onboarding-step {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
    color: var(--text-muted);
    font-weight: 700;
}

.onboarding-step i {
    color: var(--primary-blue);
}

.onboarding-step.is-done {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #067647;
}

.referral-card {
    display: grid;
    gap: 16px;
    padding: 18px;
    margin-bottom: 18px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

.referral-card h3 {
    margin: 0 0 6px;
    color: var(--text-primary);
}

.referral-card p {
    margin: 0;
    color: var(--text-muted);
}

.referral-code-box {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.referral-code-box span {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px dashed var(--primary-blue);
    background: #eef6ff;
    color: var(--primary-blue);
    font-weight: 800;
    letter-spacing: 0.04em;
}

.referral-summary-grid,
.commission-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.referral-summary-grid > div,
.commission-summary-grid > div {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
}

.referral-summary-grid span,
.commission-summary-grid span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.referral-summary-grid strong,
.commission-summary-grid strong {
    color: var(--text-primary);
    font-size: 20px;
}

.payout-profile-card {
    padding: 18px;
    margin-bottom: 18px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
}

.card-header.compact {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    padding: 0;
    margin-bottom: 14px;
    border: 0;
}

.card-header.compact h3 {
    margin: 0 0 4px;
}

.card-header.compact p {
    margin: 0;
    color: var(--text-muted);
}

.payout-profile-form .form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    color: var(--text-secondary);
}

.payout-profile-form input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.payout-profile-note {
    margin: 10px 0 14px;
    color: var(--text-muted);
    font-size: 13px;
}

.admin-action-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.admin-action-row input,
.admin-action-row select {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.admin-payment-box {
    display: grid;
    gap: 6px;
    min-width: 190px;
}

.admin-payment-box input,
.admin-payment-box select {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.admin-referral-note {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
}

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-icon.blue { background-color: #e0f2fe; color: #0284c7; }
.stat-icon.green { background-color: #dcfce7; color: #16a34a; }
.stat-icon.purple { background-color: #f3e8ff; color: #9333ea; }
.stat-icon.red { background-color: #fee2e2; color: #dc2626; }
.stat-icon.amber { background-color: #fef3c7; color: #d97706; }

.stat-info h3 {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-info p {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

/* Tables */
.card-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.btn-primary {
    background-color: var(--primary-blue);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: var(--primary-light);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f9fafb;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}

.status-active { background-color: #dcfce7; color: #166534; }
.status-inactive { background-color: #fee2e2; color: #991b1b; }
.status-warning { background-color: #fef3c7; color: #92400e; }
.status-neutral { background-color: #e5e7eb; color: #374151; }
.policy-status-badge {
    display: inline-block;
    max-width: 260px;
    white-space: normal;
    line-height: 1.35;
    border-radius: 8px;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    overflow: auto;
}

.modal-content {
    background-color: #fff;
    margin: 3vh auto;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 96vw;
    max-width: 1120px;
    position: relative;
    animation: modalFadeIn 0.3s;
}

@keyframes modalFadeIn {
    from {opacity: 0; transform: translateY(-20px);}
    to {opacity: 1; transform: translateY(0);}
}

.close-modal {
    position: absolute;
    top: 16px;
    right: 24px;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover {
    color: #333;
}

.modal-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
}

.modal-body {
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.customer-info-card {
    background: #f9fafb;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.customer-info-card h3, .policies-section h3 {
    margin-bottom: 16px;
    font-size: 16px;
    color: var(--primary-blue);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary-blue);
}

.table-responsive {
    overflow-x: auto;
}

.admin-create-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
    padding: 16px;
    background: #f9fafb;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.admin-create-grid input,
.admin-create-grid select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    min-width: 0;
}

.page-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title-row h1 {
    font-size: 24px;
    margin-bottom: 6px;
}

.page-title-row p {
    color: var(--text-muted);
}

.inline-search,
.renewal-stage-select,
.quote-status-select {
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
}

.action-icon-btn {
    display: inline-flex;
    padding: 6px 9px;
    font-size: 12px;
    margin-right: 4px;
    background: #e5e7eb;
    color: #374151;
    border: none;
    border-radius: 4px;
    text-decoration: none;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 18px;
}

.empty-state.compact {
    padding: 8px;
    font-size: 12px;
}

.error-state {
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #fecaca;
}

.kanban-board {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.renewal-action-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: center;
    padding: 18px 20px;
    margin-bottom: 14px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-blue);
    border-radius: 8px;
}

.renewal-action-panel strong {
    display: block;
    margin-bottom: 6px;
    color: var(--primary-blue);
}

.renewal-action-panel p {
    color: #374151;
    line-height: 1.6;
}

.renewal-action-premium {
    min-width: 210px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.renewal-action-premium span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.renewal-action-premium strong {
    margin: 0;
    font-size: 20px;
    color: #166534;
}

.renewal-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.renewal-summary-grid div {
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.renewal-summary-grid span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.renewal-summary-grid strong {
    font-size: 22px;
    color: #111827;
}

.renewal-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.renewal-list-header span {
    color: var(--text-muted);
    font-size: 13px;
}

.renewal-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 0 0 14px;
}

.renewal-filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.renewal-filter-btn {
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: #374151;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.renewal-filter-btn.active {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
    color: #fff;
}

.reports-chart-grid {
    display: grid;
    grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
    gap: 18px;
    margin-bottom: 24px;
}

.report-chart-card .card-header {
    display: block;
}

.report-chart-card .card-header h2 {
    margin-bottom: 4px;
}

.report-chart-card .card-header p {
    color: var(--text-muted);
    font-size: 13px;
}

.report-chart-wrap {
    position: relative;
    width: 100%;
    min-height: 320px;
}

.report-chart-wrap.pie {
    max-width: 420px;
    margin: 0 auto;
}

.fallback-pie-chart {
    width: min(280px, 85%);
    aspect-ratio: 1;
    margin: 22px auto 8px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.8);
}

.fallback-pie-chart::after {
    content: "";
    display: block;
    width: 44%;
    height: 44%;
    margin: 28%;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px var(--border-color);
}

.fallback-bar-chart {
    display: grid;
    gap: 18px;
    padding: 28px 8px 12px;
}

.fallback-bar-row {
    display: grid;
    grid-template-columns: 52px minmax(120px, 1fr) 42px;
    gap: 10px;
    align-items: center;
}

.fallback-bar-row span,
.fallback-bar-row strong {
    font-size: 13px;
    color: #374151;
}

.fallback-bar-row strong {
    text-align: right;
}

.fallback-bar-row div {
    height: 28px;
    background: #f1f5f9;
    border-radius: 6px;
    overflow: hidden;
}

.fallback-bar-row i {
    display: block;
    height: 100%;
    border-radius: 6px;
}

.report-chart-breakdown {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 14px;
}

.report-chart-breakdown div {
    padding: 10px;
    background: #f9fafb;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.report-chart-breakdown span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.report-chart-breakdown strong {
    color: #111827;
    font-size: 18px;
}

@media (max-width: 1100px) {
    .reports-chart-grid {
        grid-template-columns: 1fr;
    }
}

.kanban-column {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    min-height: 120px;
}

.kanban-column h3 {
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.mini-card {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
}

.mini-card span,
.mini-card small {
    color: var(--text-muted);
}

.customer-command-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    border: 1px solid var(--border-color);
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.customer-command-bar p {
    color: var(--text-muted);
    margin-top: 4px;
}

.customer-command-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.compact-stats {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.timeline-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.timeline-item {
    display: grid;
    grid-template-columns: 16px 1fr;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
}

.timeline-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-blue);
    margin-top: 5px;
}

.timeline-item span,
.timeline-item small {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 3px;
}

.timeline-item p {
    margin-top: 6px;
    line-height: 1.5;
}

.broker-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.broker-panel {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    min-width: 0;
}

.compact-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin: 12px 0 16px;
}

.compact-form input,
.compact-form select,
.lead-stage-select {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
}

.searchable-select {
    position: relative;
    width: 100%;
    min-width: 0;
}

.searchable-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-height: 1px !important;
    padding: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.searchable-select-input {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 8px 34px 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    color: var(--text-main);
    outline: none;
    font-size: 14px;
}

.searchable-select::after {
    content: '\f002';
    position: absolute;
    top: 12px;
    right: 12px;
    color: var(--text-muted);
    font: var(--fa-font-solid);
    font-size: 12px;
    pointer-events: none;
}

.searchable-select-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.14);
}

.searchable-select-menu {
    position: absolute;
    z-index: 1200;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-md);
}

.searchable-select-option {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    background: #fff;
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.35;
}

.searchable-select-option:hover,
.searchable-select-option.is-selected {
    background: #eaf4ff;
    color: var(--primary-blue);
}

.searchable-select-empty,
.searchable-select-hint {
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 13px;
}

.searchable-select-hint {
    border-top: 1px solid var(--border-color);
    background: #f8fafc;
}

.import-panel {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
}

.import-panel input[type="file"] {
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius);
    background: #fff;
}

.import-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.import-result {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    background: #fff;
}

.import-rollback-card {
    margin-top: 18px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    background: #fff;
}

.import-rollback-note {
    margin: 12px 0 4px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #ecfdf3;
    color: #067647;
    font-size: 14px;
}

.import-error {
    border-color: #fecaca;
    background: #fff1f1;
    color: #991b1b;
}

.import-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.import-summary-grid > div {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px;
    background: #f8fafc;
}

.import-summary-grid span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.import-summary-grid strong {
    font-size: 20px;
}

.import-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 12px;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-list span {
    display: inline-flex;
    padding: 5px 8px;
    border-radius: 999px;
    background: #eaf4ff;
    color: var(--primary-blue);
    font-size: 12px;
    font-weight: 700;
}

.import-message-list {
    margin-left: 18px;
    color: var(--text-muted);
    line-height: 1.7;
}

.notification-preview-box {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px;
    background: #fff;
}

.notification-preview-box pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: var(--font-sans);
    line-height: 1.6;
    color: var(--text-main);
}

.capacity-box {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
    color: var(--text-muted);
    line-height: 1.7;
}

@media (max-width: 760px) {
    .import-panel,
    .import-detail-grid {
        grid-template-columns: 1fr;
    }

    .import-actions {
        width: 100%;
    }

    .import-actions .btn-primary,
    .import-actions .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        width: 100%;
    }
    .nav-menu {
        padding: 12px;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .top-header,
    .page-title-row,
    .customer-command-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .search-bar {
        width: 100%;
    }
    .content-area {
        padding: 16px;
    }
    .broker-grid {
        grid-template-columns: 1fr;
    }
}

/* Tabs */
.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-top: 4px;
    margin-bottom: 16px;
    overflow-x: auto;
}
.tab-btn {
    background: none;
    border: none;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.tab-btn:hover {
    color: var(--primary-blue);
}
.tab-btn.active {
    color: var(--primary-blue);
    border-bottom-color: var(--primary-blue);
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* Presentation-ready UI refresh */
html {
    background: var(--bg-color);
}

body {
    min-height: 100vh;
    line-height: 1.5;
    text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

.app-container {
    background:
        linear-gradient(180deg, rgba(14, 165, 164, 0.05), rgba(14, 165, 164, 0) 280px),
        var(--bg-color);
}

.sidebar {
    width: 268px;
    background: linear-gradient(180deg, #0b3b79 0%, #082d5d 100%);
    box-shadow: 1px 0 0 rgba(255, 255, 255, 0.08) inset, 10px 0 28px rgba(15, 23, 42, 0.12);
}

.brand {
    min-height: 78px;
    padding: 20px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand .logo-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    background: rgba(14, 165, 164, 0.16);
    color: #7dd3d0;
    box-shadow: inset 0 0 0 1px rgba(125, 211, 208, 0.28);
}

.brand h2 {
    font-size: 20px;
    line-height: 1.1;
    font-weight: 700;
}

.nav-menu {
    padding: 18px 12px;
    gap: 4px;
}

.nav-item {
    min-height: 44px;
    padding: 11px 12px;
    border-left: 0;
    border-radius: var(--radius);
    color: rgba(255, 255, 255, 0.78);
    font-size: 14px;
    font-weight: 600;
}

.nav-item i {
    width: 22px;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    box-shadow: inset 3px 0 0 #2dd4bf;
}

.nav-item:hover i,
.nav-item.active i {
    color: #b7f1ef;
}

.main-content {
    background: transparent;
}

.top-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: 72px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(223, 229, 238, 0.9);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
}

.search-bar {
    min-height: 42px;
    width: min(430px, 44vw);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--text-muted);
}

.search-bar input {
    color: var(--text-main);
    font-size: 14px;
}

.search-bar:focus-within {
    border-color: rgba(14, 165, 164, 0.65);
    box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.12);
}

.user-profile {
    color: var(--text-main);
}

.avatar {
    background: linear-gradient(135deg, var(--primary-blue), var(--accent-blue));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

#agent-profile-name {
    display: block;
    max-width: 220px;
    line-height: 1.25;
    color: var(--text-main);
}

#btn-logout {
    min-height: 38px;
    padding: 8px 13px !important;
    border-radius: var(--radius) !important;
    background: #b91c1c !important;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}

.content-area {
    width: 100%;
    max-width: 1540px;
    margin: 0 auto;
    padding: 30px 32px 44px;
}

.page-title-row {
    align-items: center;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(223, 229, 238, 0.8);
}

.page-title-row h1 {
    font-size: clamp(25px, 2vw, 34px);
    line-height: 1.15;
    color: #111827;
    font-weight: 800;
}

.page-title-row p {
    max-width: 760px;
    font-size: 14px;
}

.stats-grid {
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card,
.card-section,
.broker-panel,
.customer-info-card,
.timeline-item,
.admin-create-grid,
.renewal-action-panel,
.renewal-summary-grid div,
.renewal-action-premium,
.report-chart-breakdown div,
.fallback-bar-row div,
.customer-command-bar,
.kanban-column,
.mini-card {
    border-radius: var(--radius);
}

.stat-card,
.card-section,
.broker-panel {
    border: 1px solid rgba(223, 229, 238, 0.95);
    box-shadow: var(--shadow-sm);
}

.stat-card {
    min-height: 116px;
    padding: 20px;
    align-items: flex-start;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
}

.stat-icon.blue { background-color: #e9f4ff; color: #0b5cad; }
.stat-icon.green { background-color: #e7f8f0; color: #047857; }
.stat-icon.purple { background-color: #f2efff; color: #6d28d9; }
.stat-icon.red { background-color: #feecec; color: #b91c1c; }
.stat-icon.amber { background-color: #fff6df; color: #b45309; }

.stat-info h3 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-info p,
.stat-value {
    font-size: clamp(22px, 2vw, 30px);
    line-height: 1.15;
}

.card-section {
    padding: 22px;
}

.card-header {
    gap: 12px;
    margin-bottom: 18px;
}

.card-header h2,
.broker-panel h3,
.customer-info-card h3,
.policies-section h3 {
    color: #111827;
    font-size: 18px;
    font-weight: 800;
}

.btn-primary,
.btn-secondary,
.action-icon-btn,
.renewal-filter-btn,
button[type="submit"] {
    min-height: 38px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 700;
    box-shadow: none;
}

.btn-primary,
button[type="submit"] {
    background: var(--primary-blue);
    color: #fff;
    border: 1px solid var(--primary-blue);
}

.btn-primary:hover,
button[type="submit"]:hover {
    background: var(--primary-light);
    border-color: var(--primary-light);
}

.btn-secondary,
.action-icon-btn {
    border: 1px solid var(--border-color) !important;
    background: #fff !important;
    color: #344054 !important;
}

.btn-secondary:hover,
.action-icon-btn:hover {
    border-color: #bdc8d8 !important;
    background: var(--surface-soft) !important;
}

.btn-done-renewal {
    background: #067647 !important;
    border-color: #067647 !important;
}

.btn-cancel-renewal {
    background: #fff1f1 !important;
    border: 1px solid #fecaca !important;
    color: #991b1b !important;
}

table {
    border-collapse: separate;
    border-spacing: 0;
}

th,
td {
    padding: 14px 16px;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    color: #667085;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

tbody tr {
    transition: background-color 0.16s ease;
}

tbody tr:hover {
    background: #fbfdff;
}

td {
    color: #344054;
}

.table-responsive {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.table-responsive table th:first-child {
    border-top-left-radius: var(--radius);
}

.table-responsive table th:last-child {
    border-top-right-radius: var(--radius);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.status-active { background-color: #e7f8f0; color: #047857; }
.status-inactive { background-color: #fff1f1; color: #b42318; }
.status-warning { background-color: #fff7e6; color: #b54708; }
.status-neutral { background-color: #f2f4f7; color: #475467; }

.policy-status-badge {
    border-radius: var(--radius);
    font-weight: 700;
}

.inline-search,
.renewal-stage-select,
.quote-status-select,
.compact-form input,
.compact-form select,
.lead-stage-select,
.admin-create-grid input,
.admin-create-grid select,
.form-group input,
.form-group select,
.form-group textarea,
input,
select,
textarea {
    min-height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text-main);
    outline: none;
}

textarea {
    min-height: 92px;
    padding: 10px 12px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.inline-search:focus,
.renewal-stage-select:focus,
.quote-status-select:focus {
    border-color: rgba(14, 165, 164, 0.7);
    box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.12);
}

.form-group label {
    color: #475467;
    font-weight: 800;
}

.modal {
    background-color: rgba(15, 23, 42, 0.56);
}

.modal-content {
    border-radius: var(--radius);
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.24);
    border: 1px solid rgba(255, 255, 255, 0.55);
    overflow: hidden;
}

.modal-header {
    background: #fff;
    padding: 22px 28px;
}

.modal-header h2 {
    font-size: clamp(24px, 2vw, 34px);
    line-height: 1.15;
}

.modal-body {
    background: #fbfcfe;
    padding: 26px 28px;
}

.close-modal {
    top: 18px;
    right: 22px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    color: #667085;
    background: #f2f4f7;
    font-size: 22px;
}

.close-modal:hover {
    color: #111827;
    background: #e5e7eb;
}

.modal-tabs {
    gap: 4px;
    padding-bottom: 0;
}

.tab-btn {
    border-radius: var(--radius) var(--radius) 0 0;
    font-weight: 800;
}

.tab-btn.active {
    background: #eef5ff;
}

.renewal-action-panel {
    background: linear-gradient(90deg, #f0fdfa, #f8fafc);
    border-left-color: var(--accent-blue);
}

.renewal-action-panel strong {
    color: #0f766e;
}

.renewal-summary-grid div {
    box-shadow: var(--shadow-sm);
}

.renewal-filter-btn {
    padding: 8px 12px;
}

.renewal-filter-btn.active {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
}

.renewal-toolbar {
    align-items: flex-start;
}

.customer-command-bar,
.admin-create-grid,
.capacity-box,
.customer-info-card {
    background: var(--surface-soft);
}

.report-chart-wrap {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: #fff;
    padding: 12px;
}

@media (max-width: 980px) {
    .top-header {
        position: static;
        display: flex;
        height: 72px;
        min-height: 72px;
        padding: 14px 18px;
        gap: 12px;
        align-items: stretch;
        justify-content: flex-end;
    }

    .search-bar {
        display: none;
    }

    .user-profile {
        justify-content: flex-end;
        margin-left: auto;
    }

    .content-area {
        padding: 24px 18px 36px;
    }

    .renewal-toolbar {
        flex-direction: column;
    }

    .inline-search {
        width: 100%;
    }
}

@media (max-width: 760px) {
    .sidebar {
        box-shadow: none;
    }

    .brand {
        min-height: 66px;
        padding: 14px 16px;
    }

    .nav-menu {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .nav-item {
        min-height: 40px;
        padding: 9px 10px;
    }

    .page-title-row {
        align-items: stretch;
    }

    .stats-grid,
    .renewal-summary-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-alert-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard-alert-panel .btn-secondary {
        justify-content: center;
        width: 100%;
    }

    .dashboard-referral-card {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard-referral-actions,
    .dashboard-referral-actions .btn-primary {
        justify-content: center;
        width: 100%;
    }

    .onboarding-panel {
        grid-template-columns: 1fr;
    }

    .card-section {
        padding: 16px;
    }

    .modal-content {
        width: 100vw;
        margin: 0;
        min-height: 100vh;
        border-radius: 0;
    }

    .modal-header,
    .modal-body {
        padding: 18px;
    }

    th,
    td {
        padding: 12px;
    }
}

/* Thai SaaS table and modal polish */
body {
    font-family: var(--font-sans);
    font-size: 14px;
    color: #1d2939;
}

.content-area {
    max-width: 1600px;
}

.page-title-row {
    margin-bottom: 26px;
}

.page-title-row h1 {
    font-size: clamp(28px, 2.1vw, 38px);
    letter-spacing: 0;
}

.page-title-row p {
    font-size: 14px;
    line-height: 1.65;
}

.card-section {
    border-radius: 8px;
    padding: 22px;
}

.data-table {
    min-width: 980px;
    table-layout: auto;
}

.data-table th,
.data-table td,
#customer-modal table th,
#customer-modal table td {
    padding: 11px 14px;
    font-size: 14px;
    line-height: 1.45;
}

.data-table th,
#customer-modal table th {
    font-size: 11.5px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.data-table tbody tr:nth-child(even),
#customer-modal table tbody tr:nth-child(even) {
    background: #fcfdff;
}

.data-table tbody tr:hover,
#customer-modal table tbody tr:hover {
    background: #f7fbff;
}

.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow: auto;
    background: #fff;
}

.table-subtext {
    display: block;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.35;
}

.policy-number-cell {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    color: #24314a;
}

.money-cell {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: #24314a;
}

.status-badge {
    min-height: 24px;
    padding: 4px 9px;
    font-size: 12px;
    line-height: 1.25;
    letter-spacing: 0;
}

.policy-status-badge {
    display: inline-block;
    max-width: 230px;
    min-height: 0;
    padding: 6px 9px;
    white-space: normal;
    line-height: 1.35;
    text-align: left;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.table-actions .btn-primary,
.table-actions .btn-secondary,
.table-actions .action-icon-btn,
.renewal-actions .btn-primary,
.renewal-actions .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 10px !important;
    border-radius: 7px !important;
    font-size: 12px !important;
    line-height: 1.1;
    white-space: nowrap;
}

.action-icon-btn {
    width: 34px;
    min-width: 34px;
    margin-right: 0;
}

.renewals-table {
    min-width: 1220px;
}

.renewals-table th:nth-child(1),
.renewals-table td:nth-child(1) {
    width: 105px;
}

.renewals-table th:nth-child(2),
.renewals-table td:nth-child(2) {
    width: 190px;
}

.renewals-table th:nth-child(3),
.renewals-table td:nth-child(3) {
    width: 135px;
}

.renewals-table th:nth-child(4),
.renewals-table td:nth-child(4) {
    width: 168px;
}

.renewals-table th:nth-child(8),
.renewals-table td:nth-child(8) {
    width: 172px;
}

.renewals-table th:nth-child(10),
.renewals-table td:nth-child(10) {
    width: 220px;
}

.renewal-stage-select {
    width: 100%;
    min-width: 145px;
    max-width: 172px;
    min-height: 36px;
    padding: 7px 32px 7px 10px;
    font-size: 13px;
    font-weight: 600;
}

.renewal-actions {
    min-width: 178px;
    max-width: 220px;
}

.btn-done-renewal {
    background: #087443 !important;
    border-color: #087443 !important;
    color: #fff !important;
}

.btn-cancel-renewal {
    background: #fff5f5 !important;
    border: 1px solid #fecaca !important;
    color: #a11212 !important;
}

.policies-table {
    min-width: 1900px;
}

.policies-table th:nth-child(1),
.policies-table td:nth-child(1) {
    width: 140px;
}

.policies-table th:nth-child(2),
.policies-table td:nth-child(2) {
    width: 190px;
}

.policies-table th:nth-child(3),
.policies-table td:nth-child(3) {
    width: 130px;
}

.policies-table th:nth-child(4),
.policies-table td:nth-child(4) {
    width: 160px;
}

.policies-table th:nth-child(7),
.policies-table td:nth-child(7) {
    width: 230px;
}

.policies-table th:nth-child(9),
.policies-table td:nth-child(9),
.policies-table th:nth-child(10),
.policies-table td:nth-child(10),
.policies-table th:nth-child(13),
.policies-table td:nth-child(13),
.policies-table th:nth-child(14),
.policies-table td:nth-child(14) {
    white-space: nowrap;
}

.policies-table th:nth-child(15),
.policies-table td:nth-child(15) {
    width: 280px;
}

.actions-table {
    min-width: 980px;
}

.actions-table th:nth-child(6),
.actions-table td:nth-child(6) {
    width: 230px;
}

.inline-search {
    min-width: min(360px, 100%);
    min-height: 42px;
    padding: 9px 12px;
    font-size: 14px;
}

#customer-modal .modal-content {
    width: 96vw;
    max-width: 1280px;
    margin: 2vh auto;
}

#customer-modal .modal-header {
    min-height: 86px;
    padding: 18px 86px 18px 28px;
    gap: 16px;
}

#customer-modal .modal-header > div:first-child {
    min-width: 0;
}

#modal-customer-name {
    max-width: min(760px, 52vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(28px, 2.2vw, 38px);
    line-height: 1.15;
}

#modal-customer-status {
    vertical-align: middle;
}

#customer-modal .modal-header > div:last-child {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

#btn-ai-insights,
#btn-delete-customer {
    min-height: 42px;
    padding: 9px 15px !important;
    font-size: 14px;
    white-space: nowrap;
}

#btn-delete-customer {
    background: #fff !important;
    border: 1px solid #fecaca !important;
    color: #991b1b !important;
}

#customer-modal .close-modal {
    top: 20px;
    right: 22px;
    z-index: 3;
}

#customer-modal .modal-body {
    padding: 24px 28px 28px;
    gap: 16px;
}

#customer-modal .modal-tabs {
    gap: 2px;
    margin-bottom: 18px;
}

#customer-modal .tab-btn {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.2;
}

.customer-command-bar {
    align-items: center;
    padding: 14px 16px;
    gap: 14px;
}

.customer-command-bar h3 {
    font-size: 18px;
    line-height: 1.3;
    margin-bottom: 4px;
}

.customer-command-bar p {
    font-size: 13px;
    line-height: 1.45;
}

.customer-command-actions .btn-primary,
.customer-command-actions .btn-secondary {
    min-height: 38px;
    padding: 8px 12px !important;
    font-size: 13px;
    white-space: nowrap;
}

.compact-stats {
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.compact-stats .stat-card {
    display: block;
    min-width: 0;
    min-height: 92px;
    padding: 14px;
}

.compact-stats .stat-info h3 {
    margin-bottom: 8px;
    font-size: 11.5px;
    line-height: 1.25;
}

.compact-stats .stat-value {
    max-width: 100%;
    font-size: clamp(20px, 1.4vw, 26px);
    overflow-wrap: anywhere;
    word-break: normal;
    font-variant-numeric: tabular-nums;
}

#customer-modal .table-responsive {
    border-radius: 8px;
}

#customer-modal table {
    min-width: 880px;
}

#modal-policies-table {
    min-width: 1820px;
}

#modal-policies-table th,
#modal-policies-table td,
#customer-renewals-table th,
#customer-renewals-table td,
#customer-quotes-table th,
#customer-quotes-table td,
#modal-medical-table th,
#modal-medical-table td,
#modal-docs-table th,
#modal-docs-table td,
#modal-calls-table th,
#modal-calls-table td {
    font-size: 13px;
    padding: 10px 12px;
}

@media (max-width: 980px) {
    #customer-modal .modal-header {
        align-items: flex-start;
        padding-right: 72px;
    }

    #modal-customer-name {
        max-width: 100%;
        white-space: normal;
    }

    .customer-command-bar {
        align-items: stretch;
    }
}

@media (max-width: 760px) {
    .data-table th,
    .data-table td,
    #customer-modal table th,
    #customer-modal table td {
        padding: 10px 11px;
        font-size: 13px;
    }

    .page-title-row h1 {
        font-size: 28px;
    }

    #customer-modal .modal-header {
        padding: 18px 66px 16px 18px;
    }

    #modal-customer-name {
        font-size: 27px;
    }

    .compact-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
