/* Active Source app — same look as the approved mockup (mockup/app.html). */
:root {
  --brand: #2e2a80;
  --brand-soft: #eceafb;
  --magenta: #c2128f;
  --magenta-soft: #f8e4f2;
  --ink: #2f2d2b;
  --muted: #6f6c68;
  --faint: #a29f9a;
  --line: #e4e2de;
  --bg: #f5f4f2;
  --card: #fff;
  --ok: #1f7a4d; --ok-bg: #e3f4ea;
  --warn: #9a5b00; --warn-bg: #fdf0d9;
  --danger: #b42318;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Open Sans", Arial, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: inherit; }

/* ---------- Layout: sidebar + main ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--card); border-right: 1px solid var(--line);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .logo-link { display: block; margin: 0 0 26px; }
.sidebar .logo { width: 150px; display: block; margin: 0 auto; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav a.later { color: var(--faint); pointer-events: none; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav-group { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 16px 12px 6px; }
.soon { margin-left: auto; font-size: 10px; font-weight: 700; color: var(--faint); border: 1px solid var(--line); border-radius: 99px; padding: 1px 7px; }
.new-btn { margin: 0 0 10px; }
.sidebar .spacer { flex: 1; }
.sidebar-foot { font-size: 12px; color: var(--muted); padding: 12px 12px 0; border-top: 1px solid var(--line); line-height: 1.5; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .who { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .btn { align-self: flex-start; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #f5f4f2, #eceafb); }
.login[hidden] { display: none; }
.login .card { width: 100%; max-width: 380px; padding: 34px 32px; }
.login .logo { width: 180px; margin: 0 auto 24px; display: block; }
.login .field { margin-bottom: 14px; }
.login .error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.login .hint { margin-top: 14px; text-align: center; }

main { padding: 28px 32px 48px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; min-height: 44px; }
h1 { font-size: 22px; font-weight: 700; }
.sub { color: var(--muted); margin-top: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); padding: 9px 16px; border-radius: 8px;
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: #cfccc7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.soft { background: var(--brand-soft); border-color: var(--brand-soft); color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { background: none; border: 0; padding: 4px; cursor: pointer; color: var(--muted); border-radius: 6px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
.link { color: var(--brand); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat .k { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat .d { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { justify-content: center; color: var(--ink); }
.empty p { margin-bottom: 18px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 0 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.r { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; white-space: nowrap; border: 0; }
.tag.q { background: var(--magenta-soft); color: var(--magenta); }
.tag.inv { background: var(--brand-soft); color: var(--brand); }
.tag.plain { background: var(--bg); color: var(--muted); }
.tag.draft { background: transparent; color: var(--faint); border: 1px dashed #cfccc7; }
.tag.paid { background: var(--ok-bg); color: var(--ok); }
.tag.unpaid { background: var(--warn-bg); color: var(--warn); }
/* Status labels keep one width so the table doesn't jump when Төлсөн ⇄ Төлөөгүй */
.tag.paid, .tag.unpaid, td > .tag.draft { min-width: 92px; text-align: center; }
button.tag { cursor: pointer; }
button.tag:hover { filter: brightness(.96); }
.lang-tag { font-size: 11px; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.row-actions { display: inline-flex; gap: 2px; vertical-align: middle; }
.filters { display: flex; gap: 10px; margin-bottom: 16px; }
.filters .input { width: auto; }
.search { flex: 1; max-width: 340px; }

/* ---------- Editor: form + live preview ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: 20px; align-items: start; }
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.input { border: 1px solid #d6d3ce; border-radius: 8px; padding: 9px 11px; background: #fff; width: 100%; }
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.input.locked { background: var(--bg); color: var(--muted); }
.input.invalid { border-color: var(--danger); }
.row { display: grid; gap: 12px; }
.row.c2 { grid-template-columns: 1fr 1fr; }
.row.c3 { grid-template-columns: 1fr 1fr 1fr; }
.seg { display: inline-flex; border: 1px solid #d6d3ce; border-radius: 8px; overflow: hidden; align-self: flex-start; }
.seg button { border: 0; background: #fff; padding: 8px 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.row.pay-row { grid-template-columns: auto minmax(0, 1fr); }   /* "Бүтэн төлбөр | Урьдчилгаа" keeps its width */
.seg button.on { background: var(--brand); color: #fff; }
.hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ok); }

.items { display: flex; flex-direction: column; gap: 10px; container-type: inline-size; }
.item, .items-head { display: grid; grid-template-columns: 1fr 70px 120px 110px 28px; gap: 8px; align-items: start; }
.items-head { font-size: 12px; font-weight: 600; color: var(--muted); }
.item .note { grid-column: 1; margin-top: -2px; font-size: 13px; padding: 7px 11px; }
.item .amount { padding: 9px 0; text-align: right; font-weight: 600; white-space: nowrap; }
.cell { display: block; min-width: 0; }
.cell-label { display: none; }   /* only on phones, where the column headings are hidden */
.item .icon-btn { margin-top: 6px; }
/* Dropdown list for saved clients / products (js/suggest.js) */
.combo { position: relative; min-width: 0; }
.combo .input { padding-right: 34px; }
.combo-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 6px; display: grid; place-items: center; }
.combo-toggle:hover { background: var(--bg); color: var(--ink); }
.combo-toggle svg { width: 16px; height: 16px; }
.item .combo { grid-column: 1; }
.suggest {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
  max-height: 260px; overflow-y: auto; padding: 4px; min-width: 240px;
}
.suggest li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.suggest li:hover, .suggest li.active { background: var(--brand-soft); }
.suggest li span { font-weight: 600; }
.suggest small { color: var(--muted); font-size: 12px; }
.add-line { color: var(--brand); font-weight: 600; background: none; border: 1px dashed #c9c5f0; border-radius: 8px; padding: 9px; cursor: pointer; }

.summary div { display: flex; justify-content: space-between; padding: 4px 0; }
.summary .big { font-weight: 700; font-size: 16px; color: var(--brand); border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.actions { display: flex; gap: 10px; }
.save-hint { margin-top: -6px; text-align: right; }
.danger-zone { text-align: right; }

.banner { display: flex; gap: 12px; align-items: center; background: var(--brand-soft); color: var(--brand); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-weight: 600; }
.banner svg { width: 18px; height: 18px; flex: none; }
.banner span { font-weight: 400; color: var(--ink); }
.banner .link { text-decoration: underline; }
.paid-box { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: var(--bg); }

.preview { position: sticky; top: 20px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--muted); font-weight: 600; font-size: 13px; }
.sheet-wrap { width: 520px; height: 736px; overflow: hidden; max-width: 100%; border-radius: 6px; box-shadow: 0 6px 30px rgba(0,0,0,.10); background: #fff; }
.sheet-wrap iframe { width: 794px; height: 1123px; border: 0; transform: scale(.655); transform-origin: 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); transition: opacity .4s; z-index: 10;
}
.toast.hide { opacity: 0; }

/* ---------- Smaller screens ---------- */
@media (max-width: 1280px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
}
.mobile-bar, .scrim { display: none; }

/* Item rows: when the form column is narrow (phones, or a small desktop window next to the preview),
   the name and note get the full width and Тоо / Нэгж үнэ / Дүн sit below with their own labels. */
@container (max-width: 600px) {
  .items-head { display: none; }
  .item { grid-template-columns: 76px 1fr auto 40px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  .item .combo, .item .note { grid-column: 1 / -1; }
  .cell-label, .item .amount::before { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
  .item .amount { padding: 0; text-align: left; }
  .item .amount::before { content: attr(data-label); }
  .item .amount { display: flex; flex-direction: column; }
  .item .amount::before { margin-bottom: 14px; }   /* label in line with Тоо / Нэгж үнэ, amount in line with their boxes */
  .item .icon-btn { align-self: end; margin-bottom: 2px; }
}

/* ---------- Phones and small tablets ---------- */
@media (max-width: 900px) {
  /* Top bar: ☰ menu · logo · + new quotation. The sidebar slides in from the left. */
  .app { display: block; }
  .mobile-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 30; height: 56px; padding: 0 12px;
    background: var(--card); border-bottom: 1px solid var(--line);
  }
  .mobile-bar .logo { height: 34px; width: auto; display: block; }
  .mobile-bar .icon-btn, .mobile-bar .btn { width: 44px; height: 44px; padding: 0; }
  .mobile-bar .icon-btn svg, .mobile-bar .btn svg { width: 22px; height: 22px; }
  .sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: 280px; max-width: 85vw; height: auto;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.18);
  }
  body.nav-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); }
  body.nav-open .scrim { display: block; }
  body.nav-open { overflow: hidden; }
  .nav a { padding: 12px; }

  main { padding: 16px 16px 40px; }
  h1 { font-size: 20px; }
  .topbar { flex-wrap: wrap; margin-bottom: 16px; }
  .topbar > .btn { width: 100%; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .v { font-size: 20px; }
  .card { padding: 16px; }
  .card h2 { flex-wrap: wrap; }
  .filters .search { max-width: none; }

  /* Bigger touch targets; 16px text so phones don't zoom in when you tap a box */
  .input, select.input { font-size: 16px; min-height: 44px; }
  .icon-btn { width: 40px; height: 40px; }
  .seg button { min-height: 42px; }

  /* Lists: each row becomes a small card (labels come from the column headings, see main.js) */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.cards tr:last-child { border-bottom: 0; }
  table.cards td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex: none; }
  table.cards td:first-child { font-size: 16px; padding-bottom: 6px; justify-content: flex-start; }
  table.cards td:first-child::before, table.cards td.actions-cell::before { display: none; }
  table.cards td.actions-cell { justify-content: flex-end; flex-wrap: wrap; padding-top: 8px; }

  /* Form */
  .row.c2, .row.c3 { grid-template-columns: 1fr; }
  .editor > * { min-width: 0; }
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; min-height: 46px; }
  .actions .btn.primary { order: -1; }
  .save-hint { text-align: left; margin-top: 0; }
  .banner { align-items: flex-start; }

  /* PDF preview: the whole A4 page, shrunk to the screen width (editor.js sets the scale) */
  .sheet-wrap { width: 100%; }
}
