/* TENI · Кабинет менеджера v4
   Рабочий инструмент: плотность SaaS, системный шрифт, монохром + бронзовый акцент TENI только для активных состояний. */

:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --surface-3: #f1f0ed;
  --border: #e4e3df;
  --border-strong: #cfcdc7;
  --text: #1b1a18;
  --muted: #6b6964;
  --faint: #9a9790;
  --primary: #1b1a18;
  --primary-hover: #000000;
  --on-primary: #ffffff;
  --accent: #a27a4a;          /* TENI sunlight: только выбранное/активное */
  --accent-soft: #f5ede3;
  --focus: #a27a4a;

  --ok: #2c7a4b;   --ok-bg: #e7f3ec;
  --warn: #9a5b0b; --warn-bg: #fbf0dc;
  --bad: #b3372a;  --bad-bg: #fbe8e5;
  --info: #2b5c9e; --info-bg: #e8eef8;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;

  --r-sm: 5px;
  --r: 7px;
  --r-lg: 10px;
  --control-h: 32px;
  --row-h: 40px;
  --appbar-h: 48px;
  --editorbar-h: 52px;
  --rail-w: 236px;
  --shadow-pop: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.12);
}
@media (pointer: coarse) {
  :root { --control-h: 38px; --row-h: 46px; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs)/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ic { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--appbar-h); display: flex; align-items: center; gap: 24px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.appbar-brand { display: flex; align-items: center; }
.appbar-brand img { display: block; height: 20px; width: auto; }
.appbar-nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.appbar-nav a {
  text-decoration: none; padding: 6px 10px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.appbar-nav a:hover { color: var(--text); background: var(--surface-3); }
.appbar-nav a.is-on { color: var(--text); background: var(--surface-3); }
.appbar-save { margin-left: auto; font-size: var(--fs-sm); color: var(--faint); white-space: nowrap; }
.appbar-save.is-busy { color: var(--warn); }
.appbar-save.is-error { color: var(--bad); font-weight: 500; }

/* ---------- Generic controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 12px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; white-space: nowrap; text-decoration: none; user-select: none;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-3); }
.btn-sm { height: 26px; padding: 0 8px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-danger { color: var(--bad); }
.btn .count { min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-3); font-size: var(--fs-xs); line-height: 18px; }
.btn .count.is-hot { background: var(--accent); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h);
  border: 0; border-radius: var(--r); background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; border-radius: var(--r-sm); }
.icon-btn.danger:hover { color: var(--bad); background: var(--bad-bg); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.link-btn { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; font-size: var(--fs-sm); }
.link-btn:hover { color: var(--text); }

input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-width: 0; height: var(--control-h); padding: 0 9px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
  outline: none;
}
textarea { height: auto; padding: 6px 9px; resize: vertical; line-height: 1.45; }
select { padding-right: 26px; appearance: none; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%236b6964' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 6px center; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(162,122,74,.18); }
input[type=number] { font-variant-numeric: tabular-nums; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); margin: 0; }
input.is-invalid, textarea.is-invalid { border-color: var(--bad); background: #fffafa; }

.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field > span { font-size: var(--fs-sm); color: var(--muted); font-weight: 500; }
.field > small { font-size: var(--fs-xs); color: var(--faint); }
.field.full { grid-column: 1 / -1; }
.grid { display: grid; gap: 10px 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--r); background: var(--surface-3); border: 1px solid var(--border); }
.seg button { height: calc(var(--control-h) - 6px); padding: 0 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.seg button:hover { color: var(--text); }
.seg button.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg button .count { font-size: var(--fs-xs); color: var(--faint); font-variant-numeric: tabular-nums; }
.seg button.is-hot .count { color: var(--accent); font-weight: 600; }

.chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 10px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.dark { background: var(--primary); color: #fff; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: #d08a1c; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
fieldset.card { margin: 0; padding: 12px 14px 14px; min-width: 0; }
fieldset.card > legend { float: left; width: 100%; padding: 0; margin: 0 0 10px; font-weight: 600; font-size: var(--fs-md); }
fieldset.card > legend + * { clear: both; }

/* ---------- Pages (projects / library / market / settings) ---------- */
#app { min-height: calc(100vh - var(--appbar-h)); }
.view:not(.view-editor) { max-width: 1440px; margin: 0 auto; padding: 16px 20px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { font-size: var(--fs-xl); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-note { color: var(--muted); margin: -4px 0 12px; max-width: 760px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search .ic { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { padding-left: 30px !important; }
.sort { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted); font-size: var(--fs-sm); }
.sort select { width: auto; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: 0; text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; color: var(--faint); padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 6px 10px; height: var(--row-h); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .col-actions { width: 1%; text-align: right; white-space: nowrap; }
.table td.empty { text-align: center; color: var(--muted); padding: 28px; }
.table .sub { display: block; font-size: var(--fs-sm); color: var(--muted); }
.table .strong { font-weight: 600; }
.projects-table tbody tr { cursor: pointer; }
.projects-table tbody tr:hover td { background: var(--surface-2); }
.projects-table tr.is-hot td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.when { white-space: nowrap; }
.when .sub { white-space: nowrap; }
.when.soon .sub { color: var(--warn); font-weight: 500; }
.when.over .sub { color: var(--bad); font-weight: 500; }
.events-cell { display: flex; align-items: center; gap: 6px; }
.events-cell .chip { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }

.settings { display: grid; gap: 12px; max-width: 980px; }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.field-note { display: block; margin-top: 8px; color: var(--muted); font-size: var(--fs-sm); }
.settings-account { max-width: 980px; margin-top: 12px; padding: 12px 14px 14px; }
.settings-account h2 { margin: 0 0 6px; font-size: var(--fs-md); }
.settings-account p { margin: 0 0 8px; color: var(--muted); font-size: var(--fs); max-width: 70ch; }
.settings-account code { font-size: var(--fs-sm); background: var(--surface-3); padding: 1px 5px; border-radius: var(--r-sm); }
.boot-error { position: fixed; inset: auto 16px 16px; z-index: 100; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 12px 14px; background: var(--bad-bg); color: var(--bad); border: 1px solid currentColor; border-radius: var(--r-lg); font: var(--fs-md)/1.4 var(--font); }
.boot-error button { margin-left: auto; font: inherit; padding: 4px 10px; border-radius: var(--r); border: 1px solid currentColor; background: #fff; color: inherit; cursor: pointer; }

/* ---------- Editor ---------- */
.view-editor { display: flex; flex-direction: column; min-height: calc(100vh - var(--appbar-h)); }
.editor-bar {
  position: sticky; top: var(--appbar-h); z-index: 20;
  min-height: var(--editorbar-h); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.eb-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 260px; }
.eb-title h1 { font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eb-title .faint { white-space: nowrap; font-size: var(--fs-sm); }
.eb-total { display: grid; line-height: 1.15; text-align: right; padding: 0 6px; }
.eb-total small { font-size: var(--fs-xs); color: var(--faint); }
.eb-total strong { font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }
.eb-actions { display: flex; align-items: center; gap: 6px; }
.ready-btn.is-ok { color: var(--ok); border-color: #b9d8c5; background: var(--ok-bg); }
.ready-btn.is-bad { color: var(--bad); border-color: #ecc3bd; background: var(--bad-bg); }
.republish-note { display: flex; align-items: center; gap: 6px; padding: 6px 16px; font-size: var(--fs-sm); color: var(--warn); background: var(--warn-bg); border-bottom: 1px solid #f0dcb6; }

.editor-body { flex: 1; display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 0; background: linear-gradient(to right, var(--surface) calc(var(--rail-w) - 1px), var(--border) calc(var(--rail-w) - 1px), var(--border) var(--rail-w), transparent var(--rail-w)); }

/* Rail */
.rail { padding: 10px 8px 24px; position: sticky; top: calc(var(--appbar-h) + var(--eb-h, var(--editorbar-h))); align-self: start; max-height: calc(100vh - var(--appbar-h) - var(--eb-h, var(--editorbar-h))); overflow-y: auto; }
.rail-label { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 4px; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
.rail-item {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  min-height: 36px; padding: 6px 8px; border: 0; border-radius: var(--r); background: transparent; text-align: left;
}
.rail-item:hover { background: var(--surface-3); }
.rail-item.is-on { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.rail-item b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item small { display: block; font-size: var(--fs-xs); color: var(--faint); font-weight: 400; }
.rail-item .rail-sum { font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rail-item .ic { color: var(--muted); }
.rail-sub { width: 100%; display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 30px; border: 0; background: none; font-size: var(--fs-sm); color: var(--muted); text-align: left; border-radius: var(--r-sm); }
.rail-sub:hover { color: var(--text); background: var(--surface-3); }
.rail-add { margin: 4px 8px 0; }
.rail .badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: var(--fs-xs); font-weight: 600; display: inline-grid; place-items: center; }

/* Work area */
.work { padding: 16px 20px 64px; min-width: 0; container-type: inline-size; container-name: work; }
.work-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.work-head .grow { flex: 1; min-width: 0; display: grid; gap: 6px; }
.title-input { font-size: var(--fs-xl) !important; font-weight: 600; height: 36px !important; border-color: transparent !important; padding: 0 6px !important; margin-left: -7px; background: transparent !important; letter-spacing: -0.01em; }
.title-input:hover { border-color: var(--border) !important; }
.title-input:focus { border-color: var(--focus) !important; background: var(--surface) !important; }
.task-input { border-color: transparent !important; background: transparent !important; padding-left: 6px !important; margin-left: -7px; color: var(--muted); resize: none; min-height: 30px; }
.task-input:hover { border-color: var(--border) !important; }
.task-input:focus { border-color: var(--focus) !important; background: var(--surface) !important; color: var(--text); }
.task-input.is-invalid { border-color: var(--bad) !important; }
.quiz-context { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; margin-bottom: 14px; border-radius: var(--r); background: var(--info-bg); color: #24446f; font-size: var(--fs-sm); }
.quiz-context img { width: 72px; height: 54px; object-fit: cover; border-radius: var(--r-sm); flex: none; }
.quiz-context b { font-weight: 600; }

.client-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@container work (max-width: 720px) { .client-grid { grid-template-columns: 1fr; } }

/* Group */
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 14px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 0 12px; flex-wrap: wrap; }
.group-name { flex: 0 1 260px; font-weight: 600 !important; border-color: transparent !important; background: transparent !important; padding-left: 4px !important; margin-left: -5px; }
.group-name:hover { border-color: var(--border) !important; }
.group-name:focus { border-color: var(--focus) !important; background: var(--surface) !important; }
.group-meta { color: var(--faint); font-size: var(--fs-sm); white-space: nowrap; }
.group-head .spacer { flex: 1; }

.sol-tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.sol-tab { display: grid; gap: 0; text-align: left; min-width: 0; padding: 6px 12px 7px; border: 1px solid transparent; border-bottom: 0; border-radius: var(--r) var(--r) 0 0; background: transparent; margin-bottom: -1px; color: var(--muted); }
.sol-tab:hover { color: var(--text); background: var(--surface-2); }
.sol-tab.is-on { background: var(--surface); border-color: var(--border); color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.sol-tab small { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--faint); font-weight: 600; }
.sol-tab b { font-weight: 500; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.sol-tab .tab-price { font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.sol-tab-add { align-self: center; margin: 0 4px 6px; }

.solution { display: grid; grid-template-columns: minmax(0, 1fr); }
@container work (min-width: 960px) {
  .solution { grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); }
  .solution > .pane + .pane { border-left: 1px solid var(--border); border-top: 0; }
}
.pane { padding: 12px; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.pane + .pane { border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) 0; }
.pane-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pane-title h3 { font-size: var(--fs-md); }
.pane-title .hint { font-size: var(--fs-sm); color: var(--faint); }
.section-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin-bottom: 6px; }
.section-label .link-btn { text-transform: none; letter-spacing: 0; font-weight: 400; }

.product-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.product-row small { font-size: var(--fs-xs); color: var(--faint); }

/* Windows table */
.win-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.win-table th { font-size: var(--fs-xs); font-weight: 600; color: var(--faint); text-align: left; padding: 0 4px 4px; white-space: nowrap; text-transform: uppercase; letter-spacing: .04em; }
.win-table td { padding: 2px 4px; vertical-align: middle; }
.win-table .c-n { width: 22px; color: var(--faint); font-size: var(--fs-sm); text-align: right; padding-right: 6px; }
.win-table .c-w, .win-table .c-h { width: 66px; }
.win-table .c-cost { width: 92px; }
.win-table .c-retail { width: 92px; text-align: right; }
.win-table .c-mkt { width: 62px; text-align: right; }
.win-table .c-act { width: 60px; text-align: right; white-space: nowrap; }
.win-table th.num, .win-table td.num { text-align: right; }
.win-table input { height: 30px !important; padding: 0 6px !important; }
.win-table input[type=number] { text-align: right; }
.win-table tfoot td { padding-top: 8px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.win-table .retail { font-variant-numeric: tabular-nums; color: var(--muted); }
.win-name { display: flex; align-items: center; gap: 4px; }
.photo-btn { position: relative; flex: none; width: 30px; height: 30px; border-radius: var(--r-sm); border: 1px dashed var(--border-strong); background: var(--surface); color: var(--faint); display: grid; place-items: center; overflow: hidden; cursor: pointer; }
.photo-btn img { width: 100%; height: 100%; object-fit: cover; }
.photo-btn:hover { border-color: var(--text); color: var(--text); }
.photo-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.ai-row td { padding-top: 0; }
.ai-state { font-size: var(--fs-xs); }
.ai-state.error { color: var(--bad); }
.ai-state.success { color: var(--ok); }
.ai-state.loading { color: var(--info); }

.mkt { display: inline-block; min-width: 46px; padding: 2px 6px; border-radius: 9px; font-size: var(--fs-xs); font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; background: var(--ok-bg); color: var(--ok); cursor: help; }
.mkt.high { background: var(--bad-bg); color: var(--bad); }
.mkt.low { background: var(--warn-bg); color: var(--warn); }
.mkt.none { background: var(--surface-3); color: var(--faint); }
.mkt.stale { box-shadow: inset 0 0 0 1px currentColor; }

/* Price box */
.price-box { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface-2); padding: 10px 12px; display: grid; gap: 10px; }
.calc-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.calc-line b { color: var(--text); font-weight: 600; }
.calc-line .op { color: var(--faint); }
.final-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px; }
.final-row .field { width: 160px; }
.final-row .field input { font-size: var(--fs-lg); font-weight: 600; height: 36px !important; text-align: right; }
.final-row .btns { display: flex; gap: 6px; padding-bottom: 2px; }
.variance { font-size: var(--fs-sm); color: var(--muted); padding-bottom: 8px; }
.variance.manual { color: var(--warn); }
.market-signal { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--r-sm); font-size: var(--fs-sm); background: var(--ok-bg); color: var(--ok); }
.market-signal.high { background: var(--bad-bg); color: var(--bad); }
.market-signal.low { background: var(--warn-bg); color: var(--warn); }
.market-signal.none { background: var(--surface-3); color: var(--muted); }
.market-signal b { font-weight: 600; }
.history { font-size: var(--fs-sm); color: var(--muted); }
.history summary { cursor: pointer; }
.history ul { margin: 6px 0 0; padding-left: 16px; }

/* Client pane */
.client-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.client-fields textarea { min-height: 52px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.media-tile { position: relative; aspect-ratio: 4 / 3; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-3); border: 1px solid var(--border); }
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .icon-btn { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; background: rgba(255,255,255,.92); color: var(--text); border-radius: 50%; }
.media-tile .icon-btn .ic { width: 12px; height: 12px; }
.media-add { aspect-ratio: 4 / 3; display: grid; place-items: center; align-content: center; gap: 2px; border: 1px dashed var(--border-strong); border-radius: var(--r-sm); color: var(--muted); font-size: var(--fs-xs); cursor: pointer; background: var(--surface); text-align: center; position: relative; }
.media-add:hover, .media-add.is-drag { border-color: var(--text); color: var(--text); }
.media-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.video-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); font-size: var(--fs-sm); }
.video-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-row label.btn { position: relative; }
.video-row label.btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.need { color: var(--bad); font-size: var(--fs-sm); display: flex; align-items: center; gap: 4px; }

.packages { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.pack { border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); padding: 6px 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.pack-main { display: grid; grid-template-columns: auto minmax(0, 1fr) 96px auto; gap: 6px; align-items: center; }
.pack-main .included { font-size: var(--fs-xs); color: var(--ok); font-weight: 600; text-align: right; padding-right: 4px; }
.pack-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.pack-detail input { height: 28px !important; font-size: var(--fs-sm); }
.pack.is-off { opacity: .6; }
.pack-empty { font-size: var(--fs-sm); color: var(--faint); }

.add-group { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: var(--fs-sm); }

/* Events */
.event-list { display: grid; gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.event-row { display: grid; grid-template-columns: 120px 180px 1fr; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); align-items: start; }
.event-row:last-child { border-bottom: 0; }
.event-row.is-new { background: var(--accent-soft); }
.event-row time { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

/* Menu / popover */
.menu, .popover { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-pop); }
.menu { min-width: 190px; padding: 4px; }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 10px; border: 0; background: none; border-radius: var(--r-sm); text-align: left; }
.menu button:hover { background: var(--surface-3); }
.menu button.danger { color: var(--bad); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.popover { width: 360px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto; padding: 10px; }
.popover h4 { font-size: var(--fs-md); margin-bottom: 8px; }
.issue { display: flex; align-items: flex-start; gap: 8px; width: 100%; padding: 7px 8px; border: 0; background: none; border-radius: var(--r-sm); text-align: left; }
.issue:hover { background: var(--surface-3); }
.issue .ic { color: var(--bad); margin-top: 1px; }
.issue small { display: block; color: var(--faint); font-size: var(--fs-xs); }
.issue-ok { display: flex; gap: 8px; align-items: center; color: var(--ok); padding: 6px 8px; }

/* Dialog */
.dialog { width: min(640px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); color: var(--text); }
.dialog::backdrop { background: rgba(20, 19, 17, .38); }
.dialog-wide { width: min(860px, calc(100vw - 24px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: var(--fs-lg); }
.dialog-head-actions { display: flex; gap: 8px; align-items: center; }
.dialog-body { padding: 14px 16px; max-height: 70vh; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.dialog-preview { width: min(1400px, calc(100vw - 24px)); height: calc(100vh - 24px); max-height: none; }
.dialog-preview[open] { display: flex; flex-direction: column; }
.preview-stage { flex: 1; background: var(--surface-3); display: flex; justify-content: center; min-height: 0; }
.preview-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-stage.is-mobile iframe { width: 390px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.lead { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.lead:last-child { border-bottom: 0; }
.lead small { display: block; color: var(--muted); font-size: var(--fs-sm); }

.toast { position: fixed; left: 50%; bottom: 20px; z-index: 80; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; padding: 9px 14px; border-radius: var(--r); background: var(--primary); color: #fff; font-weight: 500; transition: opacity .18s, transform .18s; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px rgba(179,55,42,.35); } 100% { box-shadow: 0 0 0 3px rgba(179,55,42,0); } }

/* ---------- Responsive: iPad portrait and narrower ---------- */
@media (max-width: 1100px) {
  :root { --rail-w: 208px; }
  .work { padding: 14px 14px 64px; }
}
@media (max-width: 900px) {
  .editor-body { grid-template-columns: minmax(0, 1fr); background: none; }
  .rail { background: var(--surface); position: sticky; top: calc(var(--appbar-h) + var(--eb-h, var(--editorbar-h))); z-index: 15; max-height: none; display: flex; gap: 4px; align-items: center; overflow-x: auto; padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--border); scrollbar-width: none; }
  .rail-label, .rail-sub { display: none; }
  .rail-item { width: auto; flex: none; grid-template-columns: none; grid-auto-flow: column; min-height: 34px; }
  .rail-item .rail-sum, .rail-item small { display: none; }
  .rail-item.is-on { box-shadow: inset 0 -2px 0 var(--accent); }
  .rail-add { margin: 0; flex: none; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-row { grid-template-columns: 110px 1fr; }
  .event-row > :last-child { grid-column: 2; }
}
@media (max-width: 640px) {
  .appbar { gap: 12px; padding: 0 10px; }
  .appbar-save { display: none; }
  .view:not(.view-editor) { padding: 12px 12px 32px; }
  .editor-bar { padding: 8px 12px; position: static; }
  .rail { top: var(--appbar-h); }
  .eb-title { flex-basis: 100%; }
  .eb-actions { flex-wrap: wrap; }
  .g2, .g3, .g4, .product-row, .pack-detail { grid-template-columns: minmax(0, 1fr); }
  .sort { margin-left: 0; }
  .search { max-width: none; }
  .win-wrap { overflow-x: auto; margin: 0 -12px; padding: 0 12px; }
  .win-table { min-width: 560px; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }
  .projects-table th:nth-child(4), .projects-table td:nth-child(4), .projects-table th:nth-child(7), .projects-table td:nth-child(7) { display: none; }
}
