/* Movi Invoice — authenticated app shell, pages and invoice builder. */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--ink-900); color: #EDE7E0; display: flex; flex-direction: column;
  padding: var(--s5) var(--s4); gap: var(--s4);
}
.sidebar .brand { color: #fff; padding: 0 var(--s2); }
.sidebar .brand small { color: #A39A90; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: var(--s4); }
.nav a {
  display: flex; align-items: center; gap: var(--s3); padding: 10px 12px; border-radius: var(--r-md); color: #CFC7BE; text-decoration: none;
  font-size: var(--fs-sm); font-weight: 600;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: #262321; color: #fff; }
.nav a[aria-current="page"] { background: #2C2724; color: #fff; box-shadow: inset 3px 0 0 var(--orange-500); }
.sidebar .new-btn { margin-top: var(--s2); }
.sidebar-foot { margin-top: auto; border-top: 1px solid #2E2A27; padding-top: var(--s4); font-size: var(--fs-xs); color: #A39A90; }
.sidebar-foot .org { color: #fff; font-weight: 650; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot button { background: none; border: 0; color: #CFC7BE; font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }
.plan-chip { display: inline-block; margin-top: 6px; padding: 2px 8px; border-radius: 999px; background: #2C2724; color: #FFB98A; font-weight: 650; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: var(--s8) var(--s8) var(--s16); max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--text-muted); margin-top: 4px; font-size: var(--fs-sm); }
.banner { margin-bottom: var(--s4); }

.tabbar { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: 50; height: var(--header-h); align-items: center; justify-content: space-between;
    padding: 0 var(--s4); background: rgba(251, 248, 244, .96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  }
  .content { padding: var(--s5) var(--s4) calc(96px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-decoration: none; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--orange-600); }
}

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); margin-bottom: var(--s6); }
.stat { padding: var(--s5); }
.stat .k { font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.stat .v { font-size: var(--fs-2xl); font-weight: 750; margin-top: 6px; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.stat .d { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
@media (max-width: 960px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stat .v { font-size: var(--fs-xl); } }

.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.meter > span { display: block; height: 100%; background: var(--orange-500); border-radius: 999px; }

/* Filters */
.filters { display: grid; grid-template-columns: minmax(180px, 2fr) repeat(4, minmax(120px, 1fr)); gap: var(--s3); padding: var(--s4); border-bottom: 1px solid var(--border); }
@media (max-width: 960px) { .filters { grid-template-columns: 1fr 1fr; } .filters .grow { grid-column: span 2; } }

/* Settings tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--s6); overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink-900); border-bottom-color: var(--orange-500); }

/* Onboarding */
.onboard { max-width: 760px; margin: 0 auto; }
.steps { display: flex; gap: var(--s2); margin-bottom: var(--s6); }
.steps li { flex: 1; list-style: none; }
.steps { padding: 0; }
.steps .bar { height: 4px; border-radius: 4px; background: var(--border); }
.steps .on .bar { background: var(--orange-500); }
.steps .lbl { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 6px; font-weight: 600; }
@media (max-width: 600px) { .steps .lbl { display: none; } }
.upload { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.upload .thumb { width: 140px; height: 72px; border: 1px dashed var(--border-strong); border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; background: var(--surface-2); overflow: hidden; color: var(--text-faint); font-size: var(--fs-xs); }
.upload .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.swatches { display: flex; gap: var(--s2); flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink-900); }
.template-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s3); }
.template-pick label { border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: var(--s3); cursor: pointer; background: var(--surface); }
.template-pick input { position: absolute; opacity: 0; }
.template-pick input:checked + div { color: var(--ink-900); }
.template-pick label:has(input:checked) { border-color: var(--orange-500); box-shadow: var(--focus); }
.template-pick label.locked { opacity: .55; }
.template-pick .t-name { font-weight: 650; font-size: var(--fs-sm); }
.template-pick .t-desc { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------------------------------------------------------------- Invoice builder */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s6); align-items: start; }
.builder-form { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.builder-preview { position: sticky; top: var(--s6); max-height: calc(100vh - 48px); overflow: auto; border-radius: var(--r-lg); }
.builder-preview .pv-note { font-size: var(--fs-xs); color: var(--text-muted); margin: 0 0 var(--s2); display: flex; justify-content: space-between; gap: var(--s2); }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.section > summary, .section > .section-title {
  list-style: none; cursor: pointer; padding: var(--s4) var(--s5); font-weight: 650; display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted); transform: rotate(45deg); margin-right: 4px; transition: transform .15s; }
.section[open] > summary::after { transform: rotate(-135deg); }
.section > summary .sum { font-weight: 500; color: var(--text-muted); font-size: var(--fs-sm); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.section-body { padding: 0 var(--s5) var(--s5); display: grid; gap: var(--s4); }
.step-no { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--ink-900); color: #fff; font-size: 12px; align-items: center; justify-content: center; margin-right: 8px; flex: none; }

.lines { display: flex; flex-direction: column; gap: var(--s3); }
.line { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); background: var(--surface); display: grid; gap: var(--s2);
  grid-template-columns: minmax(0, 3fr) minmax(0, 1.1fr) minmax(0, 1.4fr) minmax(0, 1.4fr) auto; align-items: end; }
.line .f-desc { grid-column: 1 / -1; }
.line .f-name { grid-column: 1; }
.line .more { grid-column: 1 / -1; }
.line .more-grid { display: grid; gap: var(--s2); grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: var(--s2); }
.line .line-total { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--text-muted); border-top: 1px dashed var(--border); padding-top: var(--s2); }
.line .line-total b { color: var(--text); }
.line label { font-size: 11px; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.line .field { gap: 3px; }
@media (max-width: 1280px) {
  .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
  .line .f-name { grid-column: 1 / -1; }
  .line .more-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.totals-box { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s4); font-size: var(--fs-sm); }
.totals-box .tr { display: flex; justify-content: space-between; padding: 3px 0; }
.totals-box .grand { font-size: var(--fs-lg); font-weight: 750; border-top: 1px solid var(--border-strong); margin-top: 6px; padding-top: 8px; }
.calc-note { font-size: var(--fs-xs); color: var(--text-muted); }

.actionbar {
  position: sticky; bottom: 0; z-index: 40; background: rgba(255, 255, 255, .97); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s3);
  justify-content: space-between; box-shadow: var(--shadow-md); flex-wrap: wrap;
}
.actionbar .grand-mini { font-weight: 750; font-size: var(--fs-lg); }
.actionbar .grand-mini small { display: block; font-weight: 500; font-size: var(--fs-xs); color: var(--text-muted); }
.preview-toggle { display: none; }

@media (max-width: 1100px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder-preview { position: static; max-height: none; display: none; }
  .builder.show-preview .builder-preview { display: block; }
  .builder.show-preview .builder-form > :not(.actionbar) { display: none; }
  .preview-toggle { display: inline-flex; }
}
@media (max-width: 960px) {
  .actionbar { bottom: calc(64px + env(safe-area-inset-bottom)); border-radius: var(--r-md); }
}

/* Invoice detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s6); align-items: start; }
.detail aside { display: flex; flex-direction: column; gap: var(--s4); position: sticky; top: var(--s6); }
@media (max-width: 1100px) { .detail { grid-template-columns: minmax(0, 1fr); } .detail aside { position: static; order: -1; } }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.actions-grid .btn { width: 100%; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: var(--fs-sm); }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--orange-500); }
.timeline .when { font-size: var(--fs-xs); color: var(--text-muted); }

.preview-frame { background: #E9E4DD; border-radius: var(--r-lg); padding: var(--s4); overflow-x: auto; }
@media (max-width: 600px) { .preview-frame { padding: var(--s2); margin: 0 calc(-1 * var(--s2)); } }

/* Plans */
.plans { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); }
@media (max-width: 1100px) { .plans { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .plans { grid-template-columns: minmax(0, 1fr); } }
.plan { padding: var(--s6); display: flex; flex-direction: column; gap: var(--s3); }
.plan.current { border-color: var(--orange-500); box-shadow: 0 0 0 1px var(--orange-500); }
.plan .price { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -0.02em; }
.plan .price small { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); }
.plan ul { margin: 0; padding-left: 18px; font-size: var(--fs-sm); color: var(--ink-700); }
.plan li { margin: 4px 0; }

.loading { padding: var(--s12); text-align: center; color: var(--text-muted); }

@media (max-width: 600px) {
  .actionbar { padding: 8px 10px; gap: 8px; flex-wrap: nowrap; }
  .actionbar .grand-mini { font-size: var(--fs-md); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .actionbar .grand-mini small { display: none; }
  .actionbar .row { flex-wrap: nowrap; gap: 6px; }
  .actionbar .btn { min-height: 38px; padding: 0 10px; font-size: 13px; }
  .actionbar .preview-toggle svg { display: none; }
}
