/* Cheapa Docs — app / dashboard styles. Mobile-first. */

.app-body { display: flex; min-height: 100vh; background: var(--paper); }

/* ---------- Dark theme overrides (app) ---------- */
[data-theme="dark"] .sidebar,
[data-theme="dark"] .bottomnav { background: var(--card); border-color: var(--line); }
[data-theme="dark"] .topbar { background: rgba(23,26,32,.85); border-color: var(--line); }
[data-theme="dark"] .block, [data-theme="dark"] .kpi, [data-theme="dark"] .set-card,
[data-theme="dark"] .set-profile, [data-theme="dark"] .qa, [data-theme="dark"] .type-card,
[data-theme="dark"] .period-panel, [data-theme="dark"] .toolbar .search .input { background: var(--card); border-color: var(--line); }
[data-theme="dark"] .side-link { color: var(--muted); }
[data-theme="dark"] .side-link:hover, [data-theme="dark"] .set-row:hover, [data-theme="dark"] .qa:hover { background: #1E222A; }
[data-theme="dark"] .side-link.active { background: var(--green-100); color: var(--green); }
[data-theme="dark"] .avatar, [data-theme="dark"] .set-ava { background: var(--green); color: var(--green-ink); }
[data-theme="dark"] .pill { background: var(--card); border-color: var(--line); color: var(--muted); }
[data-theme="dark"] .pill.active { background: var(--green); color: var(--green-ink); border-color: var(--green); }
[data-theme="dark"] .set-ic { border-color: var(--line); color: var(--ink); }
[data-theme="dark"] .tpl-stage { background: #0B0D10; }
[data-theme="dark"] .viewer { background: var(--paper); }
[data-theme="dark"] .pv-stage { background: #0B0D10; border-color: var(--line); }
[data-theme="dark"] .item-row .del { background: rgba(240,68,56,.15); color: #FDA29B; }
[data-theme="dark"] .ed-totals.grand { border-color: var(--line); }
[data-theme="dark"] .doc-dl { background: #1E222A; border-color: var(--line); color: var(--muted); }

/* ---------- Sidebar (desktop) ---------- */
.sidebar {
  width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--line);
  position: fixed; inset: 0 auto 0 0; display: none; flex-direction: column;
  padding: 16px 14px; z-index: 40;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-link {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
  color: var(--muted); font-weight: var(--fw-medium); font-size: 15px;
}
.side-link:hover { background: var(--line-2); color: var(--ink); }
.side-link.active { background: var(--green-100); color: var(--green-700); font-weight: var(--fw-semibold); }
.side-link svg { flex: none; }
.side-foot { margin-top: auto; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 10px 4px; margin-top: 8px; border-top: 1px solid var(--line); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 700; flex: none; }
.su-meta { min-width: 0; }
.su-meta b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.su-meta span { font-size: 12px; color: var(--muted); }

/* ---------- Main + topbar ---------- */
.app-main { flex: 1; min-width: 0; overflow-x: hidden; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  background: rgba(255,255,255,.85); backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.tb-title h1 { font-size: 19px; }
.tb-actions .btn { height: 42px; }
.app-content { padding: 18px; max-width: 1180px; margin: 0 auto; padding-bottom: calc(var(--bottombar-h) + 28px); }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  display: flex; position: fixed; inset: auto 0 0 0; height: var(--bottombar-h);
  background: #fff; border-top: 1px solid var(--line); justify-content: space-around;
  align-items: center; z-index: 40; padding: 0 6px; padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--muted-2); font-weight: 500; flex: 1; }
.bottomnav a.active { color: var(--green-700); }
.bottomnav a.fab {
  width: 54px; height: 54px; border-radius: 50%; background: var(--green); color: var(--green-ink);
  justify-content: center; margin-top: -22px; box-shadow: var(--shadow-green); flex: none;
}
.bottomnav a.fab svg { width: 26px; height: 26px; }

/* ---------- Warning banner ---------- */
.warn-banner { display: flex; gap: 12px; align-items: flex-start; background: #FEF0C7; border: 1px solid #FEDF89;
  color: #93370D; border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; }
.warn-banner b { font-size: 14px; } .warn-banner p { font-size: 13px; margin-top: 2px; }
.warn-banner span { flex: none; color: #B54708; }
[data-theme="dark"] .warn-banner { background: rgba(247,144,9,.12); border-color: rgba(247,144,9,.4); color: #FEDF89; }
[data-theme="dark"] .warn-banner span { color: #FEC84B; }

/* ---------- Greeting ---------- */
.greet { margin-bottom: 18px; }
.greet h2 { font-size: 22px; }
.greet p { color: var(--muted); margin-top: 2px; }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.kpi .k-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.kpi .k-ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--green-100); color: var(--green-700); }
.kpi .k-val { font-size: 24px; font-weight: 700; margin-top: 12px; letter-spacing: -.02em; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.trend-up { color: var(--up); font-weight: 600; } .trend-down { color: var(--down); font-weight: 600; }
.k-btn { border: 0; cursor: pointer; padding: 0; }
.k-btn:hover { background: var(--green); color: #fff; }

/* Period picker */
.period-panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-top: 14px; box-shadow: var(--shadow-sm); }
.period-presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.period-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.period-form label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.period-form .input { height: 46px; max-width: 180px; }

/* ---------- Admin: clickable cards, bars, chart ---------- */
.kpi-link { display: block; color: inherit; transition: border-color .15s, transform .08s, box-shadow .15s; }
.kpi-link:hover { border-color: var(--green); transform: translateY(-2px); box-shadow: var(--shadow); }
.block-link { display: block; color: inherit; transition: border-color .15s, transform .08s, box-shadow .15s; }
.block-link:hover { border-color: var(--green); transform: translateY(-2px); box-shadow: var(--shadow); }
.block-cta { font-size: 13px; color: var(--green-700); font-weight: 600; }
.admin-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 16px; }
.bar-item { margin-bottom: 12px; }
.bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar-top b { font-weight: 700; }
.bar-track { height: 8px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.bar-track span { display: block; height: 100%; background: var(--green); border-radius: 999px; }
.bar-sub { font-size: 11px; color: var(--muted-2); margin-top: 3px; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.chart-bar { width: 70%; max-width: 26px; background: var(--green); border-radius: 5px 5px 0 0; min-height: 2px; transition: opacity .15s; }
.chart-col:hover .chart-bar { background: var(--green-600); }
.chart-x { font-size: 9px; color: var(--muted-2); margin-top: 4px; }

/* ---------- Section blocks ---------- */
.block { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-top: 16px; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.block-head h3 { font-size: 16px; }
.block-head a { font-size: 13px; color: var(--green-700); font-weight: 600; }

/* ---------- Quick actions ---------- */
.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.qa { border: 1px solid var(--line); border-radius: 16px; padding: 16px; text-align: center;
  background: #fff; transition: border-color .15s, transform .08s; }
.qa:hover { border-color: var(--green); transform: translateY(-2px); }
.qa .qa-ic { font-size: 22px; }
.qa b { display: block; margin-top: 8px; font-size: 14px; }

/* ---------- Document list rows ---------- */
.doc-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line-2); }
.doc-row:last-child { border-bottom: 0; }
.doc-rowlink { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; color: inherit; }
.doc-actions { display: flex; gap: 6px; margin-left: 6px; flex: none; }
.doc-dl { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--paper); border: 1px solid var(--line); font-size: 15px; color: var(--ink-2); text-decoration: none; }
.doc-dl:hover { border-color: var(--green); color: var(--green-700); }
.doc-dl.doc-share { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.doc-dl.doc-share:hover { background: var(--green-600); }
.doc-ic { width: 40px; height: 40px; border-radius: 11px; background: var(--paper); display: grid;
  place-items: center; font-size: 13px; font-weight: 700; color: var(--ink-2); flex: none; text-transform: uppercase; }
.doc-main { min-width: 0; flex: 1; }
.doc-main b { font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-main span { font-size: 12px; color: var(--muted); }
.doc-amt { text-align: right; white-space: nowrap; }
.doc-amt b { font-size: 14px; } .doc-amt span { font-size: 11px; color: var(--muted); display: block; }
.status { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.status.completed { background: var(--green-100); color: var(--green-700); }
.status.draft { background: #FEF0C7; color: #B54708; }
.status.cancelled { background: #FEE4E2; color: #B42318; }
.status.archived { background: var(--line); color: var(--muted); }

/* ---------- Settings / Profile list ---------- */
.set-profile { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line);
  border-radius: 18px; padding: 16px; }
.set-ava { width: 56px; height: 56px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 22px; font-weight: 700; flex: none; }
.set-name { font-size: 18px; font-weight: 700; line-height: 1.2; }
.set-email { color: var(--muted); font-size: 14px; }
.set-group-label { color: var(--muted); font-size: 13px; font-weight: 600; margin: 20px 4px 8px; }
.set-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.set-row { display: flex; align-items: center; gap: 14px; padding: 15px 16px; color: inherit; border-bottom: 1px solid var(--line-2); }
.set-row:last-child { border-bottom: 0; }
.set-row:hover { background: var(--line-2); }
.set-ic { width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line);
  display: grid; place-items: center; color: var(--ink); flex: none; }
.set-label { flex: 1; font-weight: 500; font-size: 15px; }
.set-val { color: var(--muted); font-size: 14px; }
.set-chev { color: var(--muted-2); display: flex; }
.set-row.soon { cursor: default; } .set-row.soon:hover { background: transparent; }
.set-row.danger { justify-content: center; color: var(--down); font-weight: 600; }
.set-row.danger:hover { background: #FEF3F2; }

/* ---------- Accent colour swatches ---------- */
.accent-swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.asw { width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  box-shadow: 0 0 0 2px var(--line); transition: transform .1s ease, box-shadow .15s ease; }
.asw:hover { transform: scale(1.12); }
.asw.active { box-shadow: 0 0 0 2px var(--card), 0 0 0 4.5px var(--ink); transform: scale(1.08); }

/* ---------- Signature pad ---------- */
.sig-inks { display: flex; gap: 10px; margin-bottom: 10px; }
.sig-ink { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  box-shadow: 0 0 0 2px var(--line); padding: 0; }
.sig-ink.active { box-shadow: 0 0 0 2.5px var(--green); }
.sig-pad-wrap { position: relative; max-width: 562px; }
.sig-pad { display: block; background: #fff; border: 1.5px dashed var(--muted-2); border-radius: 14px;
  cursor: crosshair; width: 100%; }
.sig-pad-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted-2); font-size: 15px; pointer-events: none; }
[data-theme="dark"] .sig-pad { border-color: var(--muted); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; }
.empty .e-emoji { font-size: 40px; }
.empty p { color: var(--muted); margin: 8px 0 18px; }

/* ---------- Document type picker ---------- */
.types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.type-card { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 18px;
  padding: 18px; display: block; transition: border-color .15s, transform .08s; }
.type-card.on:hover { border-color: var(--green); transform: translateY(-2px); }
.type-card.off { opacity: .55; pointer-events: none; }
.type-card .t-emoji { font-size: 26px; }
.type-card b { display: block; margin-top: 10px; font-size: 15px; }
.type-card span { font-size: 12px; color: var(--muted); }
.type-card .soon { position: absolute; top: 12px; right: 12px; font-size: 10px; background: var(--line);
  color: var(--muted); padding: 2px 8px; border-radius: 999px; }

/* ---------- Template gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tpl-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 8px;
  display: flex; flex-direction: column; box-shadow: var(--shadow-sm);
  transition: transform .1s ease, box-shadow .15s ease; }
.tpl-stretch { position: absolute; inset: 0; z-index: 3; border-radius: 18px; }
.tpl-card .btn-use { position: relative; z-index: 4; }
.tpl-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.tpl-stage { position: relative; height: 172px; background: #EEF0F3; border-radius: 12px; overflow: hidden; }
.tpl-frame { position: absolute; top: 0; left: 0; border: 0; transform-origin: top left; pointer-events: none; visibility: hidden; }
.tpl-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tpl-ov-badge { position: absolute; top: 8px; left: 8px; z-index: 2; display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.94); border-radius: 999px; padding: 3px 9px; font-size: 11px; font-weight: 600;
  color: #9A6B00; box-shadow: 0 2px 8px rgba(16,24,40,.12); }
.tpl-ov-badge.feat { color: var(--green-700); }
.tpl-body { padding: 10px 6px 0; }
.tpl-name { font-size: 14px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.tpl-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 6px 4px; flex-wrap: wrap; }
.tpl-tier { background: var(--paper); border-radius: 999px; padding: 4px 11px; font-size: 11px; font-weight: 600; color: var(--ink-2); }
.btn-use { background: #0B0B0B; color: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s;
  flex: 1 0 auto; white-space: nowrap; }
.btn-use svg { width: 14px; height: 14px; }
.btn-use:hover { background: #000; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 1fr; gap: 16px; }
.ed-form { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.ed-group { margin-bottom: 18px; }
.ed-group > h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2);
  margin-bottom: 10px; }
.ed-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ed-preview { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px; overflow: hidden; }
.ed-preview .pv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 12px; }
.ed-preview .pv-head b { font-size: 13px; color: var(--muted); }
.pv-zoom { display: inline-flex; gap: 4px; }
.pv-zoom button { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px;
  min-width: 30px; height: 28px; font-size: 13px; font-weight: 700; cursor: pointer; padding: 0 8px; }
.pv-zoom button:hover { border-color: var(--green); color: var(--green-700); }
.pv-stage { position: relative; min-height: 220px; overflow: auto; background: #EEF0F3; border: 1px solid var(--line); border-radius: 12px; }
.ed-frame { display: block; border: 0; background: #fff; transform-origin: top left; width: 900px; height: 1200px; max-width: none; }
.tpl-frame { max-width: none; }

/* Items table editor */
.items-ed { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 56px 90px 32px; gap: 8px; align-items: center; }
.item-row .input { height: 42px; padding: 0 10px; font-size: 14px; }
.item-row .del { border: 0; background: #FEE4E2; color: #B42318; width: 32px; height: 32px;
  border-radius: 9px; cursor: pointer; font-size: 16px; line-height: 1; }
.item-head { display: grid; grid-template-columns: 1fr 56px 90px 32px; gap: 8px; font-size: 11px;
  color: var(--muted-2); text-transform: uppercase; letter-spacing: .04em; padding: 0 2px; }
.add-item { align-self: flex-start; margin-top: 4px; background: var(--green-100); color: var(--green-700);
  border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 600; cursor: pointer; font-size: 13px; }
.ed-totals { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 2px; }
.ed-totals.grand { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }

.ed-actions { display: flex; gap: 10px; margin-top: 8px; }
.brand-toggles { display: flex; flex-direction: column; gap: 12px; }
.bt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer; }

/* ---------- Toolbar (document view) ---------- */
.doc-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.doc-toolbar .left { display: flex; gap: 10px; align-items: center; }
.doc-actions-scroll { display: flex; gap: 10px; align-items: center; overflow-x: auto;
  -webkit-overflow-scrolling: touch; padding-bottom: 4px; max-width: 100%; scrollbar-width: thin; }
.doc-actions-scroll .btn, .doc-actions-scroll form { flex: 0 0 auto; }
.doc-actions-scroll::-webkit-scrollbar { height: 5px; }
.doc-actions-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.viewer { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.viewer iframe { width: 100%; height: 78vh; border: 0; background: #fff; }

/* ---------- Search / filters ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; position: relative; }
.search .input { padding-left: 40px; }
.search svg { position: absolute; left: 13px; top: 14px; color: var(--muted-2); }
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px;
  font-size: 13px; color: var(--muted); font-weight: 500; cursor: pointer; }
.pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Responsive ---------- */
@media (min-width: 720px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .types { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .editor { grid-template-columns: 1fr 1fr; align-items: start; }
  .ed-preview { position: sticky; top: 80px; }
}
@media (min-width: 960px) {
  .sidebar { display: flex; }
  .app-main { margin-left: var(--sidebar-w); }
  .bottomnav { display: none; }
  .app-content { padding: 24px; padding-bottom: 40px; }
  .gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tpl-stage { height: 270px; }
  .tpl-name { font-size: 16px; }
  .tpl-body { padding: 14px 8px 0; }
  .btn-use { padding: 10px 18px; font-size: 14px; flex: 0 0 auto; }
}
