:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --ink: #121a2b;
  --muted: #6b7385;
  --line: #e3e6ee;
  --accent: #1c69d4;
  --accent-ink: #ffffff;
  --nav: #121a2b;
  --amber: #b7791f; --amber-bg: #fdf3e1;
  --blue: #1c69d4;  --blue-bg: #e7f0fd;
  --green: #1f8a4c; --green-bg: #e4f5eb;
  --grey: #5d6576;  --grey-bg: #eceef2;
  --red: #c53030;   --red-bg: #fde8e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(18,26,43,.06), 0 4px 16px rgba(18,26,43,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.boot { padding: 40px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 0%, #1d2a45 0%, var(--nav) 60%); }
.login-card { width: min(380px, 92vw); background: var(--panel); border-radius: 16px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card .btn { width: 100%; margin-top: 14px; }
.login-err { color: var(--red); font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ---------- Header ---------- */
.top { background: var(--nav); color: #fff; position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1240px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 10px; color: #fff; cursor: pointer; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: #1d2a45; display: grid; place-items: center; color: #5fd3ff; font-weight: 800; }
.brand small { color: #9aa6bf; font-weight: 500; }
.top .spacer { flex: 1; }
.top .btn-ghost { color: #c9d2e3; border-color: #2c3a58; }
.top .btn-ghost:hover { background: #1d2a45; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 80px; }

/* ---------- Buttons & inputs ---------- */
.btn { appearance: none; border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #eef0f5; filter: none; }
.btn-green { background: var(--green); }
.btn-red { background: var(--red); }
.btn-grey { background: var(--grey); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-link { background: none; border: 0; color: var(--muted); padding: 4px 6px; cursor: pointer; font: inherit; font-size: 13px; }
.btn-link:hover { color: var(--red); }

label.f { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }
input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], input[type=search], textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(28,105,212,.15); }
textarea { min-height: 140px; resize: vertical; }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.input-with { display: flex; gap: 6px; }
.input-with .btn { flex: none; }

/* segmented */
.seg { display: inline-flex; flex-wrap: wrap; background: #eef0f5; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; font-weight: 600; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button:disabled { cursor: default; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

/* ---------- Status badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ke_schvaleni { color: var(--amber); background: var(--amber-bg); }
.st-schvaleno { color: var(--blue); background: var(--blue-bg); }
.st-podepsano { color: var(--green); background: var(--green-bg); }
.st-nepodepsano { color: var(--grey); background: var(--grey-bg); }
.st-zamitnuto { color: var(--red); background: var(--red-bg); }
.rating { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-weight: 800; font-size: 13px; }
.rating.A { background: #1f8a4c; color: #fff; }
.rating.B { background: #1c69d4; color: #fff; }
.rating.C { background: #b7791f; color: #fff; }
.rating.none { background: #eef0f5; color: #a0a7b6; }

/* ---------- List ---------- */
.list-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.list-head h1 { margin: 0; font-size: 24px; flex: 1; }
.list-head input[type=search] { width: 260px; }
.tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 16px; }
.tab { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; text-align: left; font: inherit; color: inherit; box-shadow: var(--shadow); transition: transform .1s, border-color .15s; position: relative; overflow: hidden; }
.tab:hover { transform: translateY(-1px); }
.tab .t { font-size: 13px; color: var(--muted); font-weight: 600; }
.tab .n { font-size: 26px; font-weight: 800; margin-top: 2px; }
.tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: transparent; }
.tab.on { border-color: var(--ink); }
.tab.on::after { background: var(--ink); }
.tab.k-ke_schvaleni .n { color: var(--amber); }
.tab.k-schvaleno .n { color: var(--blue); }
.tab.k-podepsano .n { color: var(--green); }
.tab.k-nepodepsano .n { color: var(--grey); }
.tab.k-zamitnuto .n { color: var(--red); }

.summary { display: flex; gap: 22px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; box-shadow: var(--shadow); font-size: 14px; color: var(--muted); }
.summary b { color: var(--ink); }

.table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: grid; grid-template-columns: 2.2fr 1.6fr 50px 1.1fr 1.1fr 130px 90px; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:hover { background: #f8f9fc; }
.row.hd { cursor: default; background: #fafbfd; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.row.hd:hover { background: #fafbfd; }
.row .name { font-weight: 700; }
.row .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }

/* ---------- Detail ---------- */
.d-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.d-head h1 { margin: 0; font-size: 24px; }
.back { color: var(--muted); font-weight: 600; cursor: pointer; background: none; border: 0; font: inherit; padding: 0; }
.back:hover { color: var(--ink); }
.d-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.card h2 .hint { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: auto; }

.calc { margin-top: 6px; border-radius: 10px; background: #f6f8fc; border: 1px solid var(--line); overflow: hidden; }
.calc .ln { display: flex; justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.calc .ln:first-child { border-top: 0; }
.calc .ln span:first-child { color: var(--muted); }
.calc .ln.big { font-size: 16px; font-weight: 800; background: #fff; }
.calc .ln b { font-weight: 700; }
.km-note { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.decision { display: flex; flex-direction: column; gap: 12px; }
.decision .now { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.decision .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.decision .flow { font-size: 12.5px; color: var(--muted); }
.kv { display: flex; gap: 24px; flex-wrap: wrap; }
.kv div { font-size: 13px; color: var(--muted); }
.kv b { display: block; color: var(--ink); font-size: 16px; margin-top: 2px; }

.drop { border: 1.5px dashed #c6ccd9; border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); font-size: 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.drop:hover, .drop.over { background: var(--blue-bg); border-color: var(--accent); color: var(--accent); }
.drop input { display: none; }
.files { list-style: none; padding: 0; margin: 10px 0 0; }
.files li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-top: 1px solid var(--line); font-size: 14px; }
.files li:first-child { border-top: 0; }
.files .ic { width: 30px; height: 30px; border-radius: 7px; background: #eef0f5; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: var(--muted); flex: none; }
.files .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.up-progress { font-size: 13px; color: var(--accent); margin-top: 8px; }
.sub-h { font-size: 13px; font-weight: 700; margin: 14px 0 8px; color: var(--ink); }
.sub-h:first-of-type { margin-top: 0; }

.hist { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.hist li { padding: 7px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.hist li:first-child { border-top: 0; }
.hist .when { color: var(--muted); font-size: 12.5px; min-width: 112px; }
.hist .note { color: var(--muted); width: 100%; padding-left: 122px; }

.savebar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(18,26,43,.96); color: #fff; padding: 12px 20px; display: flex; justify-content: center; gap: 12px; align-items: center; transform: translateY(100%); transition: transform .2s; z-index: 20; }
.savebar.show { transform: none; }
.savebar .btn-ghost { color: #c9d2e3; border-color: #3a4866; }
.savebar .btn-ghost:hover { background: #1d2a45; }
.danger-zone { text-align: right; }

/* ---------- Modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(18,26,43,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 24px; width: min(460px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 6px; font-size: 19px; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.rate-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rate-pick button { border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 6px; cursor: pointer; font: inherit; text-align: center; }
.rate-pick button b { display: block; font-size: 22px; }
.rate-pick button span { font-size: 12.5px; color: var(--muted); }
.rate-pick button.on.A { border-color: #1f8a4c; background: var(--green-bg); }
.rate-pick button.on.B { border-color: #1c69d4; background: var(--blue-bg); }
.rate-pick button.on.C { border-color: #b7791f; background: var(--amber-bg); }
#toast { position: fixed; top: 16px; left: 50%; transform: translate(-50%, -150%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; transition: transform .25s; z-index: 60; }
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .tabs { grid-template-columns: repeat(3, 1fr); }
  .d-grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr auto; }
  .row > :nth-child(2), .row > :nth-child(4), .row > :nth-child(5), .row > :nth-child(7) { display: none; }
  .row > :nth-child(3) { display: none; }
  .row.hd { display: none; }
}
@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
  .list-head input[type=search] { width: 100%; }
  .tab .n { font-size: 20px; }
  main { padding: 16px 12px 90px; }
  .hist .note { padding-left: 0; }
}
@media (max-width: 480px) { .brand small { display: none; } }
