:root {
  --bg-grad-a: #f5faf9;
  --bg-grad-b: #e6f0ee;
  --card: #ffffff;
  --ink: #14302b;
  --muted: #5d7a73;
  --faint: #93aaa3;
  --brand: #0f766e;
  --brand-2: #0d9488;
  --brand-3: #2dd4bf;
  --border: #e3edea;
  --border-strong: #cfe0db;
  --field: #f5faf9;
  --danger: #e23b4e;
  --ok: #18a058;
  --warn: #d97706;
  --shadow-md: 0 8px 24px -10px rgba(15, 60, 53, .18);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 500px at 80% -10%, rgba(45, 212, 191, .15), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(13, 148, 136, .12), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 28px; color: #fff;
  background: linear-gradient(120deg, #0b5b54 0%, #0f766e 45%, #0d9488 100%);
  box-shadow: 0 10px 30px -16px rgba(15, 118, 110, .8);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
  font-weight: 800; font-size: 17px; letter-spacing: .5px;
}
.brand-text h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand-text span { font-size: 12.5px; opacity: .85; }
.tabs { display: flex; gap: 8px; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.22); color: #fff;
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 500; font-family: inherit;
  transition: transform .12s ease, background .15s ease;
}
.tab:hover { background: rgba(255,255,255,.2); transform: translateY(-1px); }
.tab.active { background: #fff; color: var(--brand); font-weight: 700; }
.tab.link { text-decoration: none; }

main { max-width: 1040px; margin: 30px auto 60px; padding: 0 18px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px 28px; margin-bottom: 22px; box-shadow: var(--shadow-md); animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.card-head { margin-bottom: 20px; }
.card-head h2 { margin: 0 0 4px; font-size: 19px; font-weight: 700; }
.card-head p { margin: 0; color: var(--muted); font-size: 13.5px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 7px; }
.lbl { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.lbl em { text-transform: none; font-style: normal; color: var(--faint); font-weight: 500; letter-spacing: 0; }
select, input[type="text"], input[type="date"], input[type="number"] {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: 10px;
  font-size: 14.5px; font-family: inherit; color: var(--ink); background: var(--field);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
select:hover, input:hover { border-color: #aeccc5; }
select:focus, input:focus {
  outline: none; border-color: var(--brand-3); background: #fff; box-shadow: 0 0 0 4px rgba(45, 212, 191, .2);
}
select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235d7a73' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.readout { padding: 11px 13px; border: 1px dashed var(--border-strong); border-radius: 10px; background: #f1f7f5; font-size: 14px; min-height: 44px; color: var(--ink); }
.readout .muted { color: var(--faint); }

.section-label { display: flex; align-items: baseline; gap: 12px; margin: 26px 0 10px; }
.section-label h3 { margin: 0; font-size: 15px; font-weight: 700; }
.hint { font-size: 12.5px; color: var(--faint); }

.table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.lines-table { min-width: 760px; }
.lines-table thead th {
  background: #eef6f4; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.lines-table tbody td { padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lines-table tbody tr:last-child td { border-bottom: none; }
.lines-table tbody tr:hover { background: #fafdfc; }
.lines-table td.item-cell { min-width: 220px; }
.lines-table input[type="number"] { width: 92px; }
.lines-table select.line-unit { width: 110px; }
.variance { font-weight: 700; font-variant-numeric: tabular-nums; }
.variance.pos { color: var(--ok); }
.variance.neg { color: var(--danger); }
.variance.zero { color: var(--faint); }

.icon-btn {
  border: none; background: #fdeef0; color: var(--danger); width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; font-size: 13px; display: grid; place-items: center; transition: background .15s ease, transform .12s ease;
}
.icon-btn:hover { background: #fbdbdf; transform: scale(1.06); }

.btn-primary, .btn-secondary, .btn-ghost {
  border: none; border-radius: 10px; padding: 11px 20px; font-size: 14px; cursor: pointer; font-weight: 600; font-family: inherit;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease, filter .15s ease;
}
.btn-primary { background: linear-gradient(120deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 10px 22px -10px rgba(15, 118, 110, .8); }
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-secondary { background: #e3f1ee; color: var(--brand); margin-top: 12px; border: 1px dashed #aeccc5; }
.btn-secondary:hover { background: #d6ebe6; }
.btn-ghost { background: #eef3f1; color: var(--ink); font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; font-size: 13px; }
.btn-ghost:hover { background: #e1ebe8; }

.actions { display: flex; align-items: center; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.msg { font-size: 13.5px; font-weight: 500; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--danger); }
.hidden { display: none; }

.history-table thead th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); background: #eef6f4; padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.history-table td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.history-table tbody tr:last-child td { border-bottom: none; }
.history-table tbody tr:hover { background: #fafdfc; }
.history-table td:first-child { font-weight: 600; color: var(--brand); }
.history-table .empty { color: var(--faint); text-align: center; padding: 30px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions button, .row-actions a { font-size: 12.5px; padding: 7px 11px; }

/* Document */
.document { color: #14302b; padding: 34px 38px; }
.doc-toolbar { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 16px; margin-bottom: 22px; border-bottom: 3px solid var(--brand); }
.doc-title h2 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: 1px; color: var(--brand); }
.doc-title .sub { font-size: 12px; color: var(--faint); letter-spacing: 2px; text-transform: uppercase; }
.doc-badge { display: inline-block; margin-top: 10px; background: #e7f4f1; color: var(--brand); border: 1px solid #c2e0da; padding: 4px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.doc-meta { font-size: 13px; line-height: 1.9; text-align: right; }
.doc-meta .row { display: flex; gap: 8px; justify-content: flex-end; }
.doc-meta b { color: var(--muted); font-weight: 600; }
.doc-meta .val { font-weight: 600; }
.doc-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.doc-table th, .doc-table td { border: 1px solid #cfe0db; padding: 9px 10px; font-size: 12.5px; }
.doc-table thead th { background: var(--brand); color: #fff; text-align: center; font-weight: 600; }
.doc-table td.l { text-align: left; }
.doc-table td.num, .doc-table th.num { text-align: center; }
.doc-table tbody tr:nth-child(even) { background: #f4faf8; }
.doc-table tfoot td { font-weight: 800; background: #e7f4f1; }
.doc-notes { margin-top: 16px; font-size: 13px; background: #f4faf8; border-left: 3px solid var(--brand-3); padding: 10px 14px; border-radius: 0 8px 8px 0; }
.doc-signoff { display: flex; justify-content: space-between; gap: 24px; margin-top: 56px; }
.doc-signoff .sign { text-align: center; flex: 1; }
.doc-signoff .line { border-top: 1.5px solid #7d9c95; margin-top: 46px; padding-top: 6px; font-size: 12.5px; color: var(--muted); }

@media print {
  @page { margin: 14mm; size: landscape; }
  .no-print, .topbar, .doc-toolbar { display: none !important; }
  body { background: #fff; }
  main { margin: 0; max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; margin: 0; padding: 0; animation: none; }
  .document { padding: 0; }
  .doc-table thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .doc-header { flex-direction: column; }
  .doc-meta, .doc-meta .row { text-align: left; justify-content: flex-start; }
}
