:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --brand: #0f172a;
  --accent: #1d4ed8;
  --danger: #b91c1c;
  --success: #15803d;
  --warning: #b45309;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--brand); color: #e5e7eb; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { padding: 18px 18px 12px; font-weight: 700; font-size: 15px; letter-spacing: .5px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .logo small { display: block; font-weight: 400; font-size: 11px; color: #9ca3af; }
.sidebar nav { padding: 10px 0; flex: 1; }
.sidebar nav a {
  display: block; padding: 9px 18px; color: #cbd5e1; font-size: 13.5px; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: #3b82f6; }
.sidebar .foot { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12px; color: #9ca3af; }
.sidebar .foot form button { background: none; border: none; color: #cbd5e1; cursor: pointer; padding: 0; font-size: 12px; }
.sidebar .foot form button:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 0 24px 48px; }
.topbar { padding: 18px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 20px; display: flex; align-items: center; gap: 16px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards & panels */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 12px; }
.stat-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font-size: 13px; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: #cbd5e1; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { opacity: .9; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }

/* Forms */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 3px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: #fff; color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 160px; }
.inline { display: flex; align-items: center; gap: 8px; }
.inline label { margin: 0; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); }
.table-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: auto; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
th { background: #f8fafc; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.st-NEW { background: #dbeafe; color: #1e40af; }
.st-REVIEW { background: #fef3c7; color: #92400e; }
.st-SKIP { background: #e5e7eb; color: #374151; }
.st-TO_SEND { background: #c7d2fe; color: #3730a3; }
.st-GENERATED { background: #ede9fe; color: #5b21b6; }
.st-SENT { background: #bae6fd; color: #075985; }
.st-QR_OPENED { background: #fde68a; color: #92400e; }
.st-DEMO_REQUESTED { background: #fbcfe8; color: #9d174d; }
.st-CLIENT { background: #bbf7d0; color: #14532d; }
.badge.dnc { background: #fecaca; color: #991b1b; }
.badge.test { background: #fef08a; color: #713f12; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13.5px; }
.flash.success { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.flash.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash.warning { background: #fef9c3; color: #713f12; border: 1px solid #fde047; }

/* Utilities */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex.wrap { flex-wrap: wrap; }
.space-between { justify-content: space-between; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.actions-cell { white-space: nowrap; }

/* Filters bar */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filters > div { min-width: 140px; }
.filters label { margin: 0 0 2px; }

/* Pagination */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.pagination a, .pagination span { padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* Review */
.review-card { max-width: 860px; }
.review-field { margin-bottom: 10px; }
.review-field .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.review-field .val { font-size: 15px; }
.kbd { display: inline-block; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; font-size: 11px; background: #f8fafc; }

/* Letter preview iframe */
.letter-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 8px; background: #e8e8e8; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.timeline .when { color: var(--muted); font-size: 12px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .sidebar nav a { border-left: none; }
  .main { padding: 0 12px 32px; }
}

/* Pretraga leadova */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.preset { position: relative; }
.preset input { position: absolute; opacity: 0; pointer-events: none; }
.preset span {
  display: block; text-align: center; padding: 12px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: border-color .1s, background .1s;
}
.preset:hover span { border-color: #cbd5e1; }
.preset.active span { background: var(--brand); color: #fff; border-color: var(--brand); }

.b-new { background: #dbeafe; color: #1e40af; }
.b-existing { background: #e5e7eb; color: #374151; }
.b-dnc { background: #fecaca; color: #991b1b; }
.b-incomplete { background: #fef3c7; color: #92400e; }

.sticky-actions {
  position: sticky; bottom: 0; margin: 12px 0; padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 -4px 16px rgba(15,23,42,.08);
}
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 20px 22px; max-width: 420px; width: 92vw; }
dialog::backdrop { background: rgba(15,23,42,.4); }
dialog h3 { margin-top: 0; }
