/* Job Profit Check — calm neutrals, one bold accent for the main button. */
:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #eceae4;
  --text: #1f2a33;
  --muted: #5d666e;
  --border: #d9d6ce;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --thin: #8a5a00;
  --thin-bg: #fff4d6;
  --loss: #c0262d;
  --loss-bg: #fde8e8;
  --radius: 10px;
  --gap: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191d;
    --surface: #1d2429;
    --surface-2: #262e34;
    --text: #e8eaec;
    --muted: #a3abb2;
    --border: #353e45;
    --accent: #f06a2a;
    --good: #57c27a;
    --good-bg: #173322;
    --thin: #e7b549;
    --thin-bg: #3a2f12;
    --loss: #f2777c;
    --loss-bg: #3d1c1e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: inherit; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 8px 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }

.wrap, .top-inner, .nav { max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* Header */
.top { background: var(--text); color: var(--bg); position: sticky; top: 0; z-index: 5; padding-top: env(safe-area-inset-top); }
@media (prefers-color-scheme: dark) { .top { background: #0d1114; color: var(--text); } }
.top-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand > span { display: flex; flex-direction: column; line-height: 1.1; }
.brand-small { font-size: 0.72rem; opacity: 0.75; letter-spacing: 0.04em; text-transform: uppercase; }
.brand-name { font-weight: 700; font-size: 1.05rem; }
.plan-badge { font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; border: 1px solid currentColor; opacity: 0.9; }
.plan-badge.pro { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.nav { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; white-space: nowrap; font-size: 0.95rem; opacity: 0.85; }
.nav a.active { background: rgba(255, 255, 255, 0.16); opacity: 1; font-weight: 600; }

/* Layout */
.view { padding: 12px 0 32px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.lede { color: var(--muted); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 var(--gap); }
.card.empty, .card.locked { text-align: left; }
.card.locked { border-style: dashed; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.back { display: inline-block; text-decoration: none; color: var(--muted); margin-bottom: 8px; padding: 4px 0; }
.foot { color: var(--muted); font-size: 0.8rem; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-weight: 600; font-size: 0.9rem; }
.field-help { color: var(--muted); font-size: 0.8rem; }
.input-wrap { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow: hidden; }
.input-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.affix { display: flex; align-items: center; padding: 0 10px; background: var(--surface-2); color: var(--muted); font-size: 0.9rem; }
input, select {
  font: inherit; color: inherit; background: var(--surface); min-height: 44px; padding: 8px 10px; width: 100%; min-width: 0;
}
.input-wrap input { border: 0; outline: none; }
select, .field > input, .line input, .line select { border: 1px solid var(--border); border-radius: 8px; }
.line input:focus, .line select:focus, .field > input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--loss); border-color: var(--loss); }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 0.875rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 1rem; cursor: pointer; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.file-btn { position: relative; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 0 0 var(--gap); }
.stat, .price-row > div, .result-grid > div { display: flex; flex-direction: column; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.card .stat-grid { margin-bottom: 12px; }
.card .stat { background: var(--surface-2); border: 0; }
.k { color: var(--muted); font-size: 0.8rem; }
.v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.v.strong { font-size: 1.3rem; }
.price-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 12px; }

/* Result panel */
.result { margin-top: 12px; border-radius: var(--radius); padding: 14px; background: var(--surface-2); border-left: 5px solid var(--border); }
.result.good { background: var(--good-bg); border-left-color: var(--good); }
.result.thin { background: var(--thin-bg); border-left-color: var(--thin); }
.result.loss { background: var(--loss-bg); border-left-color: var(--loss); }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 8px; }
.result-msg { font-weight: 600; margin: 4px 0 0; }
.warn { color: var(--loss); font-weight: 600; margin-top: 8px; }

/* Chips and tags */
.chip { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.thin { background: var(--thin-bg); color: var(--thin); }
.chip.loss { background: var(--loss-bg); color: var(--loss); }
.tag { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }

/* Job list */
.job-list { display: flex; flex-direction: column; gap: 8px; }
.job-row {
  display: flex; justify-content: space-between; gap: 12px; text-decoration: none; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.job-row:hover { border-color: var(--muted); }
.job-main { display: flex; flex-direction: column; min-width: 0; }
.job-name { font-weight: 700; overflow-wrap: anywhere; }
.job-meta { color: var(--muted); font-size: 0.85rem; }
.job-nums { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; flex-shrink: 0; }
.job-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.job-margin { color: var(--muted); font-size: 0.8rem; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { text-decoration: none; padding: 10px 14px; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* Line items */
.lines { display: flex; flex-direction: column; gap: 10px; }
.line {
  display: grid; grid-template-columns: 150px 1fr 100px 120px 110px 44px; gap: 8px; align-items: end;
  padding-bottom: 10px; border-bottom: 1px solid var(--surface-2);
}
.mini { display: flex; flex-direction: column; font-size: 0.75rem; color: var(--muted); gap: 2px; }
.mini input { color: var(--text); }
.line-total { font-weight: 700; text-align: right; padding-bottom: 10px; font-variant-numeric: tabular-nums; }
.add-lines { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

@media (max-width: 720px) {
  .line { grid-template-columns: 1fr 1fr; }
  .line > select { grid-column: 1; }
  .line > input[name="description"] { grid-column: 1 / -1; grid-row: 2; }
  .line > .icon-btn { grid-column: 2; grid-row: 1; justify-self: end; }
  .line-total { grid-column: 1 / -1; text-align: left; padding: 0; }
}

/* Tables */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--surface-2); }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.card { overflow-x: auto; }
.neg { color: var(--loss); }
.pos { color: var(--good); }

/* Bars */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 160px; }
.bar-col { display: flex; flex-direction: column; align-items: center; height: 100%; gap: 4px; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--text); border-radius: 4px 4px 0 0; min-height: 2px; opacity: 0.8; }
.bar.neg { background: var(--loss); }
.bar-label { font-size: 0.7rem; color: var(--muted); }

/* Banners */
#banners { padding-top: 12px; }
#banners:empty { padding-top: 0; }
.banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--thin-bg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; font-size: 0.9rem;
}
.banner.subtle { background: var(--surface-2); }
.banner.danger { background: var(--loss-bg); color: var(--loss); font-weight: 600; }
.banner-actions { display: flex; gap: 8px; }

ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--surface-2); }
ul.checks li::before { content: "✓ "; color: var(--good); font-weight: 700; }

/* Print */
#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  body { background: #fff; color: #000; }
  .print-page { font-size: 12pt; padding: 0; }
  .print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; margin-bottom: 16px; padding-bottom: 8px; }
  .print-meta { text-align: right; }
  .print-total { font-size: 16pt; font-weight: 700; margin-top: 24px; border-top: 1px solid #000; padding-top: 8px; text-align: right; }
  .print-foot { margin-top: 24px; color: #444; font-size: 10pt; }
  .table th, .table td { border-bottom: 1px solid #ccc; }
  .neg { color: #000; font-weight: 700; }
}
