:root {
  --blue: #1e6fb4;
  --red: #e6323c;
  --purple: #c3328c;
  --green: #78b446;
  --yellow: #ffdc14;
  --black: #000;
  --grey: #f2f2f0;
  --grey2: #e4e4e0;
  --text: #111;
  --muted: #767672;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Verdana, Geneva, sans-serif;
  color: var(--text);
  background: #fff;
}

h1, h2, h3 { letter-spacing: -0.02em; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 12px 26px;
  border-bottom: 3px solid var(--black);
  position: sticky; top: 0; background: #fff; z-index: 50;
}
.topbar img { height: 40px; cursor: pointer; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  text-decoration: none; color: var(--text); font-weight: 700;
  padding: 8px 14px; border-radius: 999px; font-size: .95rem;
}
.topbar nav a:hover { background: var(--grey); }
.topbar nav a.active { background: var(--black); color: #fff; }
.savestate { font-size: .8rem; color: var(--muted); min-width: 90px; text-align: right; }
.savestate.saving { color: var(--blue); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 26px; }

/* ---------- buttons ---------- */
button, .btn {
  font-family: inherit; font-size: .9rem; font-weight: 700;
  border: 2px solid var(--black); background: #fff; color: var(--black);
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
}
button:hover, .btn:hover { background: var(--grey); }
button.primary { background: var(--black); color: #fff; }
button.primary:hover { background: var(--red); border-color: var(--red); }
button.danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
button.mini {
  border: none; padding: 3px 7px; font-size: .85rem; border-radius: 6px;
  background: transparent; color: var(--muted); font-weight: 400;
}
button.mini:hover { background: var(--grey2); color: var(--black); }
button.mini.del:hover { background: var(--red); color: #fff; }

/* ---------- inputs ---------- */
input, select, textarea {
  font-family: inherit; font-size: .92rem; color: var(--text);
  border: 1px solid var(--grey2); border-radius: 6px;
  padding: 7px 9px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; }
label { font-size: .75rem; font-weight: 700; color: var(--muted); display: block; margin: 0 0 4px 2px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 30px;
}
.login img { height: 74px; }
.login form { display: flex; flex-direction: column; gap: 12px; width: 300px; }
.login .err { color: var(--red); font-size: .85rem; text-align: center; min-height: 1.2em; }

/* ---------- list ---------- */
.pagehead { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.pagehead h1 { margin: 0; flex: 1; font-size: 1.7rem; }

table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--black);
}
table.list td { padding: 12px 10px; border-bottom: 1px solid var(--grey2); vertical-align: middle; }
table.list tr.row { cursor: pointer; }
table.list tr.row:hover { background: var(--grey); }
table.list .title { font-weight: 700; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.profit-pos { color: var(--green); font-weight: 700; }
.profit-neg { color: var(--red); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 70px 0; }

/* ---------- editor header card ---------- */
.card {
  border: 2px solid var(--black); border-radius: var(--radius);
  padding: 20px; margin-bottom: 24px; background: #fff;
}
.headgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.headgrid .span2 { grid-column: span 2; }
.headgrid .span3 { grid-column: span 3; }
.headgrid .span6 { grid-column: span 6; }
.doclogo { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; gap: 20px; }
.doclogo img { height: 52px; }
.doclogo input.doctitle {
  border: none; font-size: 1.5rem; font-weight: 700; text-align: right; padding: 4px 8px;
  letter-spacing: -0.02em;
}
.doclogo input.doctitle:focus { outline: 2px solid var(--blue); }

/* ---------- sections ---------- */
.section { margin-bottom: 26px; }
.sechead {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0 6px 14px; border-left: 10px solid var(--blue); margin-bottom: 4px;
}
.sechead input.secname {
  border: none; font-weight: 700; font-size: 1.12rem; padding: 4px 6px; background: transparent;
  letter-spacing: -0.02em;
}
.sechead input.secname:focus { outline: 2px solid var(--blue); background: #fff; }
.sechead .secbtns { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.section:hover .sechead .secbtns { opacity: 1; }

table.items { width: 100%; border-collapse: collapse; }
table.items th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  text-align: left; padding: 5px 6px; border-bottom: 2px solid var(--black); white-space: nowrap;
}
table.items th.r, table.items td.r { text-align: right; }
table.items th.c, table.items td.c { text-align: center; }
table.items td { padding: 3px 3px; border-bottom: 1px solid var(--grey2); vertical-align: middle; }
table.items td.comp { font-variant-numeric: tabular-nums; white-space: nowrap; padding-right: 8px; font-size: .92rem; }
table.items input { border-color: transparent; background: transparent; }
table.items input:hover, table.items select:hover { border-color: var(--grey2); background: #fff; }
table.items input:focus, table.items select:focus { background: #fff; }
table.items select { border-color: transparent; background: transparent; width: auto; padding: 6px 4px; }
table.items .rowbtns { display: flex; gap: 0; opacity: 0; }
table.items tr:hover .rowbtns { opacity: 1; }
table.items tfoot td { font-weight: 700; border-bottom: none; padding: 8px 6px; }
.secfoot { display: flex; gap: 10px; margin-top: 6px; align-items: center; }
.addpos { max-width: 260px; }

/* ---------- summary ---------- */
.feenote { font-size: .78rem; color: var(--muted); margin: 4px 2px; }
.summary {
  margin-left: auto; max-width: 430px; border: 2px solid var(--black);
  border-radius: var(--radius); padding: 16px 20px;
}
.summary .row { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.summary .row.total {
  font-weight: 700; font-size: 1.25rem; border-top: 2px solid var(--black);
  margin-top: 8px; padding-top: 12px;
}
.summary .row.total .val { background: var(--yellow); padding: 2px 10px; border-radius: 6px; }

/* ---------- internal ---------- */
.int-item { font-weight: 700; }
.costrow td { background: var(--grey); font-size: .88rem; border-bottom: 1px solid #fff; }
.costrow td:first-child { padding-left: 34px; }
.costrow input { background: transparent; font-size: .88rem; }
.addcost td { background: var(--grey); border-bottom: 1px solid var(--grey2); padding: 4px 6px 10px 34px; }
.warnbadge { display: inline-block; background: var(--yellow); border-radius: 6px; padding: 1px 8px; font-size: .75rem; font-weight: 700; margin-left: 8px; }

/* ---------- settings ---------- */
.setgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.setgrid .full { grid-column: 1 / -1; }
table.positions { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.positions td { padding: 3px; }
table.positions td.price { width: 130px; }
table.positions td.unit { width: 90px; }
table.positions td.x { width: 40px; }

/* ---------- print view ---------- */
.printbar { display: flex; gap: 10px; margin-bottom: 20px; }
.sheet {
  max-width: 900px; margin: 0 auto; background: #fff; font-size: .82rem;
}
.sheet .p-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.sheet .p-head img { height: 46px; }
.sheet .p-head h1 { margin: 0; font-size: 1.35rem; }
.sheet table.meta { width: 100%; border-collapse: collapse; margin-bottom: 26px; }
.sheet table.meta td { border: 1px solid #999; padding: 6px 10px; }
.sheet table.meta td.k { width: 32%; font-weight: 700; background: var(--grey); }
.sheet table.ptab { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.sheet table.ptab th { background: #58585a; color: #fff; font-size: .72rem; padding: 5px 8px; text-align: right; }
.sheet table.ptab th:first-child { text-align: left; }
.sheet table.ptab td { padding: 5px 8px; border-bottom: 1px solid var(--grey2); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet table.ptab td:first-child { text-align: left; white-space: normal; }
.sheet table.ptab tr.secname td { background: #f6d9db; font-weight: 700; text-align: left; }
.sheet table.ptab tr.sectotal td { font-weight: 700; border-bottom: 2px solid var(--black); }
.sheet .feerow { display: flex; justify-content: space-between; background: #f6d9db; font-weight: 700; padding: 7px 10px; margin: 18px 0; }
.sheet .p-summary { margin-left: auto; width: 330px; margin-bottom: 30px; }
.sheet .p-summary .row { display: flex; justify-content: space-between; padding: 3px 0; }
.sheet .p-summary .row.total { font-weight: 700; font-size: 1rem; border-top: 2px solid var(--black); margin-top: 6px; padding-top: 8px; }
.sheet .clause { font-size: .68rem; color: #333; margin: 22px 0 14px; }
.sheet .signs { display: flex; gap: 60px; margin: 34px 0 40px; }
.sheet .signs .s { width: 260px; }
.sheet .signs .line { border-top: 1px dotted #555; margin-top: 44px; padding-top: 5px; font-size: .75rem; }
.sheet .fincond { white-space: pre-wrap; margin: 14px 0; }
.sheet .fincond h3, .sheet .approv h3 { font-size: .9rem; margin: 0 0 6px; }
.sheet .confid { font-size: .62rem; color: #777; border-top: 1px solid var(--grey2); padding-top: 10px; }

@media print {
  body { background: #fff; }
  .topbar, .printbar { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .sheet { font-size: 9.2pt; max-width: none; }
  .sheet table.ptab th { background: #58585a !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet table.ptab tr.secname td, .sheet .feerow { background: #f6d9db !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet table.meta td.k { background: #f2f2f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .section, table.ptab tr { break-inside: avoid; }
}
@page { size: A4; margin: 14mm 12mm; }

@media (max-width: 900px) {
  .headgrid { grid-template-columns: 1fr 1fr; }
  .headgrid .span2, .headgrid .span3, .headgrid .span6 { grid-column: span 2; }
  .setgrid { grid-template-columns: 1fr; }
  .wrap { padding: 14px; }
  table.items { font-size: .85rem; }
}
