:root {
  --primary: #378ADD;
  --success: #1D9E75;
  --danger: #E24B4A;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6c757d;
  --border: #e3e6ee;
  --sidebar: #1a1a2e;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: #378ADD;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

body { display: flex; }

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  padding: 0 0.75rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 1rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.nav-link {
  display: block;
  padding: 0.55rem 0.85rem;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.92rem;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }

.logout-form { padding: 0 0.5rem; }
.logout-form button {
  width: 100%;
  background: transparent;
  color: #94a3b8;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.45rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.logout-form button:hover { background: rgba(255,255,255,0.05); color: #fff; }

/* ── Content area ─────────────────────────────────── */
.content {
  flex: 1;
  padding: 1.5rem 2rem;
  min-width: 0;
  max-width: 1300px;
}

h1 { font-size: 1.6rem; margin-bottom: 1.25rem; color: var(--text); }
h2 { font-size: 1.1rem; margin-bottom: 0.9rem; }

.card {
  background: var(--card);
  border-radius: 10px;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.muted { color: var(--muted); }
.meta { color: var(--muted); font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 0.75rem; }
.hidden { display: none; }

/* ── Stats ────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--card);
  border-radius: 10px;
  padding: 1.2rem;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--primary); }
.stat-value.small { font-size: 1rem; font-weight: 600; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

/* ── Tables ───────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; color: #475569; font-size: 0.85rem; }
tbody tr:hover { background: #f8fafc; }
.row-total { font-weight: 700; background: #f1f5f9; }
.row-total td { border-top: 2px solid var(--border); }

code { background: #f1f5f9; padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.85rem; }

/* ── Badges ───────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-skupina { background: #dbeafe; color: #1e40af; }
.badge-krop { background: #fce7f3; color: #9d174d; }

/* ── Forms ────────────────────────────────────────── */
.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  align-items: end;
}
.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
}
.grid-form input[type=text],
.grid-form input[type=number],
.grid-form input[type=password],
.grid-form input[type=file],
.grid-form select,
.grid-form textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
}
.grid-form input:focus, .grid-form select:focus, .grid-form textarea:focus {
  outline: 2px solid rgba(55, 138, 221, 0.4);
  outline-offset: 1px;
}
.grid-form label.check, .grid-form label.file {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}
.grid-form label.file { flex-direction: column; align-items: flex-start; }

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
}
fieldset legend {
  font-size: 0.82rem;
  font-weight: 600;
  color: #475569;
  padding: 0 0.3rem;
}
label.inline { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 0.85rem; font-weight: 500; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: #2872c3; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #178661; }
.btn-secondary { background: #64748b; }
.btn-secondary:hover { background: #475569; }
.btn-secondary-sm {
  background: #e2e8f0;
  color: #334155;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 5px;
  cursor: pointer;
  border: none;
  font-weight: 600;
}
.btn-secondary-sm:hover { background: #cbd5e1; }
.btn-danger-sm {
  background: var(--danger);
  color: #fff;
  padding: 0.3rem 0.7rem;
  border-radius: 5px;
  font-size: 0.8rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.btn-danger-sm:hover { background: #b32f2f; }
.btn-link { color: var(--primary); text-decoration: none; font-size: 0.85rem; }
.btn-link:hover { text-decoration: underline; }

/* ── Flash ────────────────────────────────────────── */
.flash {
  padding: 0.7rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  border-left: 4px solid;
}
.flash-ok { background: #ecfdf5; border-color: var(--success); color: #065f46; }
.flash-err { background: #fef2f2; border-color: var(--danger); color: #7f1d1d; white-space: pre-wrap; }

/* ── Sestava-specific ─────────────────────────────── */
.quick-select {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.85rem;
}
.firma-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.4rem 0.9rem;
  margin-bottom: 1rem;
  padding: 0.7rem 0.9rem;
  background: #f8fafc;
  border-radius: 8px;
}
.firma-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}
.firma-check input { margin: 0; }

.result-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 1000px) {
  .result-grid { grid-template-columns: 1fr; }
}
.result-chart { display: flex; justify-content: center; }
.result-chart canvas { max-width: 100%; height: auto !important; }

/* ── Login ────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--sidebar);
}
.login-box {
  background: #fff;
  padding: 2.5rem 2rem;
  border-radius: 12px;
  width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-box h1 { text-align: center; font-size: 1.3rem; margin-bottom: 0.5rem; }
.login-box input {
  padding: 0.7rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
}
.login-box button {
  padding: 0.7rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.login-box button:hover { background: #2872c3; }
.login-error { color: var(--danger); text-align: center; font-size: 0.9rem; }

/* ── Mobile ───────────────────────────────────────── */
@media (max-width: 760px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; min-height: 0; position: relative; flex-direction: row; align-items: center; padding: 0.75rem 1rem; }
  .sidebar .brand { padding: 0; border: none; margin: 0 1rem 0 0; }
  .nav { flex-direction: row; flex: 1; flex-wrap: wrap; gap: 0; }
  .nav-link { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
  .logout-form { padding: 0; }
  .content { padding: 1rem; }
}
