/* Бизнес-панель RIM. Палитра — из темы сайта (rim/assets/css/main.css). */
:root {
  color-scheme: light;
  --bg: #F4F1EC;
  --surface: #FFFFFF;
  --surface-2: #FBFAF8;
  --ink: #171512;
  --text: #4A453D;
  --muted: #8E8779;
  --muted-2: #6E685C;
  --line: #E6E1D8;
  --line-2: #DCD2C2;
  --ac: #8A6A3E;
  --ac-soft: #F3ECE1;
  --danger: #A33A2B;
  --danger-soft: #F8E9E6;
  --ok: #3F6B45;
  --ok-soft: #E8F0E7;
  --warn: #8A5A12;
  --warn-soft: #FBF1DE;
  --radius: 10px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'EB Garamond', Georgia, serif;
  --focus: 0 0 0 3px rgba(138, 106, 62, .28);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--font); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
code { font: 500 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(23, 21, 18, .06); padding: 1px 5px; border-radius: 4px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---- Каркас ------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
  padding: 22px 16px 18px; background: var(--surface-2); border-right: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; text-decoration: none; }
.brand-mark { font: 500 26px/1 var(--font-display); letter-spacing: .22em; color: var(--ink); }
.brand-sub { font: 600 10px/1.4 var(--font); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { padding: 8px 10px; border-radius: 8px; text-decoration: none; font-weight: 500; color: var(--text); }
.nav-link:hover { background: rgba(23, 21, 18, .05); color: var(--ink); }
.nav-link.is-active { background: var(--ink); color: #fff; }
.side-user { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 10px 0; border-top: 1px solid var(--line); }
.side-user-name { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }

.main { padding: 32px 40px 64px; max-width: 1180px; width: 100%; }
.is-wide .main { max-width: none; padding: 0; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.page-title { margin: 0; font: 500 34px/1.1 var(--font-display); letter-spacing: -0.01em; color: var(--ink); }
.page-title-small { font-size: 24px; }

/* ---- Кнопки и поля ------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 7px 14px; border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .input:focus-visible, .icon-button:focus-visible, .link-button:focus-visible, .nav-link:focus-visible { outline: 0; box-shadow: var(--focus); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ac); border-color: var(--ac); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted-2); }
.btn-quiet:hover { background: rgba(23, 21, 18, .05); border-color: transparent; color: var(--ink); }
.btn-small { min-height: 30px; padding: 4px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-add { width: 100%; min-height: 44px; border-style: dashed; color: var(--muted-2); background: transparent; }
.btn-add:hover { color: var(--ink); background: var(--surface); }
.link-button { padding: 0; border: 0; background: none; color: var(--muted-2); font-weight: 500; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); border-radius: 3px; }
.link-button:hover { color: var(--ink); }
.link-muted { color: var(--muted-2); font-weight: 500; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.link-muted:hover { color: var(--ink); }
.icon-button { width: 28px; height: 28px; display: inline-grid; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted-2); font-size: 15px; line-height: 1; cursor: pointer; }
.icon-button:hover:not(:disabled) { background: rgba(23, 21, 18, .06); color: var(--ink); }
.icon-button.is-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.icon-button:disabled { opacity: .3; cursor: default; }
.btn-quiet.is-danger { color: var(--danger); }
.btn-quiet.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.status-dot { width: 7px; height: 7px; margin-left: 2px; border-radius: 50%; background: var(--ok); }
.status-dot.is-warn { background: #C98A1B; }
.chip { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); font-size: 11.5px; font-weight: 600; vertical-align: 1px; }

.field { position: relative; display: flex; flex-direction: column; gap: 5px; min-width: 0; margin: 0 0 12px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--muted-2); }
.field-hint { font-weight: 400; color: var(--muted); }
.input {
  width: 100%; min-height: 38px; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: #B9B2A5; }
.input:hover { border-color: #C9BFAE; }
.input:focus { border-color: var(--ac); outline: 0; box-shadow: var(--focus); }
.input[readonly] { background: var(--surface-2); color: var(--muted-2); }
textarea.input { resize: vertical; line-height: 1.45; }
select.input { padding-right: 28px; }
.input.num { font-variant-numeric: tabular-nums; }
.input-small { width: auto; min-height: 30px; padding: 3px 8px; font-size: 13px; }
.input-search { max-width: 360px; }
.check { display: inline-flex; align-items: center; gap: 8px; margin: 2px 0 12px; font-weight: 500; color: var(--ink); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--ink); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; }

.flash { margin: 0 0 16px; padding: 10px 14px; border-radius: 8px; font-weight: 500; transition: opacity .4s; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-warning { background: var(--warn-soft); color: var(--warn); }
.flash.is-gone { opacity: 0; pointer-events: none; }
.is-wide .flash { position: fixed; z-index: 30; top: 14px; left: 50%; transform: translateX(-50%); box-shadow: 0 6px 24px rgba(23, 21, 18, .12); }

/* ---- Список счетов ------------------------------------------------------ */

.toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 11px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.num { font-weight: 600; color: var(--ink); }
.table .actions { width: 1%; text-align: right; }
.row-link { font-weight: 600; color: var(--ink); text-decoration: none; }
.row-link:hover { color: var(--ac); }
.row-link::after { content: ''; }

.empty { padding: 56px 24px; text-align: center; background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty-title { margin: 0; font: 500 24px/1.2 var(--font-display); color: var(--ink); }
.empty-text { max-width: 440px; margin: 8px auto 20px; color: var(--muted-2); }

/* ---- Формы -------------------------------------------------------------- */

.form-section { padding: 20px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.section-title { margin: 0 0 14px; font-size: 15px; font-weight: 700; color: var(--ink); }
.section-hint { margin: -8px 0 14px; color: var(--muted); font-size: 13px; }
.form-actions { display: flex; gap: 10px; }
.fact-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px; margin-bottom: 8px; }

.card { margin: 0 0 12px; padding: 14px 14px 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin: -2px 0 10px; }
.card-title { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ac); }
.card-tools { display: flex; gap: 2px; }
.card-foot { display: flex; justify-content: space-between; align-items: baseline; margin: 2px -14px 0; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--muted-2); }
.card-foot strong { font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }

.image-field { display: flex; align-items: center; gap: 12px; }
.image-thumb { display: none; width: 88px; height: 62px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.image-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.image-field .when-filled { display: none; }
.image-field.has-image .image-thumb { display: block; }
.image-field.has-image .when-filled { display: inline-flex; }
.image-field.has-image .when-empty { display: none; }
.image-field label.btn { position: relative; }
.image-field.is-loading { opacity: .6; pointer-events: none; }
.image-status { font-size: 12.5px; color: var(--danger); }
.image-field.is-loading .image-status { color: var(--muted-2); }

.payments { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.payment-row { display: grid; grid-template-columns: 92px minmax(0, 1fr) 28px; gap: 8px; align-items: start; }
.payment-row .field { margin: 0; }
.field-pct .input { padding-right: 26px; text-align: right; }
.input-suffix { position: absolute; right: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.payment-row .icon-button { margin-top: 5px; }
.payments-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.payments-sum { font-size: 13px; color: var(--muted-2); }
.payments-sum.is-off b { color: var(--danger); }

.totals { margin: 6px 0 0; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.totals div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.totals dt { color: var(--muted-2); }
.totals dd { margin: 0; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 500; }
.totals .totals-grand { margin: 4px 0; padding: 8px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.totals .totals-grand dt, .totals .totals-grand dd { font-size: 16px; font-weight: 700; color: var(--ink); }

/* ---- Редактор счёта ----------------------------------------------------- */

.editor { display: flex; flex-direction: column; height: 100vh; }
.editor-bar {
  flex: none; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.editor-bar-title { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.back-link { color: var(--muted-2); text-decoration: none; font-weight: 500; white-space: nowrap; }
.back-link:hover { color: var(--ink); }
.dirty-badge { font-size: 12px; font-weight: 600; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.editor-bar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.editor-bar-actions .is-last { order: 9; }

.editor-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(420px, 560px) minmax(0, 1fr); }
.editor-form { position: relative; overflow-y: auto; padding: 18px 18px 80px 24px; scrollbar-gutter: stable; }
.editor-preview { display: flex; flex-direction: column; min-height: 0; background: #EAE6DF; border-left: 1px solid var(--line); }
.preview-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-2); }
.preview-status { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--muted); }
.preview-head .link-button { margin-left: auto; text-transform: none; letter-spacing: 0; }
.preview-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.preview-frame { position: absolute; top: 0; left: 0; border: 0; background: #f5f5f4; transform-origin: top left; visibility: hidden; }
.preview-frame.is-front { visibility: visible; }

.only-narrow { display: none; }

@media (max-width: 1100px) {
  .editor-body { grid-template-columns: minmax(0, 1fr); }
  .editor-form { padding: 16px 16px 80px; }
  .editor-preview { display: none; }
  .preview-open .editor-preview { display: flex; position: fixed; inset: 0; z-index: 40; border: 0; }
  .only-narrow { display: inline-flex; }
}

/* ---- Публичная ссылка --------------------------------------------------- */

.share-panel {
  position: fixed; inset: 62px 24px auto auto; margin: 0;
  width: min(440px, calc(100vw - 32px)); padding: 18px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
  box-shadow: 0 16px 48px rgba(23, 21, 18, .16);
}
.share-panel::backdrop { background: transparent; }
.share-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.share-title { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
.share-text { margin: 0 0 14px; color: var(--muted-2); }
.share-link { display: flex; gap: 8px; }
.share-link .input { font-size: 13px; color: var(--ink); background: var(--surface-2); }
.share-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.share-note { margin: 12px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--muted-2); }
.share-note.is-warn { background: var(--warn-soft); color: var(--warn); }
.share-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 14px; }

/* ---- Недоступная ссылка ------------------------------------------------- */

.missing { max-width: 420px; text-align: center; }
.missing-title { margin: 8px 0 10px; font: 500 36px/1.1 var(--font-display); color: var(--ink); }
.missing-text { margin: 0 0 18px; color: var(--muted-2); }
.missing-contacts { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 18px; margin: 0; font-weight: 600; }
.missing-contacts a { color: var(--ink); text-underline-offset: 3px; text-decoration-color: var(--line-2); }

/* ---- Настройки ---------------------------------------------------------- */

.settings { max-width: 820px; }
.settings-form + .settings-form { margin-top: 28px; }

/* ---- Вход --------------------------------------------------------------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login { width: 100%; max-width: 380px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 24px; }
.login-brand .brand-mark { font-size: 40px; }
.login-form { padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 40px rgba(23, 21, 18, .06); }
.login-form .btn { margin-top: 6px; min-height: 42px; }

/* ---- Узкие экраны ------------------------------------------------------- */

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; }
  .side-user { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { padding: 20px 16px 48px; }
  /* На телефоне страница скроллится целиком, панель действий прилипает сверху. */
  .editor { height: auto; }
  .editor-form { overflow: visible; }
  .editor-bar { position: sticky; top: 0; z-index: 20; padding: 10px 16px; }
  .editor-bar-actions { width: 100%; }
  .editor-bar-actions .btn { flex: 1 1 auto; }
  .share-panel { inset: 12px 16px auto 16px; width: auto; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fact-row { grid-template-columns: minmax(0, 1fr); }
  .page-title { font-size: 28px; }
}
