:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --text: #14213d;
    --muted: #66738b;
    --border: #dfe5ef;
    --blue: #2878f0;
    --blue-dark: #1766da;
    --orange: #ff620f;
    --orange-dark: #e95308;
    --green: #159447;
    --purple: #654de4;
    --shadow: 0 8px 30px rgba(30, 52, 83, .06);
    --radius: 12px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.import-steps { display: grid; grid-template-columns: repeat(6, 1fr); margin-bottom: 20px; overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.import-steps span { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 52px; color: var(--muted); border-right: 1px solid var(--border); font-size: 12px; font-weight: 700; }
.import-steps span:last-child { border-right: 0; }
.import-steps b { width: 23px; height: 23px; display: grid; place-items: center; background: #eef2f7; border-radius: 50%; font-size: 11px; }
.import-steps .active { color: var(--blue); background: #f4f8ff; }
.import-steps .active b { color: #fff; background: var(--blue); }
.import-steps .complete b { color: #fff; background: var(--green); }
.import-step { display: none; }
.import-step.active { display: block; }
.import-step-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.import-step-heading h2 { margin: 0; }
.import-step-heading p { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.import-upload-form { display: grid; justify-items: center; gap: 18px; padding: 8px 0 4px; }
.import-drop-zone { width: min(100%, 650px); min-height: 210px; display: grid; place-items: center; align-content: center; gap: 8px; padding: 28px; color: var(--text); background: #fafcff; border: 2px dashed #cbd6e6; border-radius: 14px; cursor: pointer; text-align: center; }
.import-drop-zone:hover { border-color: var(--blue); background: #f6faff; }
.import-drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.import-drop-zone small { color: var(--muted); }
.import-upload-icon { width: 48px; height: 48px; display: grid; place-items: center; color: var(--blue); background: #eaf3ff; border-radius: 12px; font-size: 24px; font-weight: 800; }
.import-table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 9px; }
.import-table-wrap table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: 12px; }
.import-table-wrap th, .import-table-wrap td { max-width: 220px; padding: 11px 13px; overflow: hidden; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); text-align: left; text-overflow: ellipsis; }
.import-table-wrap th { background: #f7f9fc; font-weight: 800; }
.import-table-wrap tr:last-child td { border-bottom: 0; }
.saved-mapping-select { min-width: 270px; }
.saved-mapping-select select { margin-top: 6px; }
.import-mapping-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.import-map-field { min-width: 0; display: grid; grid-template-rows: auto 44px 15px; align-content: start; }
.import-map-field > span { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 700; }
.import-map-field b { color: #d73333; }
.import-map-field select { width: 100%; height: 44px; }
.import-map-field small { display: block; min-height: 15px; margin-top: 4px; color: var(--muted); font-size: 10px; }
.save-mapping-row { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; align-items: end; gap: 14px; margin-top: 22px; padding: 16px; background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; }
.save-mapping-row .check-row { align-self: center; margin-top: 18px; }
.import-result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.import-result-grid > div { padding: 20px; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; }
.import-result-grid span, .import-result-grid strong { display: block; }
.import-result-grid span { color: var(--muted); font-size: 12px; }
.import-result-grid strong { margin-top: 7px; font-size: 28px; }
.import-result-grid .valid strong { color: var(--green); }
.import-result-grid .error strong { color: #c73a3a; }
.validation-message { margin-top: 16px; padding: 13px 15px; color: #485a77; background: #f5f8fc; border-radius: 8px; font-size: 13px; }
.import-confirm { min-height: 330px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 13px; text-align: center; }
.import-confirm h2, .import-confirm p { margin: 0; }
.import-confirm p { max-width: 600px; color: var(--muted); line-height: 1.6; }
.import-confirm.complete .import-upload-icon { color: var(--green); background: #e9f7ef; }
.import-history-card { margin-top: 22px; }
.import-history-table td:first-child strong, .import-history-table td:first-child small { display: block; }
.import-history-table td:first-child small { margin-top: 3px; color: var(--muted); }
.btn-danger-light { padding: 8px 12px; color: #b42318; background: #fff5f4; border: 1px solid #f4c7c3; border-radius: 7px; font-size: 12px; font-weight: 700; cursor: pointer; }
.btn-danger-light:hover { background: #feeceb; }

@media (max-width: 900px) {
    .import-steps { grid-template-columns: repeat(3, 1fr); }
    .import-steps span:nth-child(3) { border-right: 0; }
    .import-steps span:nth-child(-n+3) { border-bottom: 1px solid var(--border); }
    .import-mapping-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .save-mapping-row { grid-template-columns: 1fr; }
    .save-mapping-row .check-row { margin-top: 0; }
}

@media (max-width: 600px) {
    .import-steps span { font-size: 0; }
    .import-steps b { font-size: 11px; }
    .import-step-heading { display: grid; }
    .saved-mapping-select { min-width: 0; }
    .import-mapping-grid, .import-result-grid { grid-template-columns: 1fr; }
}

.app-shell { min-height: 100vh; display: flex; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 242px; display: flex; flex-direction: column; padding: 24px 16px 18px; background: #fff; border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 26px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; color: var(--blue); border: 2px solid var(--blue); border-radius: 8px; font-weight: 800; font-size: 13px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.sidebar-logo { display: block; width: 154px; height: auto; object-fit: contain; }
.brand .sidebar-portal-label { margin: 4px 0 0 2px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sidebar .brand { display: block; padding-left: 12px; }
.nav-list { display: grid; gap: 4px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 13px; background: transparent; border: 0; border-radius: 8px; text-align: left; font-size: 13px; cursor: pointer; transition: .18s ease; }
.nav-item span:first-child { width: 20px; color: #52709d; text-align: center; font-size: 17px; }
.nav-item:hover { background: #f4f7fb; }
.nav-item.active { color: var(--blue); background: #edf5ff; font-weight: 700; }
.nav-item.active span:first-child { color: var(--blue); }
.logout { margin-top: auto; border-top: 1px solid var(--border); border-radius: 0; padding-top: 18px; }

.main-area { width: calc(100% - 242px); min-height: 100vh; margin-left: 242px; }
.topbar { height: 68px; display: flex; align-items: center; gap: 22px; padding: 0 34px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--border); }
.topbar-spacer { flex: 1; }
.topbar-customer { min-width: 270px; display: flex; align-items: center; gap: 9px; padding: 7px 11px; color: #596980; background: #f7f9fc; border: 1px solid var(--border); border-radius: 9px; text-align: left; cursor: pointer; }
.topbar-customer:hover { border-color: #b9cbe3; background: #f1f6fc; }
.topbar-customer > span:nth-child(2) { min-width: 0; display: grid; gap: 2px; }
.topbar-customer small { color: #77859a; font-size: 8px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.topbar-customer strong { max-width: 145px; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-customer-account { margin-left: auto; color: var(--blue); font-size: 9px; font-weight: 700; white-space: nowrap; }
.topbar-customer.has-customer { color: #234f88; background: #edf5ff; border-color: #cfe0f7; }
.menu-toggle, .help-button { border: 0; background: transparent; cursor: pointer; }
.menu-toggle { display: none; font-size: 22px; }
.help-button { display: flex; gap: 7px; align-items: center; color: #40516e; font-size: 13px; }
.agent-menu { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; background: var(--blue); color: white; border-radius: 50%; font-weight: 700; font-size: 11px; }
.content-wrap { max-width: 1160px; margin: 0 auto; padding: 40px 42px 70px; }
.screen { display: none; animation: screenIn .18s ease; }
.screen.active { display: block; }
@keyframes screenIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.eyebrow { margin-bottom: 9px; color: #485a77; font-size: 12px; font-weight: 700; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading h1 { margin: 0; font-size: clamp(24px, 3vw, 31px); letter-spacing: -.025em; }
.page-heading p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.with-back { align-items: center; }
.heading-actions { display: flex; align-items: center; gap: 18px; }
.section-title { margin: 30px 0 15px; }
.section-title h2, .card h2 { margin: 0; font-size: 16px; }
.stats-title { display: flex; align-items: center; justify-content: space-between; }
.stats-title button { padding: 0; color: var(--blue); background: transparent; border: 0; font-size: 12px; font-weight: 700; cursor: pointer; }

.card, .hero-card, .quick-card, .action-card, .library-card, .settings-row, .stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card { padding: 22px; margin-bottom: 20px; }
.hero-card { min-height: 145px; display: flex; align-items: center; gap: 20px; padding: 28px 30px; }
.hero-card h2 { margin: 0 0 7px; font-size: 21px; }
.hero-card p { margin: 0; color: var(--muted); font-size: 14px; }
.hero-card .btn { margin-left: auto; }
.hero-icon { flex: 0 0 auto; width: 52px; height: 52px; display: grid; place-items: center; color: var(--orange); background: #fff3ec; border-radius: 12px; font-size: 30px; }
.activity-title { margin-top: 0; }
.activity-choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.activity-choice-card { min-height: 150px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; padding: 24px; background: white; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); text-align: left; cursor: pointer; transition: .18s ease; }
.activity-choice-card:hover { transform: translateY(-2px); border-color: #b9c8dc; box-shadow: 0 12px 34px rgba(30,52,83,.09); }
.activity-choice-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 11px; font-size: 24px; font-weight: 700; }
.activity-choice-card.find .activity-choice-icon { color: var(--blue); background: #edf5ff; }
.activity-choice-card.new .activity-choice-icon { color: var(--orange); background: #fff1e9; }
.activity-choice-card > span:nth-child(2) { display: grid; gap: 7px; }
.activity-choice-card strong { font-size: 17px; }
.activity-choice-card small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.activity-choice-arrow { color: #8491a5; font-size: 27px; }

.quick-grid, .action-grid, .stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.quick-card, .action-card { min-height: 150px; display: flex; flex-direction: column; align-items: flex-start; gap: 9px; padding: 20px; text-align: left; cursor: pointer; transition: .18s ease; }
.quick-card:hover, .action-card:hover, .library-card:hover, .settings-row:hover { transform: translateY(-2px); border-color: #c5d0df; }
.quick-card strong, .action-card strong { font-size: 14px; }
.quick-card small, .action-card small, .library-card small { color: var(--muted); line-height: 1.5; }
.card-icon { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 8px; font-weight: 800; }
.card-icon.blue { color: var(--blue); background: #edf5ff; }
.card-icon.green { color: var(--green); background: #eaf8ef; }
.card-icon.purple { color: var(--purple); background: #f0edff; }
.card-icon.orange { color: var(--orange); background: #fff1e9; }
.card-icon.red { color: #c92f28; background: #fff0ef; }
.green-border { border-color: #bfe4cc; }
.purple-border { border-color: #d8d0ff; }
.orange-border { border-color: #ffd1b8; }
.blue-border { border-color: #c9dcfa; }
.red-border { border-color: #f2b9b5; }

.btn { min-height: 44px; padding: 0 22px; border: 1px solid transparent; border-radius: 7px; font-weight: 700; font-size: 13px; cursor: pointer; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-large { min-height: 50px; padding-inline: 28px; }
.btn-primary { color: white; background: var(--orange); box-shadow: 0 5px 14px rgba(255,98,15,.18); }
.btn-primary:hover { background: var(--orange-dark); }
.btn-secondary { color: white; background: var(--blue); box-shadow: 0 5px 14px rgba(40,120,240,.16); }
.btn-secondary:hover { background: var(--blue-dark); }
.btn-light { color: #3e4f6c; background: white; border-color: var(--border); }
.btn-outline-orange { color: var(--orange); background: white; border: 1px dashed var(--orange); }
.back-link { padding: 4px 0; color: #40516e; background: transparent; border: 0; cursor: pointer; font-size: 13px; }
#customer-snapshot > .back-link { margin-bottom: 15px; }

label { display: grid; gap: 8px; color: #23324e; font-size: 12px; font-weight: 700; }
.field-label { display: inline-flex; align-items: baseline; gap: 3px; color: #23324e; }
.field-label > span { color: #d93d34; }
input, select, textarea { width: 100%; color: var(--text); background: #fff; border: 1px solid #d7deea; border-radius: 7px; outline: 0; transition: border .15s, box-shadow .15s; }
input, select { height: 44px; padding: 0 13px; }
textarea { padding: 12px 13px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: #73a7f4; box-shadow: 0 0 0 3px rgba(40,120,240,.09); }
input::placeholder, textarea::placeholder { color: #9aa5b7; }
.search-card > label { margin-bottom: 9px; }
.search-row { display: flex; gap: 12px; }
.search-row input { flex: 1; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 13px; }
.card-header span { color: var(--muted); font-size: 12px; }
.customer-row { width: 100%; display: grid; grid-template-columns: 1.25fr 1fr .9fr 1.25fr 20px; gap: 16px; align-items: center; padding: 16px 6px; background: white; border: 0; border-top: 1px solid var(--border); text-align: left; cursor: pointer; }
.customer-row:hover { background: #fafcff; }
.customer-name { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.customer-avatar { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; color: #13723b; background: #e3f3e9; border-radius: 50%; font-weight: 800; }
.customer-row span:not(.customer-avatar) { color: #4f5f78; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.card-footer { display: flex; justify-content: center; padding-top: 16px; border-top: 1px solid var(--border); }
.no-results { padding: 32px 10px; color: var(--muted); text-align: center; }

.form-card { padding: 19px 20px; }
.form-card h2 { margin-bottom: 18px; }
.form-card label { gap: 6px; }
.form-card input, .form-card select { height: 40px; }
.form-card textarea { padding-block: 9px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 18px; }
.form-span-2 { grid-column: 1 / -1; }
.form-section { margin-top: 21px; padding-top: 18px; border-top: 1px solid var(--border); }
.form-section h3 { margin: 0 0 15px; font-size: 14px; }
.form-section label small { margin-left: 4px; color: var(--muted); font-size: 10px; font-weight: 500; }
.address-grid { grid-template-columns: 2fr .65fr .85fr; }
.address-grid .form-span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; padding-top: 17px; border-top: 1px solid var(--border); }
.narrow { max-width: 680px; }
.narrow > label, .narrow > .form-grid, .narrow > .channel-grid, .narrow > .disclosures { margin-bottom: 16px; }
.money-input { position: relative; }
.money-input > span { position: absolute; top: 11px; left: 13px; color: #53637b; }
.money-input input { padding-left: 30px; }
.payment-customer-summary { display: grid; grid-template-columns: .8fr 1.7fr; gap: 18px; margin: -2px 0 18px; padding: 14px 16px; background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; }
.payment-customer-summary div { display: grid; gap: 4px; }
.payment-customer-summary span { color: var(--muted); font-size: 11px; }
.payment-customer-summary strong { font-size: 13px; line-height: 1.5; }
.stack-actions { display: grid; gap: 8px; margin-top: 18px; }
.channel-grid { display: grid; grid-template-columns: 145px 1fr; gap: 12px; align-items: center; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check-row input { width: 16px; height: 16px; accent-color: var(--blue); }
.disclosures { display: grid; gap: 12px; padding: 16px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; }
.message-preview { min-height: 185px; background: #fbfcfe; }

.snapshot-card { padding: 0; overflow: hidden; }
.snapshot-primary { display: flex; align-items: center; gap: 16px; padding: 24px; }
.snapshot-primary h2 { margin: 0 0 5px; font-size: 20px; }
.snapshot-primary p { margin: 0; color: var(--muted); font-size: 12px; }
.balance { margin-left: auto; text-align: right; }
.balance span, .snapshot-details span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.balance strong { color: var(--orange); font-size: 20px; }
.snapshot-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; padding: 22px 24px; border-top: 1px solid var(--border); }
.snapshot-details strong { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.action-grid { grid-template-columns: repeat(3, 1fr); }

.library-grid, .settings-list { display: grid; gap: 12px; }
.library-card, .settings-row { width: 100%; display: flex; align-items: center; gap: 15px; padding: 18px 20px; text-align: left; cursor: pointer; transition: .18s ease; }
.library-card div:nth-child(2) { display: grid; gap: 4px; flex: 1; }
.library-card > span:last-child, .settings-row > span:last-child { margin-left: auto; color: #8390a4; font-size: 22px; }
.template-list { padding: 0; overflow: hidden; }
.template-row { display: grid; grid-template-columns: 220px 1fr auto; gap: 18px; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.template-row:last-child { border-bottom: 0; }
.template-row input { height: 40px; }
.template-row strong { font-size: 13px; }
.edit-template { min-height: 38px; padding: 0 14px; color: var(--blue); background: #edf5ff; border: 0; border-radius: 6px; cursor: pointer; }
.template-row.editing input { border-color: #73a7f4; background: #fff; }

.stats-grid { margin-bottom: 20px; }
.stat-card { display: grid; gap: 9px; min-height: 145px; padding: 22px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { font-size: 27px; letter-spacing: -.02em; }
.stat-card small { color: #8490a2; }
.dashboard-stats .stat-card { min-height: 125px; padding: 19px 20px; }
.dashboard-stats .stat-card strong { font-size: 24px; }
.empty-state { display: grid; place-items: center; padding: 50px 20px; text-align: center; }
.empty-state h2 { margin: 14px 0 0; }
.empty-state p { margin: 8px 0 0; color: var(--muted); }
.settings-row strong { flex: 1; }
.settings-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin: 0 0 13px; }
.settings-section-heading h2 { margin: 0; font-size: 16px; }
.settings-section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.settings-section-heading > span, .admin-badge { flex: 0 0 auto; padding: 5px 8px; color: #8c4a14; background: #fff3e8; border-radius: 5px; font-size: 10px; font-weight: 800; }
.agent-settings-heading { margin-top: 29px; }
.settings-copy { display: grid; gap: 4px; flex: 1; }
.settings-copy strong { font-size: 13px; }
.settings-copy small { color: var(--muted); font-size: 11px; line-height: 1.45; }
.settings-row .admin-badge { margin-left: auto; }
.settings-row .admin-badge + span { margin-left: 0; }

.login-page { min-height: 100vh; }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, .9fr) minmax(480px, 1.1fr); }
.login-brand-panel { display: flex; flex-direction: column; justify-content: space-between; padding: 42px clamp(35px, 6vw, 85px) 70px; color: white; background: linear-gradient(145deg, #10264d 0%, #173d79 60%, #2369c9 100%); }
.login-brand { padding: 0; }
.login-brand .brand-mark { color: white; border-color: rgba(255,255,255,.8); }
.login-brand span { color: rgba(255,255,255,.7); }
.login-brand-panel > div:last-child { max-width: 560px; }
.login-eyebrow { display: block; margin-bottom: 15px; color: #9fc5ff; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.login-brand-panel h1 { margin: 0; font-size: clamp(32px, 4.2vw, 52px); line-height: 1.08; letter-spacing: -.04em; }
.login-brand-panel p { max-width: 520px; margin: 20px 0 0; color: rgba(255,255,255,.75); font-size: 15px; line-height: 1.7; }
.login-form-panel { display: grid; place-items: center; padding: 35px; }
.login-card { width: min(430px, 100%); display: grid; gap: 20px; padding: 34px; background: white; border: 1px solid var(--border); border-radius: 15px; box-shadow: 0 20px 60px rgba(20,33,61,.1); }
.login-card h2 { margin: 0; font-size: 26px; letter-spacing: -.025em; }
.login-card p { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.login-card .btn { width: 100%; }
.login-card > small { color: var(--muted); text-align: center; }
.login-error { padding: 11px 13px; color: #a52a24; background: #fff0ef; border: 1px solid #f1c8c5; border-radius: 7px; font-size: 12px; }
.login-success { padding: 11px 13px; color: #176c3b; background: #eaf7ef; border: 1px solid #bee2cb; border-radius: 7px; font-size: 12px; line-height: 1.5; }
.login-password-row { display: flex; justify-content: flex-end; margin-top: -10px; }
.login-password-row a, .login-link { color: var(--blue); font-size: 12px; font-weight: 700; text-decoration: none; }
.login-link { text-align: center; }
.password-hint { margin: -9px 0 0 !important; font-size: 11px !important; line-height: 1.5; }

.admin-tabs { display: flex; gap: 7px; margin-bottom: 20px; padding: 5px; overflow-x: auto; background: #eaf0f7; border-radius: 9px; }
.admin-tabs button { min-height: 39px; display: flex; align-items: center; gap: 7px; padding: 0 15px; white-space: nowrap; color: #52617a; background: transparent; border: 0; border-radius: 7px; font-size: 12px; font-weight: 700; cursor: pointer; }
.admin-tabs button span { min-width: 20px; padding: 2px 5px; background: rgba(83,105,137,.12); border-radius: 10px; font-size: 10px; text-align: center; }
.admin-tabs button.active { color: var(--blue); background: white; box-shadow: 0 2px 8px rgba(30,52,83,.08); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.admin-panel-heading h2 { margin: 0; font-size: 17px; }
.admin-panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.admin-table-card { padding: 0; overflow: hidden; }
.admin-table-card table { width: 100%; border-collapse: collapse; }
.admin-table-card th, .admin-table-card td { padding: 14px 17px; border-bottom: 1px solid var(--border); text-align: left; font-size: 12px; vertical-align: middle; }
.admin-table-card th { color: #60708a; background: #f8fafc; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.admin-table-card tr:last-child td { border-bottom: 0; }
.admin-table-card td strong, .admin-table-card td small { display: block; }
.admin-table-card td small { margin-top: 3px; color: var(--muted); }
.admin-table-card code { color: #34527d; font-size: 11px; }
.status-pill { display: inline-block; padding: 4px 7px; color: #5a6679; background: #edf0f4; border-radius: 10px; font-size: 10px; font-weight: 800; }
.status-pill.active { color: #14703a; background: #e6f6ec; }
.status-pill.inactive, .status-pill.locked { color: #93401f; background: #fff0e9; }

.communications-screen { width: min(1500px, calc(100vw - 310px)); margin-left: 50%; transform: translateX(-50%); }
.selected-customer-pill { padding: 8px 11px; color: #315a91; background: #edf5ff; border-radius: 7px; font-size: 11px; font-weight: 700; }
.communication-layout { display: grid; grid-template-columns: 280px minmax(430px, 1fr) 300px; gap: 14px; align-items: start; }
.communication-panel { background: white; border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow); }
.communication-setup, .communication-history-panel { max-height: calc(100vh - 150px); overflow-y: auto; }
.communication-editor { padding: 18px; }
.communication-panel-heading { display: flex; align-items: center; gap: 10px; padding: 16px 17px; border-bottom: 1px solid var(--border); }
.communication-panel-heading > span { width: 27px; height: 27px; display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--blue); border-radius: 50%; font-size: 11px; font-weight: 800; }
.communication-panel-heading h2 { margin: 0; font-size: 15px; }
.communication-panel-heading p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.communication-section { display: grid; gap: 11px; padding: 15px 17px; border-bottom: 1px solid var(--border); }
.communication-section:last-child { border-bottom: 0; }
.communication-section h3 { margin: 0; font-size: 12px; }
.compact-customer-info dl { display: grid; gap: 8px; margin: 0; }
.compact-customer-info dl div { display: grid; grid-template-columns: 65px 1fr; gap: 8px; }
.compact-customer-info dt { color: var(--muted); font-size: 10px; }
.compact-customer-info dd { margin: 0; font-size: 11px; font-weight: 650; overflow-wrap: anywhere; }
.communication-type-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.communication-type-group label { display: block; }
.communication-type-group input { position: absolute; opacity: 0; pointer-events: none; }
.communication-type-group span { min-height: 36px; display: grid; place-items: center; color: #58677f; background: #f7f9fc; border: 1px solid var(--border); border-radius: 6px; font-size: 11px; cursor: pointer; }
.communication-type-group input:checked + span { color: var(--blue); background: #edf5ff; border-color: #8eb9f6; font-weight: 800; }
.communication-options { gap: 10px; }
.returned-money-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.communication-editor > label { margin-bottom: 14px; }
.communication-editor textarea { min-height: 270px; }
.merge-field-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.merge-field-row > span { margin-right: 3px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.merge-field-row button { padding: 5px 7px; color: #365f98; background: #edf5ff; border: 0; border-radius: 5px; font-size: 10px; cursor: pointer; }
.communication-workspace { overflow: hidden; background: #fff; border: 1px solid #d6deea; border-radius: 9px; }
.communication-workspace-heading { min-height: 47px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 9px; background: #f7f9fc; border-bottom: 1px solid #dfe5ee; }
.communication-workspace-heading > span { padding-right: 5px; color: var(--muted); font-size: 10px; }
.communication-view-toggle { display: inline-flex; gap: 3px; padding: 3px; background: #e8edf5; border-radius: 7px; }
.communication-view-toggle button { min-width: 74px; min-height: 32px; padding: 0 14px; color: #60708a; background: transparent; border: 0; border-radius: 5px; font-size: 11px; font-weight: 750; cursor: pointer; }
.communication-view-toggle button.active { color: var(--blue); background: #fff; box-shadow: 0 1px 5px rgba(30, 52, 83, .14); }
.communication-edit-view { padding: 14px 14px 0; }
.communication-edit-view > label { display: grid; gap: 7px; }
.communication-preview-view { padding: 10px; background: #f7f9fc; }
.communication-preview { min-height: 350px; padding: 28px 32px; color: #263650; background: #fff; border: 1px solid #ccd5e2; border-radius: 6px; white-space: pre-wrap; font-family: Georgia, "Times New Roman", serif; font-size: 13px; line-height: 1.65; }
.preview-qr { width: 76px; height: 76px; display: block; margin: 12px 0; background: repeating-conic-gradient(#17243a 0 25%, white 0 50%) 0 / 12px 12px; border: 5px solid white; outline: 1px solid #b8c2d1; }
.communication-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 15px; }
.communication-actions .btn { min-width: 0; padding: 10px 5px; font-size: 10px; white-space: nowrap; }
.ai-letter-helper { margin: 14px -14px 0; padding: 13px; background: #f7f5ff; border: 0; border-top: 1px solid #ded8ff; border-radius: 0; }
.ai-letter-helper > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ai-letter-helper strong { color: #4938b7; font-size: 12px; }
.ai-letter-helper small { color: var(--muted); font-size: 10px; }
.ai-letter-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.ai-letter-actions button { padding: 7px 9px; color: #4938b7; background: white; border: 1px solid #cbc3fa; border-radius: 7px; font-size: 10px; font-weight: 700; cursor: pointer; }
.ai-letter-actions button:hover { background: #f0edff; }
.ai-letter-actions button:disabled { opacity: .55; cursor: wait; }
.ai-working-status { display: flex; align-items: center; gap: 11px; margin-top: 12px; padding: 11px 12px; color: #4938b7; background: white; border: 1px solid #d7d0ff; border-radius: 8px; }
.ai-working-status[hidden] { display: none; }
.ai-working-status > span:last-child { display: grid; gap: 2px; }
.ai-working-status strong { font-size: 11px; }
.ai-working-status small { color: var(--muted); font-size: 10px; }
.ai-working-spinner { width: 20px; height: 20px; flex: 0 0 auto; border: 3px solid #ddd8ff; border-top-color: #654de4; border-radius: 50%; animation: aiSpin .8s linear infinite; }
@keyframes aiSpin { to { transform: rotate(360deg); } }
.ai-suggestion-modal { z-index: 70; }
.ai-suggestion-card { width: min(780px, 100%); }
.ai-suggestion-card .modal-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.ai-suggestion-card textarea { min-height: 360px; background: #fafbfe; line-height: 1.6; }
.ai-suggestion-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.communication-history { display: grid; }
.communication-history-item { display: grid; gap: 5px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.communication-history-item:last-child { border-bottom: 0; }
.communication-history-item header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.communication-history-item strong { font-size: 11px; }
.communication-history-item time, .communication-history-item small { color: var(--muted); font-size: 10px; }
.communication-history-status { padding: 3px 6px; border-radius: 8px; color: #176c3b; background: #eaf7ef; font-size: 9px; font-weight: 800; text-transform: capitalize; }
.communication-history-status.draft { color: #6a587c; background: #f1ecf8; }
.communication-history-status.failed { color: #a52a24; background: #fff0ef; }
.communication-empty { padding: 35px 18px; color: var(--muted); font-size: 11px; line-height: 1.5; text-align: center; }

.template-manager { position: fixed; inset: 0; z-index: 55; display: none; place-items: center; padding: 24px; }
.template-manager.open { display: grid; }
.template-manager-backdrop { position: absolute; inset: 0; background: rgba(20,33,61,.5); backdrop-filter: blur(2px); }
.template-manager-dialog { position: relative; width: min(1240px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden; background: white; border-radius: 14px; box-shadow: 0 25px 80px rgba(15,28,52,.28); }
.template-manager-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 23px; border-bottom: 1px solid var(--border); }
.template-manager-header > div > span { color: var(--blue); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.template-manager-header h2 { margin: 4px 0 0; font-size: 21px; }
.template-manager-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.template-manager-header > button { border: 0; background: transparent; font-size: 27px; line-height: 1; cursor: pointer; }
.template-manager-layout { min-height: 0; display: grid; grid-template-columns: minmax(560px, 1.25fr) minmax(380px, .75fr); }
.template-manager-list-panel { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.template-manager-list-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; }
.template-manager-list-heading h3 { margin: 0; font-size: 15px; }
.template-manager-list-heading small { display: block; margin-top: 3px; color: var(--muted); }
.template-manager-table-wrap { overflow: auto; }
.template-manager-table { width: 100%; border-collapse: collapse; }
.template-manager-table th, .template-manager-table td { padding: 12px 13px; border-top: 1px solid var(--border); text-align: left; font-size: 11px; vertical-align: middle; }
.template-manager-table th { position: sticky; top: 0; z-index: 1; color: #66758d; background: #f8fafc; font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.template-manager-table tr.selected td { background: #f2f7ff; }
.template-manager-table td:first-child strong, .template-manager-table td:first-child small { display: block; }
.template-manager-table td:first-child small { margin-top: 3px; color: var(--muted); }
.template-row-actions { display: flex; gap: 5px; }
.template-row-actions button { padding: 5px 7px; color: #3c5e8d; background: #edf5ff; border: 0; border-radius: 5px; font-size: 9px; font-weight: 700; cursor: pointer; }
.template-row-actions button.delete { color: #a5362e; background: #fff0ef; }
.template-manager-editor { min-width: 0; display: grid; align-content: start; gap: 15px; padding: 19px; overflow-y: auto; background: #fbfcfe; }
.template-editor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.template-editor-heading h3 { margin: 0; font-size: 16px; }
.template-editor-heading p { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.template-active-toggle { grid-template-columns: auto auto 1fr; align-items: center; gap: 8px; padding: 11px 12px; background: white; border: 1px solid var(--border); border-radius: 7px; }
.template-active-toggle input { width: 16px; height: 16px; accent-color: var(--blue); }
.template-active-toggle small { color: var(--muted); font-weight: 400; }
.template-editor-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding-top: 3px; }
.danger-button { color: #a5362e; border-color: #edc4c1; }

.modal { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 20px; }
.modal.open { display: grid; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,33,61,.45); backdrop-filter: blur(2px); }
.modal-card { position: relative; width: min(520px, 100%); display: grid; gap: 18px; padding: 24px; background: white; border-radius: 14px; box-shadow: 0 22px 70px rgba(16,30,54,.24); }
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-header button { border: 0; background: transparent; font-size: 25px; cursor: pointer; }
.portal-toast-region { position: fixed; z-index: 100; top: 82px; right: 20px; width: min(380px, calc(100vw - 40px)); display: grid; gap: 9px; pointer-events: none; }
.portal-toast { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; padding: 12px 13px; color: #273650; background: white; border: 1px solid var(--border); border-left: 4px solid var(--blue); border-radius: 10px; box-shadow: 0 14px 40px rgba(20,33,61,.16); animation: toastIn .2s ease; pointer-events: auto; }
.portal-toast > span { width: 26px; height: 26px; display: grid; place-items: center; color: white; background: var(--blue); border-radius: 50%; font-size: 12px; font-weight: 800; }
.portal-toast p { margin: 0; font-size: 12px; line-height: 1.45; }
.portal-toast button { padding: 0; color: #8793a7; background: transparent; border: 0; font-size: 20px; cursor: pointer; }
.portal-toast.success { border-left-color: var(--green); }
.portal-toast.success > span { background: var(--green); }
.portal-toast.error { border-left-color: #cf3d35; }
.portal-toast.error > span { background: #cf3d35; }
.portal-toast.leaving { opacity: 0; transform: translateX(12px); transition: .18s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateX(14px); } }
.portal-dialog { z-index: 90; }
.portal-dialog-card { width: min(450px, 100%); grid-template-columns: 48px 1fr; align-items: start; }
.portal-dialog-icon { width: 44px; height: 44px; display: grid; place-items: center; color: white; background: var(--blue); border-radius: 12px; font-size: 20px; font-weight: 800; }
.portal-dialog-icon.danger { background: #cf3d35; }
.portal-dialog-card h2 { margin: 1px 0 7px; font-size: 19px; }
.portal-dialog-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.portal-dialog-card label, .portal-dialog-actions { grid-column: 1 / -1; }
.portal-dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }
.portal-dialog-actions .btn.danger { background: #cf3d35; border-color: #cf3d35; }

.script-drawer { position: fixed; inset: 0; z-index: 45; visibility: hidden; pointer-events: none; }
.script-drawer.open { visibility: visible; pointer-events: auto; }
.script-drawer-backdrop { position: absolute; inset: 0; background: rgba(20,33,61,.28); opacity: 0; transition: opacity .2s ease; }
.script-drawer.open .script-drawer-backdrop { opacity: 1; }
.script-drawer-panel { position: absolute; inset: 0 0 0 auto; width: min(460px, 100%); display: flex; flex-direction: column; gap: 20px; padding: 24px; overflow-y: auto; background: white; box-shadow: -16px 0 45px rgba(20,33,61,.16); transform: translateX(100%); transition: transform .22s ease; }
.script-drawer.open .script-drawer-panel { transform: translateX(0); }
.script-drawer-header { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 17px; border-bottom: 1px solid var(--border); }
.script-drawer-header span { color: var(--blue); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.script-drawer-header h2 { margin: 5px 0 0; font-size: 22px; }
.script-drawer-header button { border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; }
.script-drawer-customer { display: grid; gap: 4px; padding: 14px 16px; background: #f6f9fd; border: 1px solid var(--border); border-radius: 9px; }
.script-drawer-customer span, .script-drawer-customer small { color: var(--muted); font-size: 11px; }
.script-drawer-customer strong { font-size: 14px; }
.script-content { padding: 19px; background: #fbfcfe; border: 1px solid var(--border); border-radius: 10px; }
.script-title-label { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.script-content h3 { margin: 7px 0 15px; font-size: 16px; }
.script-content div { color: #33425d; font-size: 14px; line-height: 1.7; white-space: pre-line; }
.script-drawer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; padding-top: 4px; }

@media (max-width: 1050px) {
    .quick-grid, .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .action-grid { grid-template-columns: repeat(2, 1fr); }
    .content-wrap { padding-inline: 28px; }
    .customer-row { grid-template-columns: 1.2fr .9fr 1fr 20px; }
    .customer-row span:nth-child(4) { display: none; }
    .communications-screen { width: 100%; margin-left: 0; transform: none; }
    .communication-layout { grid-template-columns: 250px 1fr; }
    .communication-history-panel { grid-column: 1 / -1; max-height: none; }
    .communication-history { grid-template-columns: repeat(2, 1fr); }
    .template-manager-layout { grid-template-columns: 1fr; overflow-y: auto; }
    .template-manager-list-panel { border-right: 0; border-bottom: 1px solid var(--border); }
    .template-manager-table-wrap { max-height: 330px; }
}

@media (max-width: 760px) {
    .login-shell { grid-template-columns: 1fr; }
    .login-brand-panel { min-height: 280px; padding: 30px 25px 38px; }
    .login-brand-panel h1 { font-size: 32px; }
    .login-form-panel { padding: 25px 18px; }
    .login-card { padding: 24px; }
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 15px 0 35px rgba(20,33,61,.13); }
    .sidebar.open { transform: translateX(0); }
    .main-area { width: 100%; margin-left: 0; }
    .topbar { padding: 0 18px; }
    .menu-toggle { display: block; }
    .content-wrap { padding: 28px 18px 55px; }
    .hero-card { align-items: flex-start; flex-wrap: wrap; }
    .hero-card .btn { width: 100%; margin-left: 0; }
    .activity-choice-grid { grid-template-columns: 1fr; }
    .action-grid, .snapshot-details { grid-template-columns: 1fr; }
    .communication-layout { grid-template-columns: 1fr; }
    .communication-setup, .communication-history-panel { max-height: none; }
    .communication-history-panel { grid-column: auto; }
    .communication-history { grid-template-columns: 1fr; }
    .topbar-customer { min-width: 0; padding: 6px; }
    .topbar-customer > span:not(.customer-avatar) { display: none; }
    .communication-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .address-grid { grid-template-columns: 1fr; }
    .form-span-2, .address-grid .form-span-2 { grid-column: auto; }
    .payment-customer-summary { grid-template-columns: 1fr; gap: 10px; }
    .customer-row { grid-template-columns: 1fr 20px; }
    .customer-row > span:not(:last-child) { display: none; }
    .template-row { grid-template-columns: 1fr auto; }
    .template-row input { grid-column: 1 / -1; }
    .page-heading { align-items: stretch; flex-direction: column; }
    .page-heading > .btn { width: 100%; }
    .heading-actions { justify-content: space-between; }
    .settings-row .admin-badge { display: none; }
    .admin-panel-heading { align-items: stretch; flex-direction: column; }
    .admin-panel-heading .btn { width: 100%; }
    .admin-table-card { overflow-x: auto; }
    .admin-table-card table { min-width: 650px; }
}

@media (max-width: 520px) {
    .quick-grid, .stats-grid { grid-template-columns: 1fr; }
    .agent-menu span:nth-child(2), .help-button span { display: none; }
    .card { padding: 17px; }
    .search-row { flex-direction: column; }
    .search-row .btn { width: 100%; }
    .snapshot-primary { align-items: flex-start; flex-wrap: wrap; }
    .balance { width: 100%; margin-left: 54px; text-align: left; }
    .channel-grid { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .communication-actions { grid-template-columns: 1fr 1fr; }
    .template-manager { padding: 10px; }
    .template-manager-dialog { max-height: calc(100vh - 20px); }
    .template-manager-list-heading { align-items: stretch; flex-direction: column; }
    .template-manager-table { min-width: 660px; }
    .template-editor-actions { grid-template-columns: 1fr; }
}

@media print {
    body * { visibility: hidden !important; }
    #communication-preview, #communication-preview * { visibility: visible !important; }
    #communication-preview { position: absolute; inset: 0; width: 100%; min-height: 100vh; padding: .75in; border: 0; box-shadow: none; font-size: 12pt; }
}
