/* NextCenturyIT Finance — Live Demo application styles (loaded on /demo only). */

.app-body { background: var(--paper); }
.app { min-height: 100vh; display: flex; flex-direction: column; }

.app-bar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  height: 64px;
  padding: 0 clamp(12px, 3vw, 24px);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.app-bar__brand .brand__mark { width: 32px; height: 32px; }
.app-bar__title { display: grid; line-height: 1.2; }
.app-bar__title strong { font: 800 1.02rem var(--font-head); color: var(--ink); letter-spacing: -0.02em; }
.app-bar__title span { font-size: .8rem; color: var(--teal-ink); font-weight: 600; }
.app-bar__actions { margin-left: auto; display: flex; gap: 8px; }
.app-bar .btn--small { min-height: 38px; padding: 6px 12px; font-size: .88rem; gap: 6px; }

.app-shell { flex: 1; display: grid; grid-template-columns: 232px minmax(0, 1fr); }

.app-nav {
  position: sticky; top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  display: flex; flex-direction: column; gap: 2px;
  padding: 20px 14px;
  background: var(--white);
  border-right: 1px solid var(--line);
}
.app-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
}
.app-nav a .icon { color: var(--muted); }
.app-nav a:hover { background: var(--paper); color: var(--ink); }
.app-nav a[aria-current="page"] { background: var(--blue-soft); color: var(--blue); }
.app-nav a[aria-current="page"] .icon { color: var(--blue); }
.app-nav__note {
  margin-top: auto;
  display: flex; gap: 8px; align-items: flex-start;
  padding: 12px;
  border-radius: 10px;
  background: var(--paper);
  font-size: .8rem; line-height: 1.45; color: var(--muted);
}
.app-nav__note .icon { flex: none; margin-top: 1px; color: var(--teal-ink); }

.app-main { min-width: 0; padding: clamp(16px, 3vw, 32px); display: flex; flex-direction: column; gap: 16px; }
.app-view { display: flex; flex-direction: column; gap: 20px; }
.app-disclaimer { margin-top: auto; padding-top: 24px; font-size: .8rem; color: var(--muted); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .app-nav {
    position: sticky; top: 64px; z-index: 40;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px clamp(12px, 3vw, 24px);
    border-right: 0;
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
  }
  .app-nav::-webkit-scrollbar { display: none; }
  .app-nav a { flex: none; padding: 8px 12px; font-size: .9rem; gap: 8px; }
  .app-nav__note { display: none; }
}
@media (max-width: 640px) {
  .app-bar__site { display: none; }
  .app-bar__title span, .app-bar .hide-sm { display: none; }
  .app-bar .btn--small { padding: 6px 10px; }
}

/* ---------- View header ---------- */

.view-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.view-head h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); letter-spacing: -0.03em; }
.view-head h1:focus { outline: none; }
.view-head p { margin: 6px 0 0; color: var(--muted); max-width: 64ch; }
.view-actions { display: flex; gap: 8px; }
.view-actions .btn { gap: 6px; }

/* ---------- KPIs ---------- */

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi {
  display: grid; gap: 4px;
  padding: 18px 20px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.kpi__label { font-size: .86rem; font-weight: 600; color: var(--muted); }
.kpi__value { font: 800 clamp(1.3rem, 2.2vw, 1.65rem) var(--font-head); color: var(--ink); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.kpi__note { font-size: .82rem; color: var(--muted); }
.kpi--good .kpi__value { color: var(--teal-ink); }
.kpi--bad .kpi__value { color: var(--danger); }
.kpi .warn { color: var(--danger); font-weight: 600; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 340px) { .kpis { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .kpi { padding: 14px; }
  .kpi__value { font-size: 1.15rem; }
  .ch-axis { font-size: 21px; }
}

/* ---------- Cards & layout ---------- */

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 20px;
  min-width: 0;
}
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin-bottom: 14px; }
.card__head h2 { font-size: 1.08rem; letter-spacing: -0.015em; }
.card__head .muted { font-size: .84rem; }
.card__head .text-link { font-size: .9rem; }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.dash-side { display: grid; gap: 16px; align-content: start; }
.report-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .dash-grid, .report-grid { grid-template-columns: minmax(0, 1fr); } }

.stat-list { margin: 0; display: grid; gap: 10px; }
.stat-list div { display: flex; justify-content: space-between; gap: 12px; font-size: .93rem; }
.stat-list dt { color: var(--muted); }
.stat-list dd { margin: 0; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-list__total { padding-top: 10px; border-top: 1px solid var(--line); }
.stat-list__total dt { color: var(--ink); font-weight: 650; }

.mini-list { list-style: none; display: grid; gap: 12px; }
.mini-list li { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; font-size: .9rem; }
.mini-list .link-cell { justify-self: start; }
.mini-list span { color: var(--muted); grid-column: 1; }
.mini-list strong { grid-column: 2; grid-row: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.mini-list em { grid-column: 2; grid-row: 2; font-style: normal; color: var(--danger); font-size: .82rem; text-align: right; }

.empty-note { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .92rem; margin: 0; }
.empty-note .icon { color: var(--teal-ink); }
.fine-print { font-size: .8rem; color: var(--muted); margin: 12px 0 0; }
.muted { color: var(--muted); }

/* ---------- Charts ---------- */

.chart { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-zero { stroke: var(--line-strong); stroke-width: 1; }
.ch-axis { fill: var(--muted); font: 500 11px var(--font-body); }
.ch-rev, .ch-profit, .ch-in { fill: var(--blue); }
.ch-rev.is-current { fill: var(--brand); }
.ch-exp, .ch-out { fill: #b8c4ec; }
.ch-out { fill: var(--teal); }
.ch-neg { fill: var(--danger); }
.ch-legend { display: flex; gap: 16px; margin: -4px 0 8px; font-size: .82rem; color: var(--muted); }
.ch-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ch-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.ch-swatch.ch-rev, .ch-swatch.ch-in, .ch-swatch.ch-profit { background: var(--blue); }
.ch-swatch.ch-exp { background: #b8c4ec; }
.ch-swatch.ch-out { background: var(--teal); }
.chart rect { transition: opacity .15s; }
.chart rect:hover { opacity: .8; }

.rank { list-style: none; display: grid; gap: 14px; }
.rank__head { display: flex; justify-content: space-between; gap: 12px; font-size: .9rem; margin-bottom: 6px; }
.rank__head strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.rank__bar { width: 100%; height: 6px; display: block; }
.rank__track { fill: var(--paper); }
.rank__fill { fill: var(--blue); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table thead th { font-size: .78rem; font-weight: 650; color: var(--muted); background: var(--paper); }
.card:not(.card--flush) .table thead th { background: none; }
.table tbody tr:hover { background: #fafbfe; }
.table tfoot th, .table tfoot td { font-weight: 650; color: var(--ink); border-bottom: 0; background: var(--paper); }
.table .num { text-align: right; }
.table .strong { font-weight: 650; color: var(--ink); }
.table .neg { color: var(--danger); }
.table td:nth-child(2) { white-space: normal; min-width: 160px; }
.table--report td:nth-child(2) { min-width: 0; white-space: nowrap; }
.table--report tbody th { font-weight: 600; color: var(--ink); }
.empty-row { text-align: center !important; color: var(--muted); padding: 32px 14px !important; white-space: normal !important; }

.cell-title { display: block; color: var(--ink); font-weight: 600; }
.cell-sub { display: block; color: var(--muted); font-size: .82rem; }
.cell-actions { text-align: right; width: 1%; }
.cell-actions .icon-btn + .icon-btn { margin-left: 2px; }

.link-cell { background: none; border: 0; padding: 0; font: inherit; font-weight: 650; color: var(--blue); cursor: pointer; }
.link-cell:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; }
.badge--paid { background: #e3f5ec; color: var(--success); }
.badge--unpaid { background: var(--blue-soft); color: var(--blue); }
.badge--overdue { background: #fdecea; color: var(--danger); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--paper); border: 1px solid var(--line); font-size: .8rem; color: var(--text); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--paper); border-color: var(--line); color: var(--ink); }
.icon-btn--danger:hover { color: var(--danger); background: #fdecea; border-color: #f7c9c4; }
.icon-btn[disabled] { opacity: .35; pointer-events: none; }

/* Stack table rows into cards on narrow screens */
@media (max-width: 700px) {
  .table--stack thead { display: none; }
  .table--stack, .table--stack tbody, .table--stack tfoot, .table--stack tr, .table--stack td, .table--stack th { display: block; width: 100%; }
  .table--stack tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table--stack td, .table--stack th { border: 0; padding: 4px 0; white-space: normal; text-align: right !important; display: flex; justify-content: space-between; gap: 16px; }
  .table--stack td::before { content: attr(data-label); color: var(--muted); font-weight: 500; text-align: left; }
  .table--stack td:not([data-label])::before { content: none; }
  .table--stack tbody th { justify-content: flex-start; font-size: 1rem; }
  .table--stack tfoot th { justify-content: flex-start; }
  .table--stack .cell-actions { justify-content: flex-end; width: 100%; padding-top: 8px; }
  .table--stack td:nth-child(2) { min-width: 0; }
  .table--stack .cell-title, .table--stack .cell-sub { text-align: right; }
  .table--stack .empty-row { display: block; text-align: center !important; }
  .table--stack .empty-row::before { content: none; }
  .card:not(.card--flush) .table--stack tr { padding-inline: 0; }
}

/* ---------- Toolbar ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.seg { display: inline-flex; padding: 3px; background: var(--white); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; max-width: 100%; }
.seg__btn {
  border: 0; background: none;
  padding: 7px 12px;
  border-radius: 7px;
  font: 600 .88rem var(--font-body);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg__btn span { margin-left: 4px; font-weight: 500; opacity: .8; }
.seg__btn:hover { color: var(--ink); }
.seg__btn[aria-pressed="true"] { background: var(--blue-soft); color: var(--blue); }

.search { position: relative; display: flex; align-items: center; flex: 0 1 300px; }
.search .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px 8px 38px;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  font: inherit;
  font-size: .92rem;
  background: var(--white);
  color: var(--ink);
}
.search input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(43, 72, 216, .14); }
@media (max-width: 640px) { .search { flex: 1 1 100%; } }

.select-inline { display: inline-flex; align-items: center; gap: 10px; font-size: .9rem; font-weight: 600; color: var(--ink); }
.input--small { min-height: 40px; padding: 8px 10px; font-size: .92rem; }
select.input { appearance: none; -webkit-appearance: none; padding-right: 34px; background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%235f6a88' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 10px center / 16px no-repeat; }

/* ---------- Dialog ---------- */

.dlg {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-l);
  background: var(--white);
  color: var(--text);
  box-shadow: 0 40px 100px -20px rgba(14, 26, 61, .45);
}
.dlg--large { width: min(860px, calc(100vw - 24px)); }
.dlg--small { width: min(420px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(11, 22, 56, .45); }
.dlg__body { padding: clamp(20px, 3vw, 28px); }
.dlg__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dlg__head h2 { font-size: 1.3rem; }
.dlg__head h2 .muted { font-weight: 600; font-size: .95rem; margin-left: 6px; font-family: var(--font-body); }
.dlg__head--plain { justify-content: flex-end; margin-bottom: -12px; }
/* Keep the status badge clear of the close button in the invoice view. */
.dlg__head--plain + .inv-doc .inv-doc__top { padding-right: 48px; }
.dlg__close { margin: -6px -6px 0 0; }
.dlg__text { margin: 0 0 8px; }
.dlg__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.btn--danger { background: var(--danger); color: var(--white); }
.btn--danger:hover { background: #8f1c13; color: var(--white); }
@media (prefers-reduced-motion: no-preference) {
  .dlg[open] { animation: dlg-in .18s ease-out; }
  @keyframes dlg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}
@media (max-width: 560px) {
  .dlg, .dlg--large, .dlg--small { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
}

.dform { display: grid; gap: 4px; }
.dgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.dgrid--3 { grid-template-columns: 2fr 1fr 1fr; }
.dgrid__full { grid-column: 1 / -1; }
@media (max-width: 640px) { .dgrid, .dgrid--3 { grid-template-columns: minmax(0, 1fr); } }
.dfield { display: grid; gap: 4px; align-content: start; }
.dfield label { display: grid; gap: 6px; font-weight: 600; font-size: .88rem; color: var(--ink); }
.dfield__label { font-weight: 600; font-size: .88rem; color: var(--ink); }
.dfield__output { min-height: 48px; display: flex; align-items: center; font: 750 1.1rem var(--font-head); color: var(--ink); }
.dfield__hint { font-size: .8rem; color: var(--muted); }
.dfield__error, .lines .dfield__error { font-size: .84rem; color: var(--danger); }
.dfield__error:empty { display: none; }

.lines { margin: 18px 0 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-m); display: grid; gap: 10px; }
.lines legend { padding: 0 6px; font: 700 .95rem var(--font-head); color: var(--ink); }
.lines__head, .line { display: grid; grid-template-columns: minmax(0, 1fr) 70px 110px 84px 104px 36px; gap: 8px; align-items: center; }
.lines__head { font-size: .76rem; font-weight: 650; color: var(--muted); }
.lines .btn { justify-self: start; gap: 6px; }
.line__total { text-align: right; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; font-size: .92rem; }
[data-lines] { display: grid; gap: 8px; }
@media (max-width: 720px) {
  .lines__head { display: none; }
  .line { grid-template-columns: 1fr 1fr 1fr auto; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .line__desc { grid-column: 1 / -1; }
  .line__total { grid-column: 1 / 4; text-align: left; }
}

.totals { margin: 16px 0 0 auto; width: min(300px, 100%); display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; gap: 12px; font-size: .93rem; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; font-weight: 600; color: var(--ink); }
.totals__gross { padding-top: 8px; border-top: 1px solid var(--line); }
.totals__gross dt, .totals__gross dd { font: 800 1.15rem var(--font-head); color: var(--ink); }

/* Invoice document */
.inv-doc__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.inv-doc__top h2 { font-size: 1.5rem; }
.inv-doc__label { margin: 0 0 4px; font-size: .78rem; font-weight: 650; color: var(--muted); }
.inv-doc__parties { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 16px; margin-bottom: 16px; background: var(--paper); border-radius: var(--radius-m); font-size: .9rem; }
.inv-doc__parties p { margin: 0; }
.inv-doc__parties strong { color: var(--ink); }
@media (max-width: 640px) { .inv-doc__parties { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  z-index: 400;
  transform: translate(-50%, 20px);
  max-width: min(460px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--navy);
  color: var(--white);
  font-weight: 550;
  font-size: .93rem;
  box-shadow: 0 20px 40px -12px rgba(11, 22, 56, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast--warn { background: #7a2e0e; }

/* Cookie banner sits above the demo's toast area */
.app-body .cookie-banner { z-index: 450; }
