:root {
    color-scheme: light;
    --blue-950: #062a4d;
    --blue-800: #084b82;
    --blue-100: #eaf3fa;
    --green-700: #087a49;
    --green-100: #e9f7f0;
    --red-700: #a62929;
    --red-100: #fcecec;
    --amber-700: #9a5b09;
    --amber-100: #fff5df;
    --ink: #1c2733;
    --muted: #667382;
    --line: #dbe3ec;
    --surface: #ffffff;
    --background: #f4f7fa;
    --shadow: 0 12px 35px rgba(6, 42, 77, .08);
}

* { box-sizing: border-box; }
html { font-family: Inter, "Segoe UI", Arial, sans-serif; background: var(--background); color: var(--ink); }
body { margin: 0; min-height: 100vh; }
a { color: var(--blue-800); }

.topbar {
    min-height: 72px;
    padding: 12px clamp(18px, 5vw, 64px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    background: var(--blue-950);
    color: white;
    box-shadow: 0 4px 18px rgba(6, 42, 77, .2);
}
.brand { display: flex; align-items: center; gap: 11px; color: white; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: #18a96b; font-weight: 800; font-size: 21px; }
.brand strong, .brand small { display: block; }
.brand small { color: #bdd3e6; margin-top: 2px; font-size: 12px; }
.topbar nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar nav a, .link-button { color: #dceaf5; text-decoration: none; padding: 9px 11px; border-radius: 8px; font: inherit; font-size: 14px; }
.topbar nav a:hover, .link-button:hover { background: rgba(255,255,255,.1); color: white; }
.inline-form { display: inline; margin: 0; }
.link-button { border: 0; background: transparent; cursor: pointer; }

.page-shell { width: min(1180px, calc(100% - 32px)); margin: 38px auto 64px; }
.auth-shell { width: min(470px, calc(100% - 32px)); min-height: calc(100vh - 100px); display: grid; align-content: center; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 22px; }
.page-heading h1 { margin: 0 0 5px; color: var(--blue-950); font-size: clamp(26px, 4vw, 36px); letter-spacing: -.02em; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--green-700); text-transform: uppercase; font-weight: 800; font-size: 12px; letter-spacing: .12em; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 24px; }
.auth-card { padding: 32px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-logo .brand-mark { color: white; }
.auth-logo h1 { font-size: 23px; margin: 0; color: var(--blue-950); }
.auth-logo p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.stat span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat strong { color: var(--blue-950); font-size: 29px; }

.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; flex: 1; max-width: 560px; }
.filter-form { max-width: 760px; }
.filter-form input { flex: 1.35; }
.filter-form select { flex: 1; min-width: 190px; }
input, select, textarea, button { font: inherit; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
    width: 100%; border: 1px solid #cbd6e2; border-radius: 9px; padding: 11px 12px; background: white; color: var(--ink); outline: none;
}
input[type="date"] { width: 100%; border: 1px solid #cbd6e2; border-radius: 9px; padding: 10px 12px; background: white; color: var(--ink); outline: none; }
input:focus, select:focus, textarea:focus { border-color: #3992ce; box-shadow: 0 0 0 3px rgba(57,146,206,.14); }
label { display: block; font-weight: 700; font-size: 14px; margin: 0 0 7px; color: #263849; }
.field { margin-bottom: 17px; }
.field small { display: block; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.checkbox { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.checkbox input { width: 18px; height: 18px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 0; border-radius: 9px; padding: 11px 16px; background: var(--blue-800); color: white; font-weight: 750; cursor: pointer; text-decoration: none; }
.button:hover { filter: brightness(.94); }
.button-success { background: var(--green-700); }
.button-danger { background: var(--red-700); }
.button-secondary { background: #e8eef4; color: var(--blue-950); }
.button-small { padding: 8px 11px; font-size: 13px; }
.button-block { width: 100%; }
.card-medium { max-width: 800px; }
.card-narrow { max-width: 620px; }
.actions-spaced { margin-top: 16px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; background: white; }
th { background: #edf3f8; color: #38516a; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 12px 14px; }
td { padding: 14px; border-top: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: #fbfdff; }
.customer-name { font-weight: 750; color: var(--blue-950); text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-weight: 750; font-size: 12px; white-space: nowrap; }
.badge-info { background: var(--blue-100); color: var(--blue-800); }
.badge-success { background: var(--green-100); color: var(--green-700); }
.badge-danger { background: var(--red-100); color: var(--red-700); }
.badge-warning { background: var(--amber-100); color: var(--amber-700); }
.badge-muted { background: #edf0f3; color: #5c6671; }
.product-badge { display: inline-flex; border-radius: 8px; padding: 5px 9px; font-weight: 850; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.product-basic { background: #e8f1ff; color: #144f91; }
.product-pro { background: #f1e9ff; color: #6734a5; }
.product-dee { background: #dff8ef; color: #08755e; }
.product-section { border-top: 4px solid #2375bd; }
.product-section.is-pro { border-top-color: #7546b8; }
.product-section.is-dee { border-top-color: #0a8f72; }
.product-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.product-heading h2 { margin: 0; }
.customer-summary { margin-bottom: 20px; }
.product-section { margin-top: 20px; scroll-margin-top: 94px; }
.product-heading > div:first-child { display: grid; gap: 8px; }
.product-detail-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(290px, .65fr); gap: 18px; margin-top: 22px; }
.subcard { padding: 19px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdff; }
.subcard h3 { margin: 0 0 16px; color: var(--blue-950); font-size: 16px; }
.section-actions { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.commercial-card { background: #f7f9fc; }
.history-card { margin-top: 20px; }

.alert { border-radius: 11px; padding: 13px 15px; margin: 0 0 18px; border: 1px solid; line-height: 1.45; }
.alert-success { background: var(--green-100); color: #075c38; border-color: #9bd4ba; }
.alert-error { background: var(--red-100); color: #842323; border-color: #efb2b2; }
.alert-warning { background: var(--amber-100); color: #754307; border-color: #e9c477; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; }
.card h2 { margin: 0 0 16px; color: var(--blue-950); font-size: 19px; }
.definition { display: grid; grid-template-columns: 145px 1fr; gap: 10px 16px; margin: 0; }
.definition dt { color: var(--muted); }
.definition dd { margin: 0; font-weight: 650; word-break: break-word; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); gap: 22px; align-items: start; }
.button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; }
.token-box { background: #0b2741; color: #e3f4ff; border-radius: 12px; padding: 16px; word-break: break-all; font-family: Consolas, monospace; font-size: 13px; }
.reconnect-result { margin-bottom: 20px; border-color: #9bd4ba; }
.reconnect-result h2 { margin-top: 6px; }
.copy-row { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 10px; align-items: stretch; margin: 16px 0 10px; }
.copy-row .token-box { width: 100%; border: 0; font-size: 20px; font-weight: 800; letter-spacing: .12em; text-align: center; }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }
.footer span { color: var(--green-700); padding: 0 5px; }

.ticket-filter { max-width: 920px; }
.ticket-row-new td { background: #f0f7ff; }
.ticket-status { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-weight: 750; font-size: 12px; white-space: nowrap; background: var(--blue-100); color: var(--blue-800); }
.ticket-status-in_progress { background: #e9eeff; color: #3c4ca1; }
.ticket-status-waiting_customer { background: var(--amber-100); color: var(--amber-700); }
.ticket-status-resolved, .ticket-status-closed { background: var(--green-100); color: var(--green-700); }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .55fr); gap: 20px; align-items: start; }
.admin-ticket-thread { display: grid; gap: 15px; }
.admin-ticket-message { width: min(90%, 760px); padding: 17px 18px; border: 1px solid var(--line); border-radius: 13px; background: #f8fbfe; }
.admin-ticket-message.is-admin { margin-left: auto; background: #eef5ff; border-color: #b5cdf1; }
.admin-ticket-message header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 11px; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.admin-ticket-message header b { color: var(--blue-950); font-size: 13px; }
.admin-ticket-message header time { color: var(--muted); font-size: 11px; }
.admin-ticket-message > div { line-height: 1.65; }
.admin-ticket-message footer { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.admin-ticket-message footer a { padding: 7px 9px; border-radius: 7px; color: var(--blue-800); background: white; font-size: 12px; text-decoration: none; }
.ticket-reply-form { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.ticket-reply-actions { display: flex; align-items: end; justify-content: space-between; gap: 15px; }
.ticket-reply-actions label { min-width: 230px; margin: 0; }

.finance-note { margin-bottom: 22px; }
.finance-filters { margin-bottom: 22px; }
.finance-filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.finance-filter-grid .field { margin-bottom: 2px; }
.finance-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.finance-stats .stat strong { font-size: clamp(19px, 2.2vw, 27px); }
.finance-stats .stat small { display: block; color: var(--muted); margin-top: 7px; }
.finance-product-summary { margin-top: 22px; }

.campaign-create-card { margin-bottom: 22px; }
.campaign-section-heading { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.campaign-section-heading h2 { margin: 4px 0 6px; }
.campaign-form textarea { line-height: 1.55; }
.campaign-stats .campaign-status-text { font-size: 21px; }
.campaign-detail-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .6fr); gap: 20px; align-items: start; }
.campaign-definition { margin-bottom: 20px; }
.campaign-message-preview { min-height: 150px; padding: 18px; border: 1px solid var(--line); border-radius: 11px; background: #f8fbfd; line-height: 1.65; white-space: normal; }
.campaign-action-stack { display: grid; gap: 10px; }
.campaign-queue-note { margin: 18px 0 0; }

@media (max-width: 820px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .detail-grid, .form-grid, .product-detail-grid, .ticket-layout, .campaign-detail-grid { grid-template-columns: 1fr; }
    .finance-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .finance-stats { grid-template-columns: repeat(2, 1fr); }
    .ticket-reply-actions { align-items: stretch; flex-direction: column; }
    .ticket-reply-actions label, .ticket-reply-actions .button { width: 100%; }
    .copy-row { grid-template-columns: 1fr; }
    .definition { grid-template-columns: 1fr; gap: 3px; }
    .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .stats { grid-template-columns: 1fr; }
    .page-shell { width: min(100% - 20px, 1180px); margin-top: 22px; }
    .card, .auth-card { padding: 18px; border-radius: 12px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .search-form { width: 100%; }
    .admin-ticket-message { width: 100%; }
    .admin-ticket-message header { align-items: flex-start; flex-direction: column; gap: 4px; }
    .finance-filter-grid, .finance-stats { grid-template-columns: 1fr; }
}
