/* CMFA — čisté, ploché UI s jemným soft-touch. Tlačítka jednoznačně vystouplá,
   stavy barevně tónované, aktivní prvky plněné (žádné matoucí inset stíny). */
:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --border: #dde3ec;
  --text: #2c3752;
  --text-soft: #7c87a1;
  --primary: #4a6cf7;
  --primary-soft: #edf1fe;
  --green: #219a63;
  --green-soft: #e6f6ee;
  --red: #d8434f;
  --red-soft: #fdecee;
  --orange: #d97f1d;
  --orange-soft: #fdf3e4;
  --violet: #7a55c9;
  --violet-soft: #f1ecfb;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 2px rgba(44,55,82,.06), 0 6px 20px rgba(44,55,82,.07);
  --shadow-btn: 0 1px 2px rgba(44,55,82,.10);
  --shadow-pop: 0 6px 30px rgba(44,55,82,.18);
  font-size: 15px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.loading-screen { display:flex; align-items:center; justify-content:center; height:100vh; color:var(--text-soft); font-size:1.2rem; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; }
.sidebar .version { margin-top: auto; padding: 12px 12px 0; font-size: .68rem;
  color: var(--text-soft); text-decoration: none; white-space: nowrap; }
.sidebar .version:hover { color: var(--primary); text-decoration: underline; }
.logo { font-size: 1.3rem; font-weight: 800; letter-spacing: 1px; padding: 4px 12px 18px; color: var(--primary); }
.logo span { color: var(--text); }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-soft); margin: 16px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text); margin-bottom: 2px; font-weight: 500; border: none;
  background: transparent; width: 100%; text-align: left; font-size: .92rem; box-shadow: none; }
.nav-item:hover { background: var(--bg); box-shadow: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; box-shadow: none; }
.nav-item .badge { margin-left: auto; }
.nav-item .badge:empty { display: none; }  /* nulový/nenačtený počet = žádná prázdná šedá pilulka */
.nav-item .dot { margin-left: auto; width: 9px; height: 9px; border-radius: 50%; background: var(--red); flex: none; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.topbar h1 { font-size: 1.3rem; font-weight: 750; flex: 1; }
.searchbox { position: relative; }
.searchbox input { width: 260px; }
.search-results { position: absolute; top: 46px; right: 0; width: 380px; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); padding: 8px; z-index: 60; }
.search-results .sr-item { padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.search-results .sr-item:hover { background: var(--primary-soft); }
.userchip { display:flex; align-items:center; gap:10px; padding: 7px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: .88rem; }
.userchip small { color: var(--text-soft); font-weight: 400; }

/* ---------- komponenty ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-card); padding: 20px; }
.card + .card { margin-top: 18px; }
.card h2 { font-size: 1.02rem; margin-bottom: 14px; }
.card h3 { font-size: .95rem; margin: 14px 0 8px; }
.grid { display: grid; gap: 16px; }
.grid > .card + .card { margin-top: 0; } /* rozestupy v gridu řeší gap - zděděný margin by kartu v buňce posunul a zmenšil */
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr); } .grid.cols-3 { grid-template-columns: 1fr 1fr; } }

button, .btn { font-family: inherit; font-size: .9rem; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 16px; cursor: pointer; box-shadow: var(--shadow-btn);
  transition: background .1s, transform .05s, box-shadow .1s; }
button:hover, .btn:hover { background: #f5f7fb; }
button:active, .btn:active { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #3d5ce0; }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-green:hover { background: #1c8656; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-red:hover { background: #c33641; }
.btn-orange { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-orange:hover { background: #c37016; }
.btn-sm { padding: 5px 11px; font-size: .82rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea { font-family: inherit; font-size: .92rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; outline: none; width: 100%; box-shadow: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,108,247,.15); }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: .76rem; font-weight: 600; color: var(--text-soft);
  margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .73rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); padding: 8px 10px; border-bottom: 2px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid #eceff5; font-size: .9rem; vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--primary-soft); }
.table-wrap { overflow-x: auto; }

/* pulzující řádky: červeně po splatnosti, oranžově dlouho nevyřízené */
@keyframes pulse-row-red {
  0%, 100% { background-color: rgba(216, 67, 79, .16); }
  50%      { background-color: rgba(216, 67, 79, .04); }
}
@keyframes pulse-row-orange {
  0%, 100% { background-color: rgba(217, 127, 29, .15); }
  50%      { background-color: rgba(217, 127, 29, .03); }
}
tr.row-overdue td { animation: pulse-row-red 1.8s ease-in-out infinite; }
tr.row-overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }
tr.row-stale td { animation: pulse-row-orange 2.4s ease-in-out infinite; }
tr.row-stale td:first-child { box-shadow: inset 3px 0 0 var(--orange); }
tr.row-overdue:hover td, tr.row-stale:hover td { animation-play-state: paused; background: var(--primary-soft); }
@media (prefers-reduced-motion: reduce) {
  tr.row-overdue td, tr.row-stale td { animation: none; }
  tr.row-overdue td { background: rgba(216, 67, 79, .12); }
  tr.row-stale td { background: rgba(217, 127, 29, .12); }
}

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .73rem;
  font-weight: 700; background: var(--bg); color: var(--text-soft); border: none; white-space: nowrap; }
.badge.st-RECEIVED, .badge.st-PROCESSING { background: var(--bg); color: var(--text-soft); }
.badge.st-REVIEW_REQUIRED { background: var(--orange-soft); color: var(--orange); }
.badge.st-WAITING_APPROVAL { background: var(--primary-soft); color: var(--primary); }
.badge.st-APPROVED, .badge.st-ACCOUNTED, .badge.st-COMPLETED { background: var(--green-soft); color: var(--green); }
.badge.st-WAITING_ACCOUNTING { background: var(--violet-soft); color: var(--violet); }
.badge.st-REJECTED { background: var(--red-soft); color: var(--red); }
.badge.st-ARCHIVED { background: var(--bg); color: var(--text-soft); }
.badge.due-warning { background: var(--orange-soft); color: var(--orange); }
.badge.due-critical, .badge.due-overdue { background: var(--red-soft); color: var(--red); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }

.stat-tile { text-align: center; padding: 18px 10px; cursor: pointer; transition: transform .1s, box-shadow .1s;
  min-height: 96px; display: flex; flex-direction: column; justify-content: center; }
.stat-tile:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(44,55,82,.12); }
.stat-tile .num { font-size: 1.9rem; font-weight: 800; line-height: 1.15; }
.stat-tile .num-money { font-size: 1.35rem; white-space: nowrap; }
.stat-tile .lbl { font-size: .8rem; color: var(--text-soft); margin-top: 2px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 7px 15px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .85rem;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); box-shadow: none; }
.tab:hover { background: #f5f7fb; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.empty { text-align: center; color: var(--text-soft); padding: 36px 10px; }

/* ---------- detail faktury ---------- */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr); gap: 18px; align-items: start; }
@media (max-width: 1150px) { .invoice-layout { grid-template-columns: 1fr; } }
.pdf-frame { width: 100%; height: calc(100vh - 130px); min-height: 500px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-card); }
.doc-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--text-soft); font-size: .82rem; padding-top: 2px; }
.kv dd { font-weight: 600; }
.amount-big { font-size: 1.5rem; font-weight: 800; }
.wf-step { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.wf-icon { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 800; flex-shrink: 0; background: var(--bg); color: var(--text-soft); }
.wf-icon.done { background: var(--green); color: #fff; }
.wf-icon.active { background: var(--primary); color: #fff; animation: pulse 1.6s infinite; }
.wf-icon.rejected, .wf-icon.returned { background: var(--red); color: #fff; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.wf-line { font-size: .88rem; }
.wf-line small { color: var(--text-soft); display: block; }
.banner { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 12px; font-weight: 600;
  font-size: .9rem; background: var(--bg); border: 1px solid var(--border); }
.banner.warn { background: var(--orange-soft); border-color: #f3ddba; color: var(--orange); }
.banner.danger { background: var(--red-soft); border-color: #f4c7cb; color: var(--red); }
.comment { padding: 10px 0; border-bottom: 1px solid #eceff5; font-size: .9rem; }
.comment .meta { font-size: .78rem; color: var(--text-soft); }
.history-item { font-size: .84rem; padding: 6px 0; border-bottom: 1px dashed #eceff5; }
.history-item .meta { color: var(--text-soft); font-size: .76rem; }

/* ---------- login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 400px; padding: 34px; }
.login-card .logo { text-align: center; font-size: 1.8rem; padding-bottom: 8px; }
.login-sub { text-align: center; color: var(--text-soft); font-size: .86rem; margin-bottom: 18px; }
.dev-users { margin-top: 18px; font-size: .82rem; }
.dev-users button { display: block; width: 100%; text-align: left; margin-top: 6px; padding: 7px 12px; font-weight: 500; }

/* ---------- modal + toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(44,55,82,.4); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  padding: 26px; width: 560px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-bottom: 14px; }
.modal .btn-row { margin-top: 18px; justify-content: flex-end; }
#toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--text); color: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow-pop);
  padding: 12px 20px; font-weight: 600; font-size: .9rem; animation: slideIn .18s ease-out; max-width: 420px; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- notifikace ---------- */
.bell { position: relative; }
.bell .dot { position: absolute; top: 4px; right: 6px; width: 9px; height: 9px; background: var(--red);
  border-radius: 50%; border: 2px solid var(--bg); }
.notif-panel { position: absolute; right: 0; top: 48px; width: 380px; max-height: 62vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); z-index: 60; padding: 12px; }
.notif-item { padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 4px; }
.notif-item:hover { background: var(--primary-soft); }
.notif-item.unread { font-weight: 700; background: var(--bg); }
.notif-item .meta { font-size: .76rem; color: var(--text-soft); font-weight: 400; }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 30px;
  text-align: center; color: var(--text-soft); cursor: pointer; background: var(--bg); }
.dropzone.drag, .dropzone:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: .78rem; background: var(--bg); border: 1px solid var(--border); }
.chip .x { cursor: pointer; margin-left: 5px; color: var(--red); font-weight: 800; }
.muted { color: var(--text-soft); font-size: .84rem; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.right { text-align: right; } .center { text-align: center; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }

/* ------------------------------------------------------------ kanban pohled */
.kanban { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 6px; }
.kb-col { min-width: 235px; flex: 1 0 235px; background: var(--bg); border-radius: 12px; padding: 10px; }
.kb-head { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.kb-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.kb-card:hover { box-shadow: var(--shadow-out-sm); }
.kb-card.overdue { border-left: 3px solid var(--red); animation: pulse-row-red 1.6s ease-in-out infinite; }
.kb-card.stale { border-left: 3px solid var(--orange); }

/* ------------------------------------------------------- mobil (telefony) */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center;
    gap: 2px; overflow-x: auto; overflow-y: hidden; padding: 8px 10px; z-index: 60;
    border-right: 0; border-bottom: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
  .sidebar .logo { padding: 2px 8px 2px 2px; font-size: 1.05rem; }
  .sidebar .nav-section { display: none; }
  .sidebar .nav-item { white-space: nowrap; padding: 6px 10px; flex: 0 0 auto; }
  .sidebar .version { display: none; }
  .main { padding: 12px 10px 40px; }
  .topbar { flex-wrap: wrap; }
  .topbar h1 { font-size: 1.1rem; flex-basis: 100%; }
  .searchbox input { width: 150px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .modal { width: 94vw; max-width: 94vw; max-height: 88vh; overflow-y: auto; }
  .btn-row { flex-wrap: wrap; }
  .card { padding: 14px 12px; }
  .kb-col { min-width: 82vw; flex-basis: 82vw; }
}
