/* ======================================================
   WESTEROS v2 — Mobile-first responsive
   ====================================================== */

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #f43f5e;

    --topbar-h: 56px;
    --sidebar-w: 220px;
    --radius: 8px;

    --font-ui: 'Inter', 'Sarabun', system-ui, sans-serif;
    --font-th: 'Sarabun', system-ui, sans-serif;
}

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

body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

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

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* === Topbar === */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}
.brand-version {
    color: var(--primary);
    font-size: 11px;
    margin-left: 4px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    font-size: 16px;
    line-height: 1;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); }

.rate-display {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 4px 8px;
    background: var(--surface-2);
    border-radius: var(--radius);
    font-size: 12px;
}
.rate-label { font-size: 10px; color: var(--text-muted); }
.rate-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* === Layout === */
.layout {
    display: flex;
    flex: 1;
    min-height: calc(100vh - var(--topbar-h));
    position: relative;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.2s;
}
.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-family: var(--font-th);
    font-weight: 500;
    margin-bottom: 2px;
    font-size: 14px;
}
.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.nav-item.active {
    background: var(--primary);
    color: white;
}
.nav-item.disabled {
    opacity: 0.4;
    pointer-events: none;
}
.nav-icon {
    font-size: 17px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.main {
    flex: 1;
    padding: 16px;
    overflow-x: hidden;
    min-width: 0;
}

/* === Mobile sidebar (< 768px) === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: -100%;
        bottom: 0;
        z-index: 100;
        transition: left 0.25s ease;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
    }
    .sidebar.open { left: 0; }

    .main { padding: 12px; }
    .topbar { padding: 0 8px; }
    .rate-display { display: none; }
}

@media (min-width: 480px) and (max-width: 768px) {
    .rate-display { display: flex; }
}

/* Hide sidebar toggle on desktop */
@media (min-width: 769px) {
    .sidebar-toggle { display: none; }
    .sidebar-backdrop { display: none !important; }
}

/* === Page header === */
.page-header { margin-bottom: 16px; }
.page-header h1 {
    font-family: var(--font-th);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}
.page-header .muted { color: var(--text-muted); font-size: 13px; }

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .page-header h1 { font-size: 20px; }
    .page-header-row > a.btn,
    .page-header-row > button.btn {
        width: 100%;
    }
}

.back-link {
    display: inline-block;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-size: 13px;
}

/* === Cards === */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.card h2, .card h3 {
    font-family: var(--font-th);
    margin-bottom: 12px;
}
.card h3 { font-size: 16px; }
.card h4 { font-size: 14px; }

@media (max-width: 480px) {
    .card { padding: 12px; }
}

/* === Grid === */
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius);
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.15s;
    text-align: center;
    line-height: 1.3;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); color: white; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #fb7185; color: white; }
.btn-success { background: var(--success) !important; color: white !important; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Lists === */
.check-list { list-style: none; }
.check-list li { padding: 6px 0; color: var(--text-muted); font-family: var(--font-th); }
.check-list li::before { content: "○ "; }
.check-list li.done { color: var(--success); }
.check-list li.done::before { content: "✓ "; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* === Forms === */
.form-group { margin-bottom: 12px; }
.form-label {
    display: block;
    margin-bottom: 6px;
    font-family: var(--font-th);
    color: var(--text-muted);
    font-size: 13px;
}
.form-control {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
@media (max-width: 480px) {
    .form-row { grid-template-columns: 1fr; }
}

.form-divider {
    border: none;
    border-top: 1px dashed var(--border);
    margin: 16px 0;
}

.form-hint { font-size: 12px; margin-top: 4px; }

/* Flash messages */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 600;
    animation: flashIn 0.3s ease;
}
.flash-success {
    background: rgba(34,197,94,0.15);
    color: #22c55e;
    border: 1px solid rgba(34,197,94,0.3);
}
.flash-error {
    background: rgba(255,77,79,0.15);
    color: #ff4d4f;
    border: 1px solid rgba(255,77,79,0.3);
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Auto-fill fields with reset */
.input-with-reset {
    display: flex;
    align-items: center;
    gap: 6px;
}
.input-with-reset input { flex: 1; }
.reset-btn {
    background: rgba(245,158,11,0.15);
    color: #f59e0b;
    border: 1px solid rgba(245,158,11,0.3);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}
.reset-btn:hover { background: rgba(245,158,11,0.25); }
.auto-badge {
    font-size: 11px;
    color: #6b7280;
    font-weight: normal;
}
.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
@media (max-width: 480px) {
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }
}

.input-lg {
    font-size: 18px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.input-with-action, .input-with-unit {
    display: flex;
    gap: 0;
}
.input-with-unit .form-control {
    flex: 1;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}
.unit-select {
    width: 90px;
    flex-shrink: 0;
    padding: 10px 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.input-with-action { gap: 8px; }
.input-with-action .form-control { flex: 1; }

.radio-row {
    display: flex;
    gap: 16px;
    font-family: var(--font-th);
    flex-wrap: wrap;
}
.radio-row label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* === Radio cards === */
.radio-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.radio-card { cursor: pointer; display: block; }
.radio-card input { display: none; }
.radio-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    transition: all 0.15s;
}
.radio-card:hover .radio-content { border-color: var(--primary); }
.radio-card input:checked + .radio-content {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}
.radio-icon { font-size: 20px; }
.radio-label { font-family: var(--font-th); font-weight: 600; font-size: 13px; }
.radio-hint { font-size: 10px; color: var(--text-muted); }

/* === Filter card === */
.filter-card { padding: 14px; }
.filter-form { display: flex; flex-direction: column; gap: 8px; }
.filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.filter-search { flex: 2 1 200px; }
.filter-select { flex: 1 1 130px; min-width: 100px; }

@media (max-width: 640px) {
    .filter-row { flex-direction: column; }
    .filter-row > * { width: 100%; }

    .filter-form > .filter-row { display: none; }
    .filter-form.expanded > .filter-row { display: flex; }
}

/* === Tables === */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.table tbody tr:hover { background: var(--surface-2); }

.tickets-table th, .tickets-table td {
    white-space: nowrap;
    font-size: 13px;
    padding: 8px 10px;
}
.ticket-type {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.row-clickable { cursor: pointer; }
.row-clickable:hover { background: var(--surface-2); }

.text-right { text-align: right; }
.tabular { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* === Mobile: convert table to cards === */
@media (max-width: 640px) {
    .table-wrap.cards-on-mobile { overflow: visible; }

    .tickets-table thead { display: none; }
    .tickets-table, .tickets-table tbody { display: block; }

    .tickets-table tr {
        display: block;
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 8px;
        padding: 10px 12px;
    }
    .tickets-table tr:hover { background: var(--surface-2); }

    .tickets-table td {
        display: block;
        padding: 3px 0;
        border: none;
        white-space: normal;
        font-size: 13px;
    }

    .tickets-table td[data-label]::before {
        content: attr(data-label) ": ";
        color: var(--text-muted);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-right: 4px;
    }

    .tickets-table td.cell-ticket {
        font-size: 15px;
        font-weight: 700;
        margin-bottom: 4px;
    }
    .tickets-table td.cell-ticket::before { content: ""; }

    .tickets-table td.cell-amount {
        font-size: 15px;
        font-weight: 600;
    }
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.badge-lg { padding: 6px 14px; font-size: 13px; }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-danger  { background: rgba(244, 63, 94, 0.15); color: #fb7185; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-info    { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.badge-default { background: var(--surface-2); color: var(--text-muted); }
.badge-cancelled { background: rgba(107, 114, 128, 0.2); color: #9ca3af; font-size: 11px; letter-spacing: 0.5px; }

.row-cancelled { opacity: 0.5; }
.card-cancelled { opacity: 0.5; }
.btn-outline-danger {
    background: transparent;
    color: #fb7185;
    border: 1px solid #fb7185;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.btn-outline-danger:hover { background: rgba(244, 63, 94, 0.1); }

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.page-info { font-family: var(--font-th); font-size: 13px; }

/* === Empty state === */
.empty-state { text-align: center; padding: 40px 20px; }
.empty-icon { font-size: 40px; opacity: 0.5; margin-bottom: 8px; }

/* === Info table === */
.info-table { width: 100%; border-collapse: collapse; }
.info-table td {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-th);
    font-size: 13px;
}
.info-table tr:last-child td { border-bottom: none; }
.info-table td:first-child { width: 40%; color: var(--text-muted); font-size: 12px; }

@media (max-width: 480px) {
    .info-table td:first-child { width: 45%; }
}

.notes-text {
    font-family: var(--font-th);
    color: var(--text);
    white-space: pre-wrap;
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 13px;
}

.profit-value { color: var(--success); font-weight: 600; }
.loss-value { color: var(--danger); font-weight: 600; }

.net-profit-row td {
    border-top: 1px solid var(--border);
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    background: rgba(99, 102, 241, 0.04);
}

.action-card .inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.action-card .inline-form input { flex: 1; min-width: 150px; }

/* === Quote layout === */
.quote-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
}
@media (max-width: 1024px) {
    .quote-layout { grid-template-columns: 1fr; }
}

.preview-card { min-height: 300px; }

.preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    text-align: center;
}
.preview-empty-icon { font-size: 40px; margin-bottom: 8px; opacity: 0.5; }

.preview-result { display: flex; flex-direction: column; gap: 12px; }

/* Tier badge */
.tier-badge {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-family: var(--font-th);
    font-weight: 500;
    font-size: 13px;
    flex-wrap: wrap;
    gap: 8px;
}
.tier-tier_1 { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.tier-tier_2 { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.tier-tier_3 { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.tier-tier_4 { background: rgba(244, 63, 94, 0.15); color: #fb7185; }
.tier-pct { font-weight: 700; font-variant-numeric: tabular-nums; }

.direction-summary {
    font-family: var(--font-th);
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* Quote numbers */
.quote-numbers { display: flex; flex-direction: column; gap: 6px; }
.quote-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: baseline;
    gap: 6px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--bg);
}
.quote-row .label { font-family: var(--font-th); color: var(--text-muted); font-size: 12px; }
.quote-row .value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quote-row .unit { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.quote-row.highlight {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.3);
}
.quote-row.highlight .value { color: var(--primary-hover); font-size: 22px; }

/* Breakdown */
.quote-breakdown {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.breakdown-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-family: var(--font-th);
    flex-wrap: wrap;
    gap: 4px;
}
.breakdown-row.profit {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    font-weight: 600;
}

.quote-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.quote-actions .btn { flex: 1; min-width: 130px; }

/* === Customer rate editor === */
.customer-rate-section {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.3);
    padding: 12px;
    border-radius: var(--radius);
}
.customer-rate-section .form-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
}
.badge-custom {
    background: var(--warning);
    color: #1a1a1a;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}
.rate-edit-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.rate-input {
    flex: 1;
    min-width: 100px;
    font-size: 18px !important;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary-hover) !important;
}
.rate-unit {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* === Step blocks === */
.step-section {
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px dashed var(--border);
}
.step-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.step-label {
    font-family: var(--font-th);
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-hover);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.step-block {
    border-radius: var(--radius);
    padding: 12px;
    margin-top: 12px;
}
.step-block-cost {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.step-block-customer {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.step-block-pending {
    background: rgba(148, 163, 184, 0.08);
    border: 1px dashed var(--border);
    text-align: center;
}
.step-block-title {
    font-family: var(--font-th);
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 13px;
}

.cost-notify {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 10px;
    margin-bottom: 10px;
}
.cost-notify-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    font-family: var(--font-th);
    flex-wrap: wrap;
    gap: 4px;
    font-size: 13px;
}
.cost-notify-value {
    font-weight: 700;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    color: var(--warning);
}

/* === Type cards === */
.ticket-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
}
.type-card {
    display: block;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}
.type-card:hover { border-color: var(--primary); color: var(--text); }
.type-card.selected {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}
.type-card-label { font-family: var(--font-th); font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.type-card-desc { font-size: 11px; color: var(--text-muted); font-family: var(--font-th); }

/* === Edit form === */
.edit-form { margin-top: 8px; }
.edit-section {
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 10px;
}
.edit-section h4 {
    font-family: var(--font-th);
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.success-card { text-align: center; padding: 24px; }
.success-card h2 {
    color: var(--success);
    font-size: 24px;
    margin-bottom: 4px;
}

/* === Alert === */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-family: var(--font-th);
    font-size: 13px;
    margin-bottom: 10px;
}
.alert-danger {
    background: rgba(244, 63, 94, 0.1);
    color: #fb7185;
    border: 1px solid rgba(244, 63, 94, 0.3);
}

/* === Ticket cards (mobile) ============================ */
.tickets-desktop { display: block; }
.tickets-mobile { display: none; }

@media (max-width: 768px) {
    .tickets-desktop { display: none; }
    .tickets-mobile { display: flex; flex-direction: column; gap: 8px; }

    .filter-toggle { display: block !important; margin-bottom: 8px; }
    .filter-form > .filter-row { display: none; }
    .filter-form.expanded > .filter-row { display: flex; }
}

@media (min-width: 769px) {
    .filter-toggle { display: none !important; }
    .filter-form > .filter-row { display: flex !important; }
}

.ticket-card {
    display: block;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color 0.15s;
}
.ticket-card:hover, .ticket-card:active {
    border-color: var(--primary);
    color: var(--text);
}

.ticket-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
}
.ticket-card-no {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

.ticket-card-type {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 12px;
}
.ticket-card-icon { font-size: 14px; }

.ticket-card-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 0;
    border-top: 1px dashed var(--border);
}
.ticket-card-amount {
    font-size: 16px;
    font-weight: 700;
}

.ticket-card-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    flex-wrap: wrap;
    gap: 4px;
    font-size: 11px;
    font-family: var(--font-th);
}

/* === Audit Log === */
/* Compact collapsible audit log */
.audit-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.audit-row {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.audit-row[open] {
    background: var(--surface);
}
.audit-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    list-style: none;
    font-size: 12px;
    user-select: none;
}
.audit-summary::-webkit-details-marker { display: none; }
.audit-summary::before {
    content: '▶';
    color: var(--text-muted);
    font-size: 9px;
    transition: transform 0.15s;
    flex: 0 0 auto;
}
.audit-row[open] .audit-summary::before {
    transform: rotate(90deg);
}
.audit-time {
    flex: 0 0 auto;
    font-family: 'Courier New', monospace;
    color: var(--text-muted);
    font-size: 11px;
    white-space: nowrap;
}
.audit-badge {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1;
}
.audit-badge--auto_complete { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.audit-badge--confirm_transfer { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.audit-badge--cancel { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.audit-badge--revert_pending { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.audit-brief {
    flex: 1;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.audit-detail {
    padding: 10px 12px 12px 32px;
    border-top: 1px dashed var(--border);
    background: var(--bg);
}
.audit-notes {
    font-size: 12px;
    margin-bottom: 8px;
    font-style: italic;
}
.audit-diff {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 6px;
}
@media (max-width: 600px) {
    .audit-diff { grid-template-columns: 1fr; }
    .audit-summary { flex-wrap: wrap; gap: 6px; }
    .audit-brief { flex: 1 1 100%; order: 99; font-size: 11px; }
}
.audit-side {
    background: var(--surface);
    padding: 8px;
    border-radius: 6px;
}
.audit-old { border-left: 3px solid var(--text-muted); }
.audit-new { border-left: 3px solid var(--success); }
.audit-label {
    font-size: 11px;
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
}
.audit-content {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--text);
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

/* === Dashboard ============================================ */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    transition: border-color 0.15s;
}
.metric-card.metric-primary {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}
.metric-card.metric-warning {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.05);
}
.metric-icon {
    font-size: 22px;
    margin-bottom: 6px;
}
.metric-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
}
.metric-label {
    font-size: 11px;
    font-family: var(--font-th);
}

/* Alert */
.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.alert-link {
    margin-left: 8px;
    color: var(--warning);
    font-weight: 600;
    text-decoration: underline;
}

/* Quick actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}
.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 14px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: all 0.15s;
}
.quick-action-btn:hover, .quick-action-btn:active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
    color: var(--text);
}
.qa-icon { font-size: 24px; margin-bottom: 4px; }
.qa-label {
    font-family: var(--font-th);
    font-size: 12px;
    font-weight: 600;
}

/* Recent list */
.recent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.recent-item {
    display: block;
    padding: 10px;
    background: var(--bg);
    border-radius: var(--radius);
    color: var(--text);
    transition: background 0.15s;
}
.recent-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.recent-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    gap: 6px;
}
.recent-item-meta {
    margin-top: 2px;
    font-size: 11px;
}

.card-footer {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}

/* P&L stats */
.pnl-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.pnl-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    font-family: var(--font-th);
    font-size: 14px;
}
.pnl-row:last-child { border-bottom: none; }
.pnl-row .tabular { font-size: 16px; font-weight: 700; }

.top-ticket {
    text-align: center;
    padding: 8px;
    background: var(--bg);
    border-radius: var(--radius);
    font-family: var(--font-th);
}

/* Currency totals */
.currency-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.currency-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 13px;
}

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    margin-top: 8px;
    font-family: var(--font-th);
}

.wallet-mini-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.wallet-mini-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-th);
    transition: background 0.15s;
}
.wallet-mini-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.wallet-mini-name { font-size: 13px; }
.wallet-mini-balance { font-weight: 600; }

.status-footer {
    text-align: center;
    padding: 16px 8px;
    font-size: 11px;
    font-family: var(--font-th);
    border-top: 1px solid var(--border);
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
}
@media (max-width: 480px) {
    .status-footer { flex-direction: column; text-align: center; }
}

/* === Customers === */
.customer-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 10px;
}
.customer-card {
    display: block;
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color 0.15s;
}
.customer-card:hover {
    border-color: var(--primary);
    color: var(--text);
}
.customer-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
}
.customer-name {
    font-family: var(--font-th);
    font-size: 15px;
}
.customer-type-badge { font-size: 10px; }

.customer-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    font-family: var(--font-th);
}

.customer-stats {
    display: flex;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}
.customer-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: var(--font-th);
    font-size: 13px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-th);
    font-size: 13px;
    cursor: pointer;
}

/* === Agents === */
.agent-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 10px;
}

.agent-card {
    display: block;
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}
.agent-card:hover {
    border-color: var(--primary);
    color: var(--text);
}

.agent-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
}
.agent-name {
    font-family: var(--font-th);
    font-size: 15px;
    margin-right: 6px;
}
.commission-pct {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    padding: 4px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.agent-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    margin-top: 6px;
}
.agent-stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-family: var(--font-th);
    font-size: 13px;
    flex-wrap: wrap;
}
.agent-stat-pending {
    color: var(--warning);
}
.agent-stat strong {
    font-weight: 700;
}

/* === Payout card === */
.payout-card {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.05);
}

.payout-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.payout-amount {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.payout-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--warning);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.payout-form {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    margin-top: 6px;
}

/* === Ledger === */
.ledger-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ledger-entry {
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius);
    border-left: 3px solid var(--border);
}
.ledger-entry.ledger-accrued {
    border-left-color: var(--warning);
}
.ledger-entry.ledger-paid {
    border-left-color: var(--success);
    opacity: 0.85;
}

.ledger-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    gap: 6px;
    flex-wrap: wrap;
}
.ledger-ticket {
    font-weight: 700;
    color: var(--text);
}

.ledger-numbers {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    font-family: var(--font-th);
}
.ledger-amount {
    margin-left: auto;
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.wallet-addr {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: var(--surface);
    padding: 2px 8px;
    border-radius: 4px;
    word-break: break-all;
}

/* === Settings === */
.settings-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
}
.settings-row:last-child {
    border-bottom: none;
}

.settings-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: var(--font-th);
}
.settings-label strong {
    font-size: 14px;
}

.settings-input {
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-input .form-control {
    width: 90px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.input-suffix {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    min-width: 40px;
}

@media (max-width: 480px) {
    .settings-row {
        grid-template-columns: 1fr;
    }
    .settings-input {
        justify-content: flex-end;
    }
}

.info-stat {
    background: var(--bg);
    padding: 10px 12px;
    border-radius: var(--radius);
}
.info-stat strong {
    display: block;
    font-size: 18px;
    font-variant-numeric: tabular-nums;
    margin-top: 4px;
}

.settings-value {
    word-break: break-all;
    font-size: 11px;
    max-width: 100%;
    display: inline-block;
}

/* === Copy modal === */
.copy-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.copy-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.copy-modal h3 {
    font-family: var(--font-th);
    margin-bottom: 8px;
}

.copy-modal-text {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-th);
    font-size: 14px;
    margin-top: 12px;
    resize: vertical;
}

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

/* === Profit highlight === */
.profit-highlight {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05));
    border: 2px solid var(--success);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 12px;
    text-align: center;
    box-shadow: 0 2px 12px rgba(16, 185, 129, 0.15);
}

.profit-highlight-label {
    font-family: var(--font-th);
    color: #34d399;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.profit-highlight-main {
    font-size: 32px;
    font-weight: 800;
    color: #34d399;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
}

.profit-highlight-unit {
    font-size: 16px;
    font-weight: 600;
    color: #6ee7b7;
}

.profit-highlight-equiv {
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-th);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
    .profit-highlight {
        padding: 14px;
    }
    .profit-highlight-main {
        font-size: 28px;
    }
}

/* === Editable THB input === */
.editable-row .thb-input {
    background: transparent;
    border: 1px dashed transparent;
    border-radius: 6px;
    color: var(--primary-hover);
    font-size: 22px;
    font-weight: 700;
    text-align: right;
    padding: 4px 8px;
    flex: 1;
    min-width: 100px;
    font-variant-numeric: tabular-nums;
    font-family: inherit;
    transition: all 0.15s;
    cursor: text;
}

.editable-row .thb-input:hover {
    border-color: rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.05);
}

.editable-row .thb-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.editable-row .thb-input[readonly] {
    cursor: not-allowed;
    border-color: transparent;
}
.editable-row .thb-input[readonly]:hover {
    background: transparent;
    border-color: transparent;
}

/* Customer rate input - same auto-select behavior */
.rate-input {
    cursor: text;
}

/* === Fee info === */
.fee-info {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin: 10px 0;
}

.fee-info-header {
    font-family: var(--font-th);
    font-size: 12px;
    font-weight: 600;
    color: #fbbf24;
    margin-bottom: 6px;
}

.fee-info-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.fee-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: var(--font-th);
    font-size: 12px;
}

.fee-row-net {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed rgba(245, 158, 11, 0.2);
    font-weight: 600;
}

/* === 2-way tier inputs === */
.tier-baht-input {
    width: 70px !important;
    text-align: right !important;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.tier-eq {
    color: var(--text-muted);
    font-size: 13px;
    margin-left: 6px;
    margin-right: 4px;
}

.settings-input {
    flex-wrap: wrap;
    gap: 4px;
}

@media (max-width: 480px) {
    .settings-input {
        justify-content: flex-end;
    }
    .tier-baht-input {
        width: 80px !important;
    }
}

/* === 3-way adjustment grid === */
.adjustment-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.adjustment-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.adjustment-label {
    font-family: var(--font-th);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 11px;
}

.adjustment-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 8px;
    transition: border-color 0.15s;
}

.adjustment-input-row:focus-within {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.adjustment-input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    padding: 8px 0 !important;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary-hover);
    font-size: 15px;
    text-align: right;
    min-width: 60px;
}

.adjustment-input:focus {
    outline: none;
}

.adjustment-unit {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .adjustment-grid {
        grid-template-columns: 1fr;
    }
}

/* === Live rate button === */
#live-rate-btn {
    flex-shrink: 0;
    padding: 10px 14px;
    white-space: nowrap;
    font-size: 13px;
}
#live-rate-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* === Pending transfer badge === */
.badge-pending {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.5);
}

.pending-action-card {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.05);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.1);
}

.pending-action-card h3 {
    color: #fbbf24;
}

.ticket-card[data-status="pending_fee"] {
    border-left: 3px solid var(--warning);
}

/* === Tx hash display === */
.tx-hash {
    display: inline-block;
    padding: 2px 8px;
    background: var(--surface-2);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    word-break: break-all;
    max-width: 100%;
}

/* === USDT → THB equivalent === */
.metric-equiv {
    margin-top: -2px;
    margin-bottom: 4px;
    font-size: 10px;
    opacity: 0.7;
}

.wallet-mini-balance small {
    display: block;
    font-size: 10px;
    font-weight: 400;
    margin-top: 2px;
    opacity: 0.7;
}

.currency-pill .muted {
    font-size: 10px;
    margin-left: 4px;
}

/* === Copy toast === */
.copy-toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(16, 185, 129, 0.95);
    color: white;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.copy-toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.copy-toast-warn {
    background: rgba(245, 158, 11, 0.95);
}

/* === Copy fallback dialog (mobile) === */
.copy-fallback-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

.copy-fallback-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.copy-fallback-card h3 { margin: 0 0 4px 0; }

.copy-fallback-card textarea {
    width: 100%;
    min-height: 100px;
    margin: 12px 0;
    padding: 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    -webkit-user-select: all;
    user-select: all;
}

.copy-fallback-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === Wallet CRUD === */
.page-actions { margin-bottom: 8px; }
.action-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.form-card { max-width: 600px; }

/* === Ticket card type colors === */
.ticket-card { border-left: 4px solid var(--border); }
.ticket-type-green   { border-left-color: #10b981; }
.ticket-type-blue    { border-left-color: #3b82f6; }
.ticket-type-purple  { border-left-color: #a855f7; }
.ticket-type-orange  { border-left-color: #f97316; }
.ticket-type-cyan    { border-left-color: #06b6d4; }
.ticket-type-red     { border-left-color: #ef4444; }
.ticket-type-violet  { border-left-color: #8b5cf6; }
.ticket-type-amber   { border-left-color: #f59e0b; }
.ticket-type-gray    { border-left-color: #6b7280; }

/* === Quick date filter buttons === */
.quick-filter-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 4px 0;
    padding: 8px 0;
    border-top: 1px dashed var(--border);
}
.quick-filter-row .btn-sm {
    flex: 1;
    min-width: 80px;
    font-size: 12px;
    padding: 6px 10px;
}
.form-label { display: block; margin-bottom: 2px; }
.flex-1 { flex: 1; }
input[type="date"] { color-scheme: dark; }

/* === Inventory flow form === */
.flow-section {
    background: var(--surface-2);
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
}
.flow-label {
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 11px;
}
.flow-arrow {
    text-align: center;
    font-size: 24px;
    margin: 4px 0;
    color: var(--primary);
}

/* SWAP cross-currency warning */
.swap-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-left: 3px solid #f59e0b;
    color: #f59e0b;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    margin: 8px 0;
}
.swap-warning b { color: #fbbf24; font-weight: 700; }
.ticket-type-teal { border-left-color: #14b8a6; }

/* === Rate row in exchange form === */
.rate-row {
    background: rgba(99, 102, 241, 0.08);
    border: 1px dashed rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
    margin: 8px 0;
}
.rate-suffix {
    display: flex;
    align-items: center;
    padding: 0 12px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

/* === Focus pulse for prefill form === */
.focus-pulse {
    animation: focusPulse 1s ease-in-out 2;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4) !important;
    border-color: var(--primary) !important;
}

@keyframes focusPulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.6); }
}

/* === Min sell rate hints === */
.min-rate-hint { margin: 8px 0; }
.min-rate-card {
    background: rgba(99, 102, 241, 0.05);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12px;
}
.lot-list { margin: 6px 0; padding-left: 4px; font-family: monospace; font-size: 11px; }
.lot-row { color: var(--text-muted); }
.min-rate-total {
    display: flex; justify-content: space-between;
    padding-top: 8px; margin-top: 6px;
    border-top: 1px dashed var(--border); font-weight: 500;
}
.min-rate-value { color: #f59e0b; font-size: 13px; }
.min-rate-value b { color: #fbbf24; font-size: 14px; }
.hint-warn { color: #f59e0b; padding: 4px 0; }
.hint-danger { color: #ef4444; padding: 4px 0; font-weight: 600; }
.hint-success { color: #10b981; padding: 4px 0; font-weight: 600; }
.rate-loss { border-color: #ef4444 !important; box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2) !important; }
.rate-profit { border-color: #10b981 !important; box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2) !important; }
.rate-warning { margin-top: 4px; font-size: 12px; }

/* === Wallet summary cards (vertical stack) === */
.summary-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
}
.summary-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.summary-right { text-align: right; }
.summary-total {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.06));
    border-color: rgba(99, 102, 241, 0.25);
}
.summary-bank { border-left: 3px solid #10b981; }
.summary-crypto { border-left: 3px solid #f59e0b; }
.summary-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.summary-value-big { font-size: 24px; font-weight: 800; line-height: 1.15; }
.summary-value { font-size: 20px; font-weight: 700; line-height: 1.15; }
.summary-value-sub { font-size: 12px; margin-top: 2px; }
.rate-info {
    text-align: center;
    margin: 4px 0 14px;
    padding: 4px 8px;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 6px;
}
@media (max-width: 480px) {
    .summary-card { padding: 12px 14px; }
    .summary-value-big { font-size: 22px; }
    .summary-value { font-size: 18px; }
}

/* === Dashboard period filter === */
.period-filter {
    display: flex;
    gap: 6px;
    margin: 12px 0 8px;
}
.period-btn {
    flex: 1;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    text-align: center;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}
.period-btn:hover { border-color: var(--primary); }
.period-btn.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}
.period-custom {
    display: none;
    gap: 6px;
    align-items: center;
    margin: 0 0 8px;
    padding: 10px;
    background: var(--surface-2);
    border-radius: 8px;
}
.period-custom.show { display: flex; flex-wrap: wrap; }
.period-custom .form-control { flex: 1; min-width: 120px; }

/* === Vertical stat cards === */
.stat-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0 16px;
}
.stat-card-v {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
}
.stat-highlight {
    border-color: rgba(99, 102, 241, 0.3);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(168, 85, 247, 0.05));
}
.stat-pending { border-left: 3px solid #f59e0b; }
.stat-profit { border-left: 3px solid #10b981; }
.stat-loss { border-left: 3px solid #ef4444; }
.stat-icon-v { font-size: 24px; flex: 0 0 auto; }
.stat-body-v { flex: 1; min-width: 0; }
.stat-label-v {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}
.stat-value-v {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.2;
}
.stat-sub-v { font-size: 12px; margin-top: 2px; }
.stat-fraction b { color: #10b981; font-size: 24px; }
.stat-pending-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
}
.stat-profit .stat-value-v { color: #10b981; }
.stat-loss .stat-value-v { color: #ef4444; }
@media (max-width: 480px) {
    .stat-value-v { font-size: 20px; }
    .stat-fraction b { font-size: 22px; }
    .period-btn { font-size: 11px; padding: 7px 6px; }
}

/* === P&L breakdown card === */
.pnl-breakdown-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid #10b981;
    border-radius: 10px;
    padding: 14px 16px;
}
.pnl-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}
.pnl-rows { display: flex; flex-direction: column; gap: 4px; }
.pnl-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 3px 0;
    font-size: 13px;
}
.pnl-label { color: var(--text-muted); }
.pnl-value { font-weight: 600; text-align: right; }
.pnl-usdt { font-size: 11px; margin-left: 4px; font-weight: 400; }
.pnl-gross .pnl-value { color: #10b981; }
.pnl-deduction { padding-left: 8px; }
.pnl-deduction .pnl-value { color: #ef4444; }
.pnl-pending-row { opacity: 0.85; }
.pnl-net {
    margin-top: 6px;
    padding-top: 8px !important;
    border-top: 1px solid var(--border);
    font-size: 16px !important;
}
.pnl-net .pnl-label { font-weight: 700; color: var(--text); }
.pnl-net .pnl-value { font-size: 18px; }
.pnl-positive .pnl-value { color: #10b981 !important; }
.pnl-negative .pnl-value { color: #ef4444 !important; }

/* === Datetime edit form === */
.dt-edit-form input[type="datetime-local"] {
    color-scheme: dark;
}

.dt-edit-form .form-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* === Breakdown Card === */
.breakdown-card .bd-group { margin-top: 14px; }
.breakdown-card .bd-group:first-of-type { margin-top: 8px; }
.breakdown-card .bd-group-title {
    font-size: 13px; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 8px; padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.breakdown-card .bd-row { padding: 8px 0; border-bottom: 1px dashed var(--border); }
.breakdown-card .bd-row:last-child { border-bottom: none; }
.breakdown-card .bd-row-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.breakdown-card .bd-emoji { font-size: 16px; }
.breakdown-card .bd-type { font-weight: 600; color: var(--text); font-size: 14px; }
.breakdown-card .bd-count { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.breakdown-card .bd-row-body { padding-left: 24px; }
.breakdown-card .bd-line {
    display: flex; justify-content: space-between;
    font-size: 13px; color: var(--text-muted); padding: 2px 0;
}
.breakdown-card .bd-line.bd-profit { margin-top: 4px; font-weight: 600; }
.breakdown-card .bd-subtotal {
    display: flex; justify-content: space-between; margin-top: 8px;
    padding-top: 6px; font-weight: 600; font-size: 13px; color: var(--text-muted);
}
.breakdown-card .bd-grand {
    margin-top: 16px; padding-top: 12px;
    border-top: 2px solid var(--border);
}
.breakdown-card .bd-grand-title { font-weight: 700; color: var(--text); margin-bottom: 8px; font-size: 14px; }
.breakdown-card .pos { color: var(--success); }
.breakdown-card .neg { color: var(--danger); }
.breakdown-card .exf-net { display: block; }
.breakdown-card .exf-net .bd-line { display: flex; justify-content: space-between; }
.exchange-flow-group { border-left: 3px solid #a78bfa; padding-left: 8px; }

/* Stronger negative values: bold bright red */
.pnl-row .loss-value,
.pnl-deduction .pnl-value {
    color: #ff4d4f !important;
    font-weight: 700;
}

/* Breakdown collapsible */
details.breakdown-card { overflow: hidden; }
details.breakdown-card > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    user-select: none;
}
details.breakdown-card > summary::-webkit-details-marker { display: none; }
.breakdown-toggle .bd-chevron::after { content: '▼'; font-size: 11px; color: var(--text-muted); margin-left: 8px; }
details[open].breakdown-card .bd-chevron::after { content: '▲'; }
details.breakdown-card > summary:hover { opacity: 0.8; }

/* USDT editor in quote (mirrors .thb-input style) */
.editable-row .usdt-input {
    background: transparent;
    border: 1px dashed transparent;
    border-radius: 6px;
    color: var(--primary-hover);
    font-size: 22px;
    font-weight: 700;
    text-align: right;
    padding: 4px 8px;
    flex: 1;
    min-width: 100px;
    transition: border-color 0.15s, background 0.15s;
}
.editable-row .usdt-input:hover {
    border-color: rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.05);
}
.editable-row .usdt-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

/* Outstanding memo section in P&L card */
.pnl-outstanding {
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}
.pnl-outstanding-title { margin-bottom: 4px; }
.pnl-row.pnl-memo { padding: 4px 0; }
.pnl-row.pnl-memo .pnl-label { font-size: 12px; }
.pnl-row.pnl-memo .pnl-value { font-size: 12px; }

/* Net (period) grand total box */
.pnl-net-grand {
    margin-top: 16px;
    padding: 16px 14px;
    background: rgba(255,255,255,0.04);
    border-top: 3px double rgba(255,255,255,0.15);
    border-bottom: 3px double rgba(255,255,255,0.15);
    border-radius: 8px;
}
.pnl-net-grand-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; color: var(--text); }
.pnl-net-grand-line { display: flex; justify-content: space-between; padding: 3px 0; }
.pnl-net-grand-line .label { color: var(--text-muted); font-weight: 500; }
.pnl-net-grand-line.thb .value { font-weight: 700; font-size: 18px; }
.pnl-net-grand-line.usdt .value { font-weight: 600; font-size: 15px; }

/* Outstanding memo */
.pnl-outstanding { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); }
.pnl-outstanding-title { font-size: 13px; color: #9ca3af; font-weight: 600; margin-bottom: 6px; }
.pnl-outstanding-item { padding-left: 12px; }
.pnl-outstanding-item .item-label { font-size: 12px; color: #9ca3af; margin-bottom: 4px; }
.pnl-outstanding-line { display: flex; justify-content: space-between; font-size: 13px; color: #9ca3af; padding: 2px 0; }
.pnl-outstanding-hint { font-size: 11px; color: #6b7280; font-style: italic; margin-top: 6px; padding-left: 12px; }

/* === Pending Quotes === */
.pending-quotes-card { margin-top: 16px; }
.pq-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.pq-clear {
    background: transparent;
    color: #9ca3af;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}
.pq-clear:hover { color: #ff4d4f; border-color: #ff4d4f; }
.pq-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}
.pq-entry:hover { background: rgba(255,255,255,0.06); }
.pq-direction {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
}
.pq-direction.BUY  { color: #22c55e; }
.pq-entry.BUY  { border-left-color: #22c55e; }
.pq-direction.SELL { color: #f87171; }
.pq-entry.SELL { border-left-color: #f87171; }
.pq-time {
    font-size: 11px;
    color: #6b7280;
    margin-right: 12px;
    white-space: nowrap;
}
.pq-actions {
    display: flex;
    gap: 6px;
}
.pq-open {
    background: #6366f1;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.pq-open:hover { background: #4f46e5; }
.pq-remove {
    background: transparent;
    color: #9ca3af;
    border: 1px solid rgba(255,255,255,0.1);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pq-remove:hover { color: #ff4d4f; border-color: #ff4d4f; }
.pq-empty {
    text-align: center;
    color: #6b7280;
    font-size: 13px;
    padding: 16px;
}
.pq-pin-btn {
    background: transparent;
    color: #9ca3af;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}
.pq-pin-btn:hover { color: #f59e0b; border-color: #f59e0b; }
.pq-info { flex: 1; min-width: 0; }
.pq-note { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.pq-meta { font-size: 12px; color: #d1d5db; margin-top: 2px; }
.pq-meta.muted { font-size: 11px; color: #6b7280; }
.pq-entry.pq-active { background: rgba(99,102,241,0.12); border-left-width: 4px; }
.pq-entry.pq-active.BUY  { border-left-color: #22c55e; }
.pq-entry.pq-active.SELL { border-left-color: #f87171; }
.thb-remainder-hint {
    font-size: 12px;
    color: #22c55e;
    padding: 2px 12px 6px;
    opacity: 0.85;
}
.loss-warning {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #f87171;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    margin-top: 8px;
}

/* THB sub-line + conversion display */
.thb-sub,.conv-sub{font-size:.72rem;color:#64748b;text-align:right;margin-top:.15rem;font-variant-numeric:tabular-nums}
.wallet-mini-right{display:flex;flex-direction:column;align-items:flex-end}

/* Holdings collapsible lots */
.holding-group summary::-webkit-details-marker { display: none; }
.holding-group[open] .muted span { display: inline; }
.holding-group[open] > summary .muted span::after { content: ' ▾'; }
.holding-group:not([open]) > summary .muted span::after { content: ''; }
