/* RSA CRM — admin theme (custom, no framework). */
:root {
    --accent: #206bc4;
    --accent-dark: #1a579e;
    --ink: #1f2933;
    --muted: #6b7280;
    --line: #e6e8ec;
    --line-soft: #f0f1f3;
    --bg: #f5f6f8;
    --card: #ffffff;
    --danger: #c0392b;
    --radius: 7px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
}

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

/* ---- App shell ---- */
body.app { display: flex; align-items: stretch; min-height: 100vh; }
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.sidebar {
    width: 216px;
    flex-shrink: 0;
    background: #1d273b;
    color: #aab4c8;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar a.brand:hover { background: rgba(255,255,255,.05); text-decoration: none; }
.sidebar nav { padding: 8px 0; flex: 1; }
.sidebar nav a {
    display: block;
    padding: 9px 18px;
    color: #aab4c8;
    font-size: 14px;
    border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(32,107,196,.18); color: #fff; border-left-color: var(--accent); }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar-foot .who { color: #8a94a8; margin-bottom: 6px; }
.sidebar-foot a { color: #cdd4e0; }

.content { flex: 1; min-width: 0; padding: 20px 24px; }
body.auth .content { flex: none; width: 100%; max-width: 400px; padding: 0 16px; }

/* ---- Кабінет користувача (public) ---- */
body.cab { display: block; min-height: 100vh; background: var(--bg); }
body.cab .content { width: 100%; margin: 0 auto; padding: 24px 20px; }
.cab-head {
    display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.cab-head > strong { font-size: 18px; }
.cab-head > div { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cab-title { margin-bottom: 2px; }
.cab-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cab-card h4 { margin: 0 0 6px; font-size: 15px; }

/* Список послуг кабінету */
.svc-box { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 12px 0; }
.svc-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; margin: 0; cursor: pointer; border-bottom: 1px solid var(--line-soft); }
.svc-row:last-child { border-bottom: none; }
.svc-row:hover { background: #fafbfc; }
.svc-row:has(input:checked) { background: rgba(32,107,196,.05); }
.svc-row input { width: 18px; height: 18px; margin: 0; flex-shrink: 0; }
.svc-ic { display: flex; color: var(--muted); flex-shrink: 0; }
.svc-main { flex: 1; min-width: 0; }
.svc-nm { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-ty { display: block; font-size: 12px; color: var(--muted); }
.svc-pr { font-weight: 600; white-space: nowrap; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
.chip-ok { background: #e7f6ec; color: #1e7d34; }
.chip-soon { background: #fdf0d5; color: #b9770e; }
.chip-overdue { background: #fbe3e3; color: var(--danger); }
.chip-none { background: #f0f1f3; color: var(--muted); }

/* Панель оплати */
.pay-bar {
    position: sticky; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; margin-top: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.08); font-size: 15px;
}
.pay-bar button { padding: 10px 24px; font-size: 15px; }

/* Способи оплати — рівні рядки-спойлери (акордеон) */
.pay-acc { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; }
.pay-acc h3 { margin-bottom: 2px; }
.pay-acc .pay-row {
    display: flex; align-items: center; gap: 10px;
    width: 100%; box-sizing: border-box; height: 52px; padding: 0 16px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink); text-decoration: none;
    font-family: inherit; text-align: left;
}
.pay-acc .pay-row:hover { background: #f7f8fa; text-decoration: none; }
.pay-row > .pi, .pay-row > .pe { flex: 0 0 auto; display: flex; align-items: center; color: var(--muted); }
.pay-row > .pt { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-row > .pe { margin-left: auto; }
.chev { transition: transform .15s; }
.pay-item.open .pay-row { border-color: var(--accent); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.pay-item.open .chev { transform: rotate(180deg); color: var(--accent); }
.pay-item .pay-content { display: none; }
.pay-item.open .pay-content {
    display: block; border: 1px solid var(--accent); border-top: none;
    border-radius: 0 0 var(--radius) var(--radius); padding: 12px 16px; background: var(--card);
}
.reqs { font-size: 14px; line-height: 1.8; word-break: break-word; }

/* Договір-оферта */
.oferta { line-height: 1.6; }
.oferta h1 { font-size: 22px; }
.oferta h3 { margin-top: 22px; font-size: 16px; }
.oferta p { margin: 8px 0; }
.oferta ul { margin: 8px 0; padding-left: 20px; }
.oferta li { margin: 4px 0; }

@media (max-width: 520px) {
    .svc-ic { display: none; }
    .svc-pr { font-size: 13px; }
}

/* ---- Headings ---- */
h1, h2, h3, h4 { margin: 0 0 .3rem; font-weight: 600; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
hgroup { margin-bottom: 18px; }
hgroup h2, hgroup h3 { margin-bottom: 2px; }
.muted { color: var(--muted); }
small.muted { font-size: 12px; }

/* ---- Cards (article) ---- */
article {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
}
article > header {
    font-weight: 600;
    margin: -14px -16px 12px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
.sort-ind { color: var(--accent); font-size: 11px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }

/* ---- Buttons ---- */
button, [role="button"], a.button {
    display: inline-block;
    font-size: 13px;
    font-family: inherit;
    padding: 7px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: #fff;
    color: #374151;
    cursor: pointer;
    line-height: 1.3;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
button:hover, [role="button"]:hover, a.button:hover { background: #f3f4f6; text-decoration: none; }
button:active { transform: translateY(1px); }

button[type="submit"], .primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
button[type="submit"]:hover, .primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.secondary { color: var(--muted); }
.contrast { color: var(--danger); border-color: #e3b4b4; }
.contrast:hover { background: #fbeeee; }
.outline { background: #fff; }

.row-actions button, .row-actions [role="button"] { padding: 4px 10px; font-size: 12px; margin-left: 4px; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; color: #374151; margin-bottom: 12px; }
input, select, textarea {
    display: block;
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    padding: 7px 9px;
    margin-top: 4px;
    border: 1px solid #d3d7de;
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
}
input[type="checkbox"] { width: auto; display: inline-block; margin: 0 6px 0 0; vertical-align: -1px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(32,107,196,.12); }
input[readonly] { background: #f3f4f6; color: var(--muted); }
textarea { min-height: 60px; }

/* ---- Layout helpers ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: start; }
[role="group"] { display: inline-flex; gap: 6px; }

/* ---- Status colors ---- */
.u-overdue { color: var(--danger); font-weight: 600; }
.u-soon { color: #b9770e; font-weight: 600; }
.u-ok { color: #1e7d34; }
.u-none { color: var(--muted); }

/* ---- Row tint by term proximity (warm = urgent, cool = far) ---- */
.row-overdue td { background: #f4b4b4; }
.row-overdue:hover td { background: #efa0a0; }
.row-d14 td { background: #ffcda6; }
.row-d14:hover td { background: #ffbd8c; }
.row-d30 td { background: #ffeaa6; }
.row-d30:hover td { background: #ffe187; }
.row-d60 td { background: #e6f1a8; }
.row-d60:hover td { background: #dbe98c; }
.row-d90 td { background: #c4eccb; }
.row-d90:hover td { background: #aee3b7; }
.row-far td { background: #c7e6f2; }
.row-far:hover td { background: #aedaea; }

/* ---- Tabs (огляд: Хостинг / Домени) ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
    background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0;
    padding: 9px 16px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
}
.tabs button:hover { background: none; color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button:active { transform: none; }
.tab-count { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 2px; }
.tabs .ov-filter { width: 560px; max-width: 50vw; margin: 0 0 6px auto; align-self: center; }

/* Домени клієнта в рядку хостингу */
.cdom { display: block; font-size: 12px; white-space: nowrap; line-height: 1.5; }

/* Галочка «email підтверджено» */
.mail-ok { color: #1e7d34; font-weight: 700; }

/* Колонка «Контакти»: email + телефони з іменами і месенджерами */
.mail-line { display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph-name { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.2; }
.ph-line { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.im { display: inline-flex; align-items: center; }
.im svg { width: 15px; height: 15px; }
.im-tg { color: #229ED9; }
.im-vb { color: #7360F2; }
.im:hover { opacity: .75; }

/* Форма телефонів у редагуванні клієнта */
.cf-ph { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.cf-ph input { margin: 0; font-size: 13px; padding: 5px 7px; }

/* Клітинка «Повідомлення» */
.msg-cell { display: inline-flex; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.msg-cell svg { width: 17px; height: 17px; }
.msg-cell:hover { color: var(--accent); background: #eef0f3; }

/* Кнопка «+ оплата» під ціною */
.pay-add { display: block; font-size: 11px; color: var(--accent); cursor: pointer; margin-top: 2px; }
.pay-add:hover { text-decoration: underline; }

/* Борг у колонці «Залишилось» */
.debt-cell { display: block; font-size: 12px; font-weight: 600; color: var(--danger); cursor: pointer; margin-top: 2px; white-space: nowrap; }
.debt-cell:hover { text-decoration: underline; }
.debt-cell.nodebt { color: var(--muted); font-weight: 400; opacity: .65; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Icon button (дії в рядку) ---- */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; padding: 0; margin-right: 4px;
    border: 1px solid transparent; background: none; color: var(--muted);
    border-radius: 6px; vertical-align: middle;
}
.icon-btn:hover { background: #eef0f3; color: var(--ink); border-color: var(--line); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---- Custom tooltip (JS, position:fixed — не обрізається overflow-контейнером) ---- */
#tip {
    position: fixed; z-index: 9999; max-width: 280px;
    background: #1d273b; color: #fff; font-size: 12px; font-weight: 400; line-height: 1.35;
    padding: 5px 9px; border-radius: 6px; white-space: normal;
    box-shadow: 0 3px 12px rgba(0,0,0,.24); pointer-events: none;
    opacity: 0; transition: opacity .1s ease;
}
#tip.show { opacity: 1; }

/* ---- Клікабельний ПІБ клієнта (відкриває редагування) ---- */
.client-edit { color: var(--accent); cursor: pointer; }
.client-edit:hover { text-decoration: underline; }
.client-edit-plain { color: inherit; display: inline-block; }
.client-edit-plain:hover { text-decoration: none; opacity: .75; }

/* ---- "Інше" (контактна нотатка) — повний текст, без обрізання ---- */
.extra-full { display: inline-block; max-width: 320px; white-space: pre-wrap; word-break: break-word; }

/* ---- Об'єднання клієнтів (пари дублів) ---- */
.merge-pair { padding: 0; overflow: hidden; }
.merge-cols { display: flex; }
.merge-col {
    flex: 1; display: flex; gap: 10px; align-items: flex-start;
    padding: 14px 16px; margin: 0; cursor: pointer; border-right: 1px solid var(--line);
}
.merge-col:last-of-type { border-right: none; }
.merge-col input[type="radio"] { margin: 3px 0 0; }
.merge-col:has(input:checked) { background: rgba(32,107,196,.06); }
.merge-foot {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 11px 16px; border-top: 1px solid var(--line); background: #fafbfc;
}
@media (max-width: 640px) {
    .merge-cols { flex-direction: column; }
    .merge-col { border-right: none; border-bottom: 1px solid var(--line); }
}

/* ---- Overview flash ---- */
.ov-flash { padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.ov-flash.ok  { background: #e7f6ec; color: #1e7d34; border: 1px solid #bfe3c9; }
.ov-flash.err { background: #fbeeee; color: var(--danger); border: 1px solid #e3b4b4; }

/* ---- Metric cards on dashboard ---- */
.grid > article { margin-bottom: 0; }
.grid > article h3 { font-size: 26px; margin-bottom: 0; }

/* ---- Modal + chat (коментарі) ---- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; max-width: 560px; width: 92%; background: var(--card); color: var(--ink); overflow: visible; }
dialog .flatpickr-calendar { z-index: 10000; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog > article { margin: 0; border: none; }
.comment-cell { display: inline-block; max-width: 300px; white-space: pre-wrap; word-break: break-word; vertical-align: top; }
.chat { max-height: 50vh; overflow-y: auto; margin-bottom: 12px; }
.cbubble { background: #f3f5f8; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; }
.cbubble.pinned { background: #fff7e0; border-color: #f0d98a; }
.cmeta { font-size: 12px; color: var(--muted); margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.cact { margin-left: auto; white-space: nowrap; display: flex; gap: 4px; align-items: center; }
.pin-btn { text-decoration: none; font-size: 13px; line-height: 1; }
.pin-btn:hover { text-decoration: none; }
.pin-btn.off { filter: grayscale(1); opacity: .35; }
.pin-btn.off:hover { opacity: .8; }
.cicon { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 5px; color: var(--muted); }
.cicon svg { width: 14px; height: 14px; }
.cicon:hover { background: #eef0f3; color: var(--ink); text-decoration: none; }
.cicon-del:hover { background: #fbeeee; color: var(--danger); }
.cbody { font-size: 14px; white-space: pre-wrap; }
.chat-add textarea { margin-bottom: 6px; }

/* ---- Small screens ---- */
@media (max-width: 760px) {
    body.app { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: column; }
    .sidebar nav { display: flex; flex-wrap: wrap; padding: 4px; }
    .sidebar nav a { border-left: none; border-radius: var(--radius); padding: 7px 12px; }
    .sidebar nav a.active { border-left: none; }
    .content { padding: 14px; }
}
