/* EkoDreams — UI стил */
:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #16212f;
  --ink-2: #5b6b7d;
  --line: #e3e8ef;
  --brand: #1d4ed8;
  --brand-2: #1e40af;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --ok: #16a34a;
  --side: #101828;
  --side-ink: #cbd5e1;
  --radius: 10px;
}
* { box-sizing: border-box; }
/* Бутоните ни имат display, който иначе надвива вграденото поведение на hidden. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14.5px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; max-width: 100%; overflow-x: clip; }

/* ------------------------------- Sidebar ------------------------------ */
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; }
a.brand:hover { text-decoration: none; }
a.brand:hover .brand-name { color: #fff; opacity: 0.85; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; font-size: 22px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.brand-mark.big { width: 56px; height: 56px; font-size: 32px; margin: 0 auto 12px; }
.brand-name { font-weight: 600; color: #fff; font-size: 16px; }
.company-switch { padding: 0 12px 10px; }
.company-switch select {
  width: 100%; background: rgba(255,255,255,0.08); color: #fff; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 7px 8px; font-size: 13px;
}
/* Windows рисува списъка на option със светъл фон; цветът от select (#fff) ги прави невидими. */
.company-switch select option {
  color: var(--ink);
  background-color: #fff;
}
.company-switch-label { font-size: 12px; color: #94a3b8; padding: 0 4px; }
.sidebar nav { flex: 1; padding: 8px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; color: var(--side-ink);
  padding: 10px 12px; border-radius: 8px; margin-bottom: 2px; font-size: 14px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar nav .ic { width: 20px; text-align: center; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-chip { color: #fff; font-weight: 600; margin-bottom: 4px; }
.link-quiet { color: var(--side-ink); font-size: 13px; }
.link-quiet.ver { float: right; opacity: 0.65; }

/* -------------------------------- Main -------------------------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 12px 22px; position: sticky; top: 0; z-index: 5;
}
/* min-width: 0 позволява на заглавието да се свие, вместо да разпъне бара.
   Логото след него е с auto полета — застава по средата на празното място. */
.topbar h1 { font-size: 18px; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.burger { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.45); }
.lang-switch { display: flex; gap: 4px; }
.lang-switch button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
  padding: 4px 9px; cursor: pointer; font-size: 12px; color: var(--ink-2);
}
.lang-switch button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.content { padding: 22px; max-width: 1180px; width: 100%; margin: 0 auto; min-width: 0; }

/* ------------------------------- Panels ------------------------------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; min-width: 0; overflow-wrap: anywhere;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; color: var(--ink); }
/* Заглавие с действие вдясно (напр. „Напомняния  + Ново"). */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h2 { margin: 0 0 12px; }
/* Предложените клаузи по договор: едно цъкане ги превръща в напомняне. */
.suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.suggest p { margin: 0; width: 100%; }
.btn-chip {
  background: var(--panel); border: 1px dashed var(--line); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.btn-chip:hover { border-style: solid; border-color: var(--accent); color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.card.warn { border-left: 4px solid var(--danger); }
/* Картите на началната страница водят към съответния списък. */
a.card { display: block; color: inherit; transition: border-color .15s ease, box-shadow .15s ease; }
a.card:hover { text-decoration: none; border-color: var(--brand); box-shadow: 0 2px 12px rgba(29, 78, 216, 0.12); }
a.card.warn:hover { border-left-color: var(--danger); }
.card-label { color: var(--ink-2); font-size: 12.5px; }
.card-num { font-size: 26px; font-weight: 700; margin: 2px 0; }
.card-sub { color: var(--ink-2); font-size: 13px; }

/* ------------------------------- Tables ------------------------------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; color: var(--ink-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.kv td:first-child { color: var(--ink-2); width: 160px; }
.tbl tr.inactive td { opacity: 0.5; }
.tbl tr.totals td { font-weight: 600; background: #f8fafc; }
/* Цял ред като връзка към документа. */
tr[data-href] { cursor: pointer; }
tr[data-href]:hover > td { background: #f7f9fc; }
/* Името взима свободното място, останалите колони не се пренасят. */
.tbl.stack td.c-name { width: 99%; }
.tbl.stack td:not(.c-name) { white-space: nowrap; }
.red { color: var(--danger); } .green { color: var(--ok); }
.quiet { color: var(--ink-2); font-size: 13px; }
tr.is-current td { background: #eff6ff; }
.seller-mode { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.mono { font-family: Consolas, monospace; font-size: 12px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; background: #eef2f7; color: var(--ink-2); }
.b-draft { background: #f1f5f9; color: #475569; }
.b-sent { background: #dbeafe; color: #1e40af; }
.b-accepted { background: #dcfce7; color: #166534; }
.b-rejected { background: #fee2e2; color: #991b1b; }
.b-converted { background: #ede9fe; color: #5b21b6; }
.b-active { background: #dcfce7; color: #166534; }
.b-suspended { background: #fef3c7; color: #92400e; }
.b-expired { background: #f1f5f9; color: #475569; }
.b-terminated { background: #fee2e2; color: #991b1b; }
.b-pending { background: #fef3c7; color: #92400e; }
.b-snoozed { background: #e0e7ff; color: #3730a3; }
.b-done { background: #dcfce7; color: #166534; }
.b-cancelled { background: #f1f5f9; color: #475569; }

/* -------------------------------- Forms ------------------------------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.form-grid .span2 { grid-column: span 2; }
.form-grid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 14px; }
.form-grid legend { font-size: 12.5px; color: var(--ink-2); padding: 0 6px; }
input, select, textarea {
  font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(29, 78, 216, 0.25); border-color: var(--brand); }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
.price-mode { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.two { display: flex; gap: 8px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; align-items: center; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; min-width: 0; }

.btn-primary {
  background: var(--brand); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 18px; font-size: 14px; cursor: pointer; display: inline-block; text-decoration: none;
}
.btn-primary:hover { background: var(--brand-2); text-decoration: none; }
.btn-ghost {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font-size: 13.5px; cursor: pointer; display: inline-block;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.link-danger { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: 13px; padding: 4px; }
.row-actions { display: flex; gap: 10px; align-items: center; }
.row-actions form { margin: 0; }

/* Бързо отбелязване на плащане: Банка / Кеш / Карта с днешна дата. */
.pay-quick { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row-actions .pay-quick { margin-top: 0; }
.pay-hint { color: var(--ink-2); font-size: 12.5px; }
.row-actions .pay-hint { display: none; }
.btn-pay {
  background: var(--panel); color: var(--ink-2); border: 1px solid var(--line); border-radius: 20px;
  padding: 5px 12px; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.btn-pay:hover { border-color: var(--ok); color: var(--ok); }
.btn-ghost.on { border-color: var(--brand); color: var(--brand); background: #eff4ff; }

/* ------------------------------ Страници ------------------------------ */
.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
}
.pager-info { font-size: 12.5px; color: var(--ink-2); }
.pager-links { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-btn {
  min-width: 34px; text-align: center; padding: 6px 9px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
a.pager-btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pager-btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager-btn.off { color: #cbd5e1; }
.pager-gap { padding: 6px 2px; color: var(--ink-2); }

/* Подредбата на списъка с имейли: на телефон заглавията на колоните ги няма. */
.only-mobile { display: none; }
.sort-pick { margin-bottom: 10px; }
.sort-pick label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.sort-pick select { width: auto; flex: 1; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.toolbar > div { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .search input { min-width: min(240px, 100%); }
.flash {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  border-radius: 8px; padding: 10px 14px; margin-bottom: 14px;
}

/* -------------------------------- Login ------------------------------- */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(150deg, #0f172a, #1e293b);
}
.login-card {
  background: #fff; border-radius: 14px; padding: 34px 36px; width: 380px; max-width: calc(100vw - 32px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35); text-align: center;
}
.login-card h1 { font-size: 18px; margin: 0 0 18px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 12px; }
.login-card label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 5px; }
.login-card .btn-primary { width: 100%; margin-top: 4px; }
.login-card .or { color: var(--ink-2); margin: 14px 0 10px; }
.btn-google {
  display: block; border: 1px solid var(--line); border-radius: 8px; padding: 9px; color: var(--ink);
}

/* --------------------------------- Chat ------------------------------- */
.chat-wrap {
  display: flex; flex-direction: column;
  height: calc(100vh - 140px); min-height: 420px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-title { font-weight: 600; }
.chat-actions { display: flex; gap: 8px; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: #eef2f7; border-bottom-left-radius: 4px; }
.msg.err { align-self: flex-start; background: #fee2e2; color: #991b1b; }
.msg.typing { color: var(--ink-2); font-style: italic; }
.chat-confirm {
  border-top: 2px solid #f59e0b; background: #fffbeb; padding: 12px 16px;
}
.confirm-hint { font-size: 13px; color: #92400e; margin-bottom: 8px; }
.confirm-actions { display: flex; gap: 10px; }
.chat-input {
  display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); align-items: flex-end;
}
.chat-input textarea { flex: 1; resize: none; max-height: 130px; }
.chat-input .send { padding: 9px 16px; }
.mic { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 16px; cursor: pointer; padding: 8px 10px; }
.mic.rec { background: #fee2e2; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

/* -------------------------------- Emails ------------------------------ */
.email-thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.email-msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.email-msg.in { border-left: 4px solid var(--accent); }
.email-msg.out { border-left: 4px solid var(--ok); }
.email-msg.draft { border-left: 4px solid #f59e0b; background: #fffbeb; }
.email-meta { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.email-body { line-height: 1.5; overflow-wrap: anywhere; }
.email-draft-edit { width: 100%; margin-bottom: 8px; }

/* ----------------------- CompanyBook lookup -------------------------- */
.cb-lookup {
  margin-bottom: 16px; padding: 14px; border: 1px dashed var(--brand);
  border-radius: var(--radius); background: #f5f8ff;
}
.cb-lookup > label { display: block; font-weight: 600; margin-bottom: 8px; }
.cb-row { display: flex; gap: 8px; flex-wrap: wrap; }
.cb-row input {
  flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px;
}
.cb-results { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.cb-item {
  text-align: left; padding: 9px 12px; border: 1px solid var(--line);
  background: var(--panel); border-radius: var(--radius); cursor: pointer;
  display: flex; flex-direction: column; gap: 2px; font-size: 14px;
}
.cb-item:hover { border-color: var(--brand); background: #eef3ff; }
.cb-uic { font-size: 12px; color: var(--muted, #64748b); }
.cb-msg { margin-top: 8px; font-size: 13px; }
.cb-msg.red { color: var(--danger); }
input.cb-filled, textarea.cb-filled { background: #eefaf0; }

/* ------------------ Избор на партньор с търсене ----------------------- */
.partner-field { display: flex; gap: 8px; align-items: flex-start; }
.partner-field .picker { flex: 1; }
.partner-field .btn-ghost { white-space: nowrap; padding: 8px 12px; }
.picker { position: relative; }
/* Оригиналният select стои под полето: пази стойността и валидацията. */
.picker-native {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 1px;
  opacity: 0; pointer-events: none; border: 0; padding: 0;
}
.picker-list {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 260px; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
}
.picker-item {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 9px 12px; font-size: 14px; color: var(--ink); cursor: pointer;
}
.picker-item:hover, .picker-item.active { background: #eef3ff; }
.picker-item.on { font-weight: 600; }
.picker-empty { padding: 10px 12px; font-size: 13px; color: var(--ink-2); }
.picker.invalid .picker-input { border-color: var(--danger); }

/* --------------------------- Модален прозорец ------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center;
  justify-content: center; background: rgba(16, 24, 40, 0.5); padding: 16px;
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border-radius: var(--radius); width: 100%; max-width: 44rem;
  max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px 20px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-x { background: none; border: 0; font-size: 18px; color: var(--ink-2); cursor: pointer; padding: 4px 8px; }
.modal-x:hover { color: var(--ink); }
.modal-msg { font-size: 13px; min-height: 18px; }
.modal-msg.red { color: var(--danger); }
.modal .cb-lookup { margin-bottom: 0; }
body.modal-open { overflow: hidden; }

/* ------------------ Прикачване от системата към писмо ----------------- */
.attach-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.attach-head .btn-ghost { padding: 4px 10px; font-size: 13px; }
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px;
  background: #f4f7fb; font-size: 13px;
}
.attach-chip-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem; }
.attach-swap {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 1px 8px; font-size: 11.5px; color: var(--ink-2); cursor: pointer;
}
.attach-swap:hover { border-color: var(--brand); color: var(--ink); }
.attach-mark { font-size: 11.5px; color: var(--ink-2); }
.attach-x { border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 13px; padding: 0 4px; }
.attach-x:hover { color: var(--danger); }
.attach-search { width: 100%; }
.attach-results { margin-top: 10px; max-height: 50vh; overflow-y: auto; }
.attach-group {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-2); padding: 10px 2px 4px;
}
.attach-result {
  display: block; width: 100%; text-align: left; background: none; cursor: pointer;
  border: 0; border-top: 1px solid var(--line); padding: 8px 4px;
}
.attach-result:hover { background: #eef3ff; }
.attach-title { display: block; font-size: 14px; color: var(--ink); }
.attach-sub { display: block; font-size: 12.5px; }

/* ----------------------------- Email search -------------------------- */
.email-search { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.email-search input[type="search"] {
  flex: 1; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px;
}
.tbl th a { color: inherit; display: inline-block; }
.tbl th a:hover { color: var(--brand); }
.tbl th a.active { color: var(--brand); font-weight: 700; }
.nowrap { white-space: nowrap; }

/* --------------------------- Email sync progress --------------------- */
.sync-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sync-item:last-child { border-bottom: 0; }
.sync-head { margin-bottom: 8px; }
.progress { background: #e5eaf1; border-radius: 20px; height: 12px; overflow: hidden; }
.progress-bar {
  height: 100%; width: 0; border-radius: 20px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 0.35s ease;
}
.progress-bar.done { background: var(--ok); }
.progress-bar.err { background: var(--danger); }
.sync-status { margin-top: 6px; font-size: 13px; }

/* ------------------------------ Items editor -------------------------- */
.items-editor input { padding: 6px 8px; }
.items-editor .it-total { white-space: nowrap; }

/* --------------------------- Дата (дд.мм.гггг) ------------------------ */
.date-field { position: relative; display: flex; align-items: center; gap: 6px; }
.date-field .date-eu { flex: 1; min-width: 0; }
.date-field .date-native {
  position: absolute; left: 0; bottom: 0; width: 1px; height: 1px;
  opacity: 0; padding: 0; border: 0; pointer-events: none;
}
.date-field .date-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 7px 9px; cursor: pointer; line-height: 1; font-size: 14px;
}
.date-field .date-btn:hover { border-color: var(--brand); }

/* ------------------------------ Известия ------------------------------ */
/* Логото и в горния бар — на телефон менюто е скрито, а връзката към Начало трябва да е под ръка. */
.topbar-logo { display: flex; align-items: center; margin: 0 auto; }
.topbar-logo:hover { text-decoration: none; }
.topbar-logo .brand-mark { width: 30px; height: 30px; border-radius: 8px; font-size: 18px; }
.topbar-logo:hover .brand-mark { filter: brightness(1.12); }
.bell { position: relative; text-decoration: none; font-size: 18px; padding: 4px 8px; }
.bell-count {
  position: absolute; top: -2px; right: -2px; min-width: 17px; height: 17px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; line-height: 17px; text-align: center; padding: 0 4px; font-weight: 700;
}
.notif { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.notif.pending { border-left: 4px solid var(--brand); background: #f5f8ff; }
.notif-title { font-weight: 600; margin-bottom: 4px; }
.notif-body { font-size: 14px; color: var(--ink-2); margin-bottom: 8px; }
.notif-actions { display: flex; gap: 8px; align-items: center; }

/* --------------------- Подписи и имейл шаблони ------------------------ */
.sig-preview {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 14px; background: #fff; overflow-x: auto;
}
.sig-preview img { max-width: 100%; height: auto; }
.tpl-help { margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.tpl-help ul { margin: 6px 0 0; padding-left: 18px; }
.tpl-help li { margin: 2px 0; }
.tpl-help code, .quiet code {
  background: #eef2f7; border-radius: 4px; padding: 1px 5px; font-size: 12px;
}

/* --------------------------- Готови забележки ------------------------- */
.note-pick { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.note-pick select { flex: 1; min-width: 180px; }

/* --------------------- Инсталиране като приложение -------------------- */
.install-btn {
  background: var(--brand); color: #fff; border: 0; border-radius: 8px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.install-btn:hover { background: var(--brand-2); }
.install-sheet {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end;
  justify-content: center; background: rgba(16, 24, 40, 0.5);
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
}
/* Задължително: правило с display побеждава вградения стил на hidden. */
.install-sheet[hidden] { display: none; }
.install-card {
  background: var(--panel); border-radius: var(--radius); padding: 20px;
  width: 100%; max-width: 26rem; box-shadow: 0 -8px 40px rgba(0,0,0,0.25);
}
.install-card h3 { margin: 0 0 10px; font-size: 17px; }
.install-steps { margin: 0 0 12px; padding-left: 20px; }
.install-steps li { margin: 6px 0; }
.install-card .btn-ghost { margin-top: 12px; }
@media (min-width: 861px) { .install-sheet { align-items: center; } }

.markup-box { margin-left: 14px; font-size: 13px; color: var(--ink-2); display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.markup-input { width: 70px; padding: 4px 6px; }

/* Прикачен файл към чата */
.chat-attach { display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-top: 1px solid var(--line); }
.chat-attach .chip { font-size: 13px; color: var(--ink-2); }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 14px; }

/* ------------------------ Печати и подписи --------------------------- */
.mark-grid { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.mark-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
  width: 170px; background: repeating-conic-gradient(#f6f7f9 0% 25%, #fff 0% 50%) 50% / 14px 14px;
}
.mark-card img { max-width: 100%; max-height: 90px; display: block; margin: 0 auto 6px; }
.mark-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; background: var(--panel); }
.sign-pad-wrap { border: 1px dashed var(--line); border-radius: var(--radius); background: #fff; }
#signPad { width: 100%; height: 220px; display: block; touch-action: none; cursor: crosshair; }

/* Редактор: палитра отляво, страниците отдясно. */
.mark-editor { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.mark-palette {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; position: sticky; top: 14px;
}
.mark-palette h3 { margin: 0 0 6px; font-size: 15px; }
.mark-chip {
  display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 8px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--panel); text-align: left;
}
.mark-chip:hover { border-color: var(--brand); }
.mark-chip.on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15); }
.mark-chip img { width: 46px; height: 36px; object-fit: contain; }
.mark-chip span { font-size: 12.5px; color: var(--ink-2); }
.mark-tools { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }

.mark-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.mark-page { position: relative; box-shadow: 0 2px 14px rgba(16, 24, 40, 0.16); background: #fff; max-width: 100%; }
.mark-page-img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.mark-layer { position: absolute; inset: 0; }
.mark-pageno {
  position: absolute; right: -10px; top: -10px; background: var(--ink); color: #fff;
  border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center;
  justify-content: center; font-size: 12px;
}
.mark-item { position: absolute; cursor: move; touch-action: none; }
.mark-item img { width: 100%; height: auto; display: block; pointer-events: none; }
.mark-item.on { outline: 2px dashed var(--brand); outline-offset: 2px; }
.mark-x, .mark-size { position: absolute; display: none; }
.mark-item.on .mark-x, .mark-item.on .mark-size { display: flex; }
.mark-x {
  top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: #fff; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer;
}
.mark-size {
  right: -8px; bottom: -8px; width: 16px; height: 16px; background: var(--brand);
  border: 2px solid #fff; border-radius: 4px; cursor: nwse-resize;
}

.archive-preview { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; }
.archive-text {
  white-space: pre-wrap; font-size: 12.5px; color: var(--ink-2); max-height: 420px;
  overflow: auto; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin: 0;
}

/* ------------------------- За системата ------------------------------ */
.about-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.about-head h2 { margin: 0 0 4px; }
.about-head p { margin: 0; }
.about-ver { display: flex; align-items: center; gap: 8px; }
.ver-badge {
  display: inline-block; background: #eef2ff; color: var(--brand-2); border: 1px solid #c7d2fe;
  border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 600;
}
.ver-badge.now { background: var(--brand); color: #fff; border-color: var(--brand); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-2); font-size: 13.5px;
}
.tabs a:hover { text-decoration: none; border-color: var(--brand); }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.guide { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; align-items: start; }
.guide-card h3 { margin: 0 0 8px; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.guide-ic {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 8px; background: #eef2ff;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.guide-card ol { margin: 0; padding-left: 20px; }
.guide-card li { margin: 6px 0; line-height: 1.5; }

.release { padding: 14px 0; border-bottom: 1px solid var(--line); }
.release:last-child { border-bottom: 0; padding-bottom: 0; }
.release:first-child { padding-top: 0; }
.release-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.release ul { margin: 0; padding-left: 20px; }
.release li { margin: 5px 0; line-height: 1.5; }

/* ---------------- Безопасна зона (изрез и лента на iPhone) ------------ */
.topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
.sidebar { padding-top: env(safe-area-inset-top); }
.sidebar-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.content { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }

/* ------------------------------ Календар ------------------------------ */
.cal-month { min-width: 9.5rem; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-2); padding: 2px 4px; }
.cal-day {
  min-height: 92px; border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  display: flex; flex-direction: column; gap: 2px; background: #fff;
}
.cal-day.out { background: #fafbfc; opacity: .6; }
.cal-day.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal-num { font-size: 12px; color: var(--ink-2); }
.cal-day.today .cal-num { color: var(--brand); font-weight: 700; }
.cal-ev {
  display: block; font-size: 11.5px; line-height: 1.35; padding: 2px 5px; border-radius: 5px;
  background: #eef2f7; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-ev:hover { text-decoration: none; filter: brightness(0.96); }
.cal-ev.done { opacity: .5; text-decoration: line-through; }
.cal-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #94a3b8; }
.k-reminder { background: #fef3c7; color: #92400e; }
.k-billing { background: #dbeafe; color: #1e40af; }
.k-contract_start { background: #dcfce7; color: #166534; }
.k-contract_end { background: #fee2e2; color: #991b1b; }
.k-contract_notice { background: #ffe4e6; color: #9f1239; }
.k-invoice_due { background: #ede9fe; color: #5b21b6; }
.k-promo { background: #fce7f3; color: #9d174d; }
.k-promo_end { background: #fae8ff; color: #86198f; }

/* ------------------------------- Mobile ------------------------------- */
@media (max-width: 860px) {
  /* Pinch и double-tap zoom местят цялата страница настрани. Скролът остава. */
  html, body {
    touch-action: pan-x pan-y;
    overscroll-behavior-x: none;
  }
  .sidebar {
    position: fixed; left: -240px; z-index: 30; transition: left 0.2s ease; height: 100vh;
  }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  /* Затъмнението стои под менюто и поема цъкането извън него. */
  body.menu-open .sidebar-backdrop { display: block; }
  .burger { display: block; }
  /* На тесен екран барът събира повече елементи — по-малко въздух между тях. */
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .topbar h1 { font-size: 16px; }
  .install-btn { padding: 5px 10px; font-size: 12px; }
  .lang-switch button { padding: 4px 7px; }
  .only-mobile { display: block; }
  .grid-2, .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .content { padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .chat-wrap { height: calc(100vh - 120px); }
  .msg { max-width: 92%; }
  .toolbar .search input { min-width: 0; width: 100%; }
  .email-search input[type="search"] { min-width: 0; flex: 1 1 100%; }
  .markup-box { margin-left: 0; }
  .partner-field { flex-direction: column; }
  .partner-field .picker, .partner-field .btn-ghost { width: 100%; }
  .guide { grid-template-columns: 1fr; }
  .mark-editor { grid-template-columns: 1fr; }
  .mark-palette { position: static; }
  .mark-grid { gap: 8px; }
  .mark-card { width: calc(50% - 4px); }
  .attach-chip-t { max-width: 11rem; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-width: none; border-radius: var(--radius) var(--radius) 0 0; max-height: 92vh;
                padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

  /* Всички таблици (без ключ–стойност) се четат вертикално на телефон. */
  .tbl:not(.kv) { display: block; overflow: visible; white-space: normal; }
  .tbl:not(.kv) thead { display: none; }
  .tbl:not(.kv) tbody { display: block; }
  .tbl:not(.kv) tbody tr { display: flex; flex-direction: column; gap: 6px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
  .tbl:not(.kv) tbody tr:last-child { border-bottom: 0; }
  .tbl:not(.kv) tbody td { display: block; border: 0; padding: 0; min-width: 0; }
  .tbl:not(.kv) tbody td:empty { display: none; }
  .tbl:not(.kv) tbody td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-2); font-size: 12.5px; }
  .tbl:not(.kv) tbody td:not(.c-name) { white-space: normal; }
  .tbl:not(.kv) tbody td.num, .tbl:not(.kv) tbody td.nowrap { white-space: nowrap; }
  .tbl:not(.kv) tbody td.num { text-align: left; }
  .tbl:not(.kv) tbody td.c-name { order: -1; font-weight: 600; font-size: 15.5px; }
  .tbl:not(.kv) tbody td.c-name::before { content: none; }
  .tbl:not(.kv) tbody td.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .tbl:not(.kv) tbody td.row-actions::before { content: none; }

  /* Редактор на позиции: полетата са едно под друго; сумите — етикет + число. */
  .tbl.items-editor tbody td[data-label]::before { display: block; margin-bottom: 3px; }
  .tbl.items-editor tfoot { display: block; }
  .tbl.items-editor tfoot tr { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
  .tbl.items-editor tfoot td { display: block; border: 0; padding: 0; min-width: 0; }
  .tbl.items-editor tfoot td:empty { display: none; }
  .tbl.items-editor tfoot td.num { text-align: left; }
  .tbl.items-editor tfoot td[colspan] { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

  /* Календарът на телефон: по-ниски клетки, само точки вместо заглавия. */
  .cal-grid { gap: 2px; }
  .cal-day { min-height: 62px; padding: 3px; }
  .cal-ev { font-size: 0; padding: 0; height: 6px; border-radius: 3px; }
  .cal-ev b { font-size: 0; }
}

