:root {
  --bg: #eaeef5;
  --bg-grad-a: #f6f8fc;
  --bg-grad-b: #e7ecf5;
  --card: #ffffff;
  --ink: #18233b;
  --muted: #67748e;
  --faint: #97a2b8;
  --brand: #1f4e79;
  --brand-2: #2f6db0;
  --brand-3: #4f8fd6;
  --accent: #0ea5a3;
  --border: #e6eaf1;
  --border-strong: #d6dde9;
  --field: #f7f9fc;
  --danger: #e23b4e;
  --ok: #18a058;
  --shadow-sm: 0 1px 2px rgba(24, 35, 59, .06);
  --shadow-md: 0 8px 24px -10px rgba(24, 35, 59, .18);
  --shadow-lg: 0 22px 50px -22px rgba(24, 35, 59, .35);
  --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(79, 143, 214, .16), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(14, 165, 163, .12), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 28px;
  background: linear-gradient(120deg, #173f63 0%, #1f4e79 45%, #2f6db0 100%);
  color: #fff;
  box-shadow: 0 10px 30px -16px rgba(31, 78, 121, .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;
  backdrop-filter: blur(4px);
}
.brand-text h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.brand-text span { font-size: 12.5px; opacity: .8; }

.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, box-shadow .15s ease;
}
.tab:hover { background: rgba(255, 255, 255, .2); transform: translateY(-1px); }
.tab.active {
  background: #fff; color: var(--brand);
  font-weight: 700;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .4);
}
.tab-ico { font-size: 13px; }

/* ---------------- Layout ---------------- */
main { max-width: 940px; 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 ---------------- */
.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: #c2ccdc; }
select:focus, input:focus {
  outline: none;
  border-color: var(--brand-3);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(79, 143, 214, .18);
}
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='%2367748e' 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;
}

.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); }

/* ---------------- Item lines table ---------------- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
.lines-table { min-width: 480px; }
.lines-table thead th {
  background: #f3f6fb;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted);
  padding: 11px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.lines-table tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lines-table tbody tr:last-child td { border-bottom: none; }
.lines-table tbody tr { transition: background .12s ease; }
.lines-table tbody tr:hover { background: #fafbfe; }
.lines-table td select, .lines-table td input { background: #fff; }
.line-unit { color: var(--muted); font-size: 13.5px; font-weight: 500; }

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

/* ---------------- Buttons ---------------- */
.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(31, 78, 121, .8);
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: #eaf1fa; color: var(--brand); margin-top: 12px;
  border: 1px dashed #b9cce5;
}
.btn-secondary:hover { background: #dfeafa; border-color: var(--brand-3); }

.btn-ghost {
  background: #eef2f8; 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: #e2e8f2; }

.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 ---------------- */
.history-table thead th {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); background: #f3f6fb;
  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: #fafbfe; }
.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; }

/* ---------------- Printable document ---------------- */
.document { color: #15233b; 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: #eef4fb; color: var(--brand); border: 1px solid #cfe0f3;
  padding: 4px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; letter-spacing: .5px;
}
.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 #d4ddea; padding: 10px 12px; font-size: 13px; }
.doc-table thead th { background: var(--brand); color: #fff; text-align: left; font-weight: 600; letter-spacing: .3px; }
.doc-table tbody tr:nth-child(even) { background: #f6f9fd; }
.doc-table td.num, .doc-table th.num { text-align: center; }
.doc-table tfoot td { font-weight: 800; background: #eef4fb; font-size: 13.5px; }

.doc-notes {
  margin-top: 16px; font-size: 13px; background: #f7f9fc;
  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 #8895a8; margin-top: 46px; padding-top: 6px; font-size: 12.5px; color: var(--muted); }

@media print {
  @page { margin: 16mm; }
  .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: 680px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { padding: 14px 18px; }
  .doc-header { flex-direction: column; }
  .doc-meta, .doc-meta .row { text-align: left; justify-content: flex-start; }
  .document { padding: 22px; }
}
