/* --------------------------------------------------
 * CSS Reset & Theme Variables
 * -------------------------------------------------- */
:root {
    /* Fonts */
    --font-main: 'Inter', 'Noto Sans Thai', sans-serif;

    /* Light Theme (Default) */
    --bg-app: #f4f6fc;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --border-color: rgba(226, 232, 240, 0.8);
    
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-white: #ffffff;

    --primary: #4f46e5;
    --primary-light: #e0e7ff;
    --primary-dark: #3730a3;

    --success: #10b981;
    --success-light: #d1fae5;
    --success-dark: #065f46;

    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --warning-dark: #92400e;

    --danger: #ef4444;
    --danger-light: #fee2e2;

    --info: #0ea5e9;
    --info-light: #e0f2fe;
    
    /* Business Colors */
    --seller-color: #0d9488; /* Teal */
    --seller-light: rgba(13, 148, 136, 0.04);
    --seller-accent: rgba(13, 148, 136, 0.2);
    --customer-color: #8b5cf6; /* Purple */
    --customer-light: rgba(139, 92, 246, 0.04);
    --customer-accent: rgba(139, 92, 246, 0.2);

    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.02);
    --shadow-hover: 0 20px 40px -15px rgba(0, 0, 0, 0.1), 0 1px 10px rgba(0, 0, 0, 0.05);
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --backdrop-blur: blur(16px);
}

/* Dark Theme overrides */
[data-theme="dark"] {
    --bg-app: #0b0f19;
    --bg-card: rgba(20, 27, 45, 0.7);
    --bg-card-hover: rgba(26, 36, 60, 0.85);
    --border-color: rgba(255, 255, 255, 0.08);

    --text-main: #f1f5f9;
    --text-muted: #94a3b8;

    --primary: #6366f1;
    --primary-light: rgba(99, 102, 241, 0.15);
    --primary-dark: #4f46e5;

    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.15);
    --success-dark: #059669;

    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.15);
    --warning-dark: #d97706;

    --danger: #f87171;
    --danger-light: rgba(248, 113, 113, 0.15);

    --info: #38bdf8;
    --info-light: rgba(56, 189, 248, 0.15);

    --seller-color: #14b8a6;
    --seller-light: rgba(20, 184, 166, 0.05);
    --seller-accent: rgba(20, 184, 166, 0.2);
    --customer-color: #a78bfa;
    --customer-light: rgba(167, 139, 250, 0.05);
    --customer-accent: rgba(167, 139, 250, 0.2);

    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 20px 40px -15px rgba(0, 0, 0, 0.5), 0 1px 10px rgba(0, 0, 0, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-app);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    background-image: 
        radial-gradient(at 0% 0%, var(--primary-light) 0px, transparent 50%),
        radial-gradient(at 100% 100%, var(--seller-light) 0px, transparent 50%);
    background-attachment: fixed;
}

/* --------------------------------------------------
 * Typography & General Utilities
 * -------------------------------------------------- */
h1, h2, h3, h4 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

p {
    line-height: 1.6;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-seller { color: var(--seller-color) !important; }
.text-customer { color: var(--customer-color) !important; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background-color: var(--primary);
    color: var(--text-white);
}
.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1.05rem;
}

.btn-secondary {
    background-color: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-main);
}
.btn-secondary:hover {
    background-color: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.btn-danger {
    background-color: var(--danger);
    color: var(--text-white);
}
.btn-danger:hover {
    background-color: #b91c1c;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    padding: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.btn-icon:hover {
    background-color: var(--primary-light);
    color: var(--primary);
    transform: scale(1.05);
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 4px 8px;
    font-size: 0.85rem;
}
.btn-link:hover {
    color: var(--primary);
    text-decoration: underline;
}

.btn-label {
    cursor: pointer;
}

.btn-seller {
    background-color: var(--seller-color);
    color: var(--text-white);
}
.btn-seller:hover {
    background-color: #0b7a70;
}

.btn-customer {
    background-color: var(--customer-color);
    color: var(--text-white);
}
.btn-customer:hover {
    background-color: #7c3aed;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 20px;
    background-color: var(--primary-light);
    color: var(--primary);
}

/* Cards (Base) */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-hover);
    background-color: var(--bg-card-hover);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.border-primary {
    border-bottom: 2px solid var(--primary);
}

.card-header h2, .card-header h3 {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon {
    font-size: 1.4rem;
    color: var(--primary);
}

/* --------------------------------------------------
 * App Header
 * -------------------------------------------------- */
.app-header {
    background-color: rgba(255, 255, 255, 0.4);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

[data-theme="dark"] .app-header {
    background-color: rgba(11, 15, 25, 0.4);
}

.header-container {
    max-width: 1500px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 2.2rem;
    color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--seller-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo h1 {
    font-size: 1.4rem;
    color: var(--text-main);
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.backup-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --------------------------------------------------
 * App Grid Layout
 * -------------------------------------------------- */
.app-container {
    max-width: 1500px;
    width: 100%;
    margin: 0 auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    flex-grow: 1;
}

/* --------------------------------------------------
 * 1. Dashboard Section
 * -------------------------------------------------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    padding: 24px;
}

.status-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    border-radius: var(--radius-md);
    background-color: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .status-card {
    background-color: rgba(255, 255, 255, 0.03);
}

.status-card .card-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    flex-shrink: 0;
}

.status-card .card-content {
    flex-grow: 1;
}

.status-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.status-card .value-group {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 4px;
}

.status-card .main-val {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.status-card .unit {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.status-card .card-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Dashboard Color Themes */
.status-card.info .card-icon {
    background-color: var(--info-light);
    color: var(--info);
}
.status-card.primary .card-icon {
    background-color: var(--primary-light);
    color: var(--primary);
}
.status-card.success .card-icon {
    background-color: var(--success-light);
    color: var(--success);
}
.status-card.warning .card-icon {
    background-color: var(--warning-light);
    color: var(--warning);
}

/* Progress bar section */
.progress-section {
    padding: 0 24px 24px 24px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.progress-percent {
    color: var(--success);
}

.progress-bar-bg {
    height: 12px;
    background-color: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 6px;
    width: 0%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --------------------------------------------------
 * 3. Unified Form Section
 * -------------------------------------------------- */
.entry-form {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.form-split-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.form-side-column {
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border-color);
}

.seller-column-bg {
    background-color: var(--seller-light);
    border-color: var(--seller-accent);
}

.customer-column-bg {
    background-color: var(--customer-light);
    border-color: var(--customer-accent);
}

.form-side-title {
    font-size: 1.05rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-col label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.calc-label {
    font-size: 0.72rem;
    color: var(--primary);
    font-weight: 500;
    font-style: italic;
}

.form-col input {
    height: 42px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-main);
    padding: 8px 14px;
    font-family: var(--font-main);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.form-col input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Readonly auto calculated input styling */
.form-col input.readonly-input {
    background-color: rgba(0, 0, 0, 0.03);
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    font-weight: 600;
}

[data-theme="dark"] .form-col input.readonly-input {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Custom Checkbox Design */
.checkbox-col {
    justify-content: flex-end;
    padding-bottom: 8px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 32px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    user-select: none;
    height: 42px;
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 22px;
    width: 22px;
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    transition: var(--transition);
}

.checkbox-container:hover input ~ .checkmark {
    border-color: var(--primary);
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--primary);
    border-color: var(--primary);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 7px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
}

/* Highlight checkboxes */
.checkmark.mark-seller {
    border-color: var(--seller-accent);
}
.checkbox-container input:checked ~ .checkmark.mark-seller {
    background-color: var(--seller-color);
    border-color: var(--seller-color);
}

.checkmark.mark-customer {
    border-color: var(--customer-accent);
}
.checkbox-container input:checked ~ .checkmark.mark-customer {
    background-color: var(--customer-color);
    border-color: var(--customer-color);
}

.form-actions-row {
    display: flex;
    justify-content: center;
}

.form-actions-row button {
    min-width: 320px;
}

/* --------------------------------------------------
 * Active Filter Banner (On main page)
 * -------------------------------------------------- */
.filter-status-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background-color: var(--warning-light);
    border: 1px solid var(--warning);
    border-radius: var(--radius-md);
    color: var(--warning-dark);
    font-size: 0.95rem;
    font-weight: 500;
}

[data-theme="dark"] .filter-status-banner {
    background-color: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.banner-icon {
    font-size: 1.1rem;
}

/* --------------------------------------------------
 * 4. Combined Table Layout
 * -------------------------------------------------- */
.table-full-section {
    width: 100%;
}

.table-scroll-wrapper {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* Large Combined Table Style */
.data-table-large {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
    min-width: 1200px; /* บังคับหน้ากว้างขั้นต่ำของตารางคู่เพื่อไม่ให้บีบกัน */
}

/* Multi-level Headers */
.data-table-large th {
    padding: 10px 14px;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-super-headers th {
    font-size: 1rem;
    text-align: center;
    color: var(--text-white);
    padding: 12px 14px;
    top: 0; /* Sticky top level */
}

.super-header-seller {
    background-color: var(--seller-color);
}

.super-header-customer {
    background-color: var(--customer-color);
}

.super-header-actions {
    background-color: #475569;
}

.table-sub-headers th {
    background-color: var(--bg-card);
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    top: 45px; /* Offset sticky header level 2 */
    z-index: 9;
}

/* Cell borders and highlighting */
.data-table-large td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    transition: var(--transition);
}

.data-table-large tbody tr {
    cursor: pointer;
}

/* Fading text effect for fully completed jobs */
.job-completed td {
    opacity: 0.45;
    text-decoration: none;
}

/* Completed Row Background overrides */
.data-table-large tbody tr.job-completed {
    background-color: rgba(241, 245, 249, 0.4);
}

[data-theme="dark"] .data-table-large tbody tr.job-completed {
    background-color: rgba(255, 255, 255, 0.015);
}

/* Recover readability on hover for completed rows */
.data-table-large tbody tr.job-completed:hover td {
    opacity: 0.85;
}

.data-table-large tbody tr:hover td {
    background-color: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] .data-table-large tbody tr:hover td {
    background-color: rgba(255, 255, 255, 0.025);
}

/* Vertical separating line between purchase & sales */
.table-super-headers th.super-header-seller {
    border-right: 3px solid rgba(255, 255, 255, 0.3);
}

.data-table-large th:nth-child(4) {
    border-right: 3px solid var(--border-color);
}

.data-table-large td:nth-child(4) {
    border-right: 3px solid var(--border-color);
}

/* Highlights depending on job payment status */
.job-pending {
    background-color: rgba(245, 158, 11, 0.01);
}

/* Overdue Warning style on date cell */
.overdue-warning-text {
    color: var(--danger) !important;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Col styling */
.col-price {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
}

.cell-seller-color {
    background-color: rgba(13, 148, 136, 0.015);
}

.cell-customer-color {
    background-color: rgba(139, 92, 246, 0.015);
}

/* Checkbox and icon styles inside tables */
.table-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.row-actions-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.row-actions-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    transform: scale(1.1);
}

/* Empty row text style */
.empty-row {
    color: var(--text-muted);
    padding: 60px !important;
    font-style: italic;
}

/* --------------------------------------------------
 * Modal Design
 * -------------------------------------------------- */
.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(5px);
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    width: 100%;
    max-width: 550px;
    margin: 20px;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
}

.modal-large {
    max-width: 950px;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}

.close-modal:hover {
    color: var(--text-main);
}

#editForm {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 10px;
}

/* --------------------------------------------------
 * Settings Tabs Design (Inside Settings Modal)
 * -------------------------------------------------- */
.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.02);
    padding: 0 16px;
    gap: 8px;
}

[data-theme="dark"] .settings-tabs {
    background-color: rgba(255, 255, 255, 0.02);
}

.tab-btn {
    padding: 14px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.tab-btn:hover {
    color: var(--primary);
    background-color: rgba(0,0,0,0.01);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.settings-tab-content {
    padding: 24px;
    min-height: 380px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Advanced Search & Filter layout in Settings */
.filters-modal-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.search-group-modal input {
    height: 48px;
    font-size: 1rem;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    outline: none;
    background-color: var(--bg-card);
    color: var(--text-main);
    width: 100%;
}

.modal-filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 16px;
    border-top: 1px dashed var(--border-color);
    padding-top: 16px;
}

/* Partner database layout (Add inline and tables) */
.partner-manager-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-panel-title {
    font-size: 1rem;
    color: var(--text-muted);
}

.partner-inline-form {
    display: flex;
    gap: 12px;
}

.partner-inline-form input {
    flex-grow: 1;
    height: 44px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-main);
    padding: 10px 16px;
    font-family: var(--font-main);
    outline: none;
}

.partner-inline-form input:focus {
    border-color: var(--primary);
}

.partner-list-scroll {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.partner-list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.partner-list-table th {
    background-color: rgba(0, 0, 0, 0.02);
    padding: 10px 16px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    font-weight: 700;
    text-align: left;
    position: sticky;
    top: 0;
}

[data-theme="dark"] .partner-list-table th {
    background-color: rgba(255, 255, 255, 0.02);
}

.partner-list-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

.partner-list-table tr:last-child td {
    border-bottom: none;
}

/* --------------------------------------------------
 * Toast System (Notifications)
 * -------------------------------------------------- */
.toast {
    visibility: hidden;
    min-width: 280px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: var(--radius-md);
    padding: 16px 24px;
    position: fixed;
    z-index: 2000;
    right: 30px;
    bottom: 30px;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(20px);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
}

.toast.show {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background-color: var(--success);
    border-left: 5px solid #047857;
}

.toast.error {
    background-color: #ef4444;
    border-left: 5px solid #b91c1c;
}

.toast.info {
    background-color: var(--info);
    border-left: 5px solid #0284c7;
}

/* --------------------------------------------------
 * Footer
 * -------------------------------------------------- */
.app-footer {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.01);
    margin-top: auto;
}

/* --------------------------------------------------
 * Responsive Breakpoints
 * -------------------------------------------------- */
@media (max-width: 1024px) {
    .form-split-columns {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

@media (max-width: 768px) {
    .header-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    .header-actions {
        justify-content: space-between;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .filters-container {
        flex-direction: column;
        align-items: stretch;
    }

    .form-row {
        flex-direction: column;
        gap: 16px;
    }

    .checkbox-col {
        justify-content: flex-start;
        padding-top: 8px;
    }

    .app-container {
        padding: 16px 12px;
        gap: 20px;
    }

    /* สไตล์ปุ่มบันทึกและล้างข้อมูลบนโทรศัพท์มือถือ */
    .form-actions-row {
        flex-direction: column !important;
        width: 100% !important;
        gap: 10px !important;
        align-items: stretch !important;
    }
    
    .form-actions-row button,
    .form-actions-row .btn {
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    /* ซ่อนคำว่า (Excel) และลดขนาดปุ่มปิดยอดรายเดือนบนโทรศัพท์ */
    .excel-text-suffix {
        display: none !important;
    }
    
    .btn-close-balance {
        font-size: 0.68rem !important;
        padding: 5px 8px !important;
        gap: 4px !important;
        height: auto !important;
        min-height: 32px !important;
        line-height: 1.25 !important;
        white-space: normal !important;
        text-align: center !important;
    }
}

/* --------------------------------------------------
 * Autocomplete / Datalist Dropdown Arrow Enhancements
 * -------------------------------------------------- */
input[list]::-webkit-calendar-picker-indicator {
    display: inline-block !important;
    opacity: 1 !important;
    cursor: pointer;
    color: var(--primary);
    background-color: transparent;
    padding: 6px;
    border-radius: 4px;
    transition: var(--transition);
}

input[list]::-webkit-calendar-picker-indicator:hover {
    background-color: var(--primary-light);
}

/* --------------------------------------------------
 * Mini Refresh Button & Spin Animation
 * -------------------------------------------------- */
.bsp-status-title {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.btn-refresh {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    color: var(--text-muted);
    padding: 6px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    outline: none;
}

.btn-refresh:hover {
    color: var(--primary);
    background-color: var(--primary-light);
    transform: scale(1.1);
}

.spin-animation {
    animation: spin-anim 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes spin-anim {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --------------------------------------------------
 * Main Table Instant Search Bar
 * -------------------------------------------------- */
.search-main-container {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 320px;
    width: 100%;
    margin-left: auto;
    margin-right: 16px;
}

.search-main-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    font-size: 0.95rem;
    pointer-events: none;
}

.search-main-container input {
    height: 38px;
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-main);
    padding: 8px 14px 8px 36px;
    font-family: var(--font-main);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition);
}

.search-main-container input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Adjust table header layout to fit the search bar nicely */
.flex-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;
    gap: 16px;
}

@media (max-width: 768px) {
    .search-main-container {
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

/* --------------------------------------------------
 * 1. Unified Dashboard Grid (Dashboard & Controls)
 * -------------------------------------------------- */
.dashboard-unified-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1.3fr;
    gap: 20px;
    padding: 16px 20px;
}

.dashboard-col {
    display: flex;
    flex-direction: column;
}

/* Vertical divider lines between columns */
.dashboard-col:not(:last-child) {
    border-right: 1px solid var(--border-color);
    padding-right: 20px;
}

.sub-column-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Compact stats list styling */
.mini-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.mini-stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mini-stat-item .label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.mini-stat-item .val {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.mini-stat-item .unit {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 2px;
}

/* Tab button inside sub headers */
.tab-btn-mini {
    padding: 3px 8px;
    background: none;
    border: none;
    font-family: var(--font-main);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
    outline: none;
}

.tab-btn-mini.active {
    color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.partner-list-scroll-embedded {
    max-height: 85px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: rgba(0, 0, 0, 0.01);
}

[data-theme="dark"] .partner-list-scroll-embedded {
    background-color: rgba(255, 255, 255, 0.005);
}

/* --------------------------------------------------
 * 4. Space Saving Compact Table Adjustments
 * -------------------------------------------------- */
.data-table-large th {
    padding: 8px 10px !important;
    font-size: 0.8rem !important;
}

.data-table-large td {
    padding: 8px 10px !important;
    font-size: 0.8rem !important;
}

.data-table-large tbody tr td strong {
    font-size: 0.8rem !important;
}

.data-table-large th.super-header-seller, 
.data-table-large th.super-header-customer, 
.data-table-large th.super-header-actions {
    padding: 8px 10px !important;
    font-size: 0.85rem !important;
}

.table-scroll-wrapper {
    max-height: 720px !important;
}

/* ปุ่มปิดยอดประจำเดือนสีเหลืองเข้ม/อำพัน */
.btn-close-balance {
    background-color: #ffb300 !important;
    border-color: #ffa000 !important;
    color: #1a1a1a !important;
    font-weight: 600 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.72rem;
    border: none;
    transition: var(--transition);
}

.btn-close-balance:hover {
    background-color: #ffa000 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(255, 160, 0, 0.2);
}

.btn-close-balance i {
    font-size: 0.85rem;
}

/* General Layout Optimization */
.app-container {
    padding: 16px 20px !important;
    gap: 16px !important;
}

.card-header {
    padding: 10px 18px !important;
}

/* Responsive stacks */
@media (max-width: 1024px) {
    .dashboard-unified-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .dashboard-col:not(:last-child) {
        border-right: none;
        border-bottom: 1px dashed var(--border-color);
        padding-right: 0;
        padding-bottom: 16px;
    }
}
