:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #66716b;
  --line: #dce2de;
  --accent: #2f9a4e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4ea;
  --danger: #c0392b;
  --warn-bg: #fff6e0;
  --warn-ink: #7a5600;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}
[hidden] { display: none !important; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .92rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-title { font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); padding-left: 12px; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font: inherit; color: var(--muted);
}
.tab:hover { background: var(--bg); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: .75rem; line-height: 18px; text-align: center;
}

/* ---------- layout ---------- */
#view-documents, #view-offer {
  display: grid; grid-template-columns: minmax(420px, 640px) 1fr; gap: 20px;
  padding: 20px; align-items: start;
}
.editor { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.preview {
  position: sticky; top: 72px; height: calc(100vh - 92px);
  display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.preview iframe { flex: 1; width: 100%; border: 0; background: #525659; }

#view-registry, #view-settings { padding: 20px; max-width: 1280px; margin: 0 auto; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.settings-grid .wide { grid-column: 1 / -1; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}

/* ---------- form ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span { font-size: .8rem; color: var(--muted); font-weight: 500; }
.field.grow { flex: 1; margin-bottom: 0; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input.is-missing, textarea.is-missing { border-color: #e0a100; background: #fffdf5; }
.check { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: .9rem; }
.check input { width: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.span-2 { grid-column: 1 / -1; }
.eik-row { display: flex; gap: 10px; align-items: flex-end; }
.hint { font-size: .82rem; color: var(--muted); margin: 4px 0 10px; }
.muted { color: var(--muted); font-size: .85rem; }
.status { min-height: 20px; font-size: .85rem; margin: 6px 0 8px; }
.status.ok { color: var(--accent); }
.status.err { color: var(--danger); }
.status.busy { color: var(--muted); }
.more { margin: 6px 0 4px; font-size: .9rem; }
.more summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.more pre { max-height: 260px; overflow: auto; background: var(--bg); padding: 10px; border-radius: 7px; font-size: .75rem; }
.addon-picker { margin-top: 14px; }
.input-with-btn { display: flex; gap: 6px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: #b9c3bd; background: #fafbfa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.file-btn { position: relative; }

.segmented { display: inline-flex; background: var(--bg); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  font: inherit; border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; cursor: pointer; color: var(--muted);
}
.segmented button.is-active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented.small button { padding: 5px 11px; font-size: .88rem; }

/* ---------- order lines ---------- */
.line {
  border: 1px solid var(--line); border-radius: 9px; padding: 12px 12px 4px; margin-bottom: 10px; position: relative;
  background: #fcfdfc;
}
.line-head { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 2px; }
.line-head .field { flex: 1; }
.line-num { font-weight: 700; color: var(--muted); padding-bottom: 18px; min-width: 18px; }
.line-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 10px; }
.line-grid.rent { grid-template-columns: repeat(4, 1fr); }
.line .remove { margin-bottom: 10px; }
.line .calc { font-size: .8rem; color: var(--muted); margin: -4px 0 8px; }
.totals { margin-top: 10px; font-size: .88rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 18px; }
.totals b { color: var(--text); }

/* ---------- actions ---------- */
.sticky-actions { position: sticky; bottom: 12px; z-index: 5; }
.warnings { font-size: .84rem; color: var(--warn-ink); background: var(--warn-bg); border-radius: 7px; padding: 8px 10px; margin-bottom: 10px; }
.warnings:empty { display: none; }

/* ---------- tables ---------- */
.registry-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.registry-head h2 { margin: 0; }
.registry-head input[type=search] { max-width: 340px; flex: 1; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
th.group { text-align: center; border-bottom: 1px solid var(--line); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }
tr.expired td { background: #fdecea; }
tr.expiring td { background: #fff6e0; }
.pill { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 9px; margin-left: 6px; }
.pill.expired { background: var(--danger); color: #fff; }
.pill.expiring { background: #e0a100; color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
table.catalog input { padding: 5px 6px; min-width: 70px; }
table.catalog td:first-child input { min-width: 280px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1d2420; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: .9rem; z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100vw - 32px);
}

/* ---------- responsive ---------- */
@media (max-width: 1050px) {
  #view-documents, #view-offer { grid-template-columns: 1fr; }
  .preview { position: static; height: 80vh; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  :root { font-size: 14px; }
  .topbar { flex-direction: column; align-items: stretch; padding: 10px 16px; }
  #view-documents, #view-offer, #view-registry, #view-settings { padding: 12px 16px; }
  .grid-2, .grid-3, .line-grid, .line-grid.rent { grid-template-columns: 1fr 1fr; }
  .eik-row { flex-direction: column; align-items: stretch; }
}

/* ---------- offer ---------- */
.device { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px 2px; margin-bottom: 10px; background: #fcfdfc; }
.device.is-off { background: transparent; opacity: .65; }
.device.is-off .device-prices { display: none; }
.device-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 600; }
.device-head input[type=checkbox] { width: auto; }
.device-head .muted { font-weight: 400; }
.device-prices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 10px; }
.extra-row { display: grid; grid-template-columns: auto 1fr 110px 120px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.extra-row input[type=checkbox] { width: auto; }
.extra-row.is-off input:not([type=checkbox]), .extra-row.is-off select { opacity: .55; }
@media (max-width: 560px) {
  .device-prices { grid-template-columns: 1fr 1fr; }
  .extra-row { grid-template-columns: auto 1fr; }
}
