:root {
  --bg: #f5f6fa; --panel: #ffffff; --border: #e6e8ee; --text: #14181f; --muted: #6b7280;
  --accent: #4f46e5; --accent-dark: #4338ca; --accent-soft: #eef0ff;
  --ok: #16a34a; --ok-soft: #ecfdf3; --warn: #b45309; --warn-soft: #fef6e7; --danger: #dc2626; --danger-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.04);
  --shadow-md: 0 6px 20px rgba(16,24,40,.07);
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }

/* ---------------- Header / brand / nav ---------------- */
header { background: var(--panel); border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; letter-spacing: .02em; box-shadow: var(--shadow-sm); flex-shrink: 0; }
header h1 { font-size: 16px; margin: 0; }
header .sub { color: var(--muted); font-size: 12px; }
nav { display: flex; gap: 4px; padding: 8px 24px; background: var(--panel); border-bottom: 1px solid var(--border); }
nav button { border: none; background: none; padding: 9px 14px; font-size: 13.5px; cursor: pointer; color: var(--muted); border-radius: 8px; font-weight: 500; transition: background .12s, color .12s; }
nav button:hover { background: var(--bg); color: var(--text); }
nav button.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

main { padding: 24px; max-width: 1140px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 15px; margin: 0 0 14px; }
.breadcrumb { margin-bottom: 12px; font-size: 13px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; user-select: none; }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--text); }
tbody tr:hover { background: #fafbfd; }

.btn { background: var(--accent); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 500; box-shadow: var(--shadow-sm); transition: background .12s, transform .05s; }
.btn:hover { background: var(--accent-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); box-shadow: none; }
.btn.secondary:hover { background: var(--accent-soft); }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); box-shadow: none; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; color: var(--text); transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; margin-top: 10px; font-weight: 500; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; padding-top: 48px; position: relative; box-shadow: var(--shadow-sm); }
.kpi-icon { position: absolute; top: 14px; left: 14px; width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1; }
.kpi .label { color: var(--muted); font-size: 12px; margin-top: 4px; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.active { background: var(--ok-soft); color: var(--ok); }
.pill.paused { background: var(--warn-soft); color: var(--warn); }
.pill.draft { background: #eef0f4; color: var(--muted); }
.pill.finished { background: #eef0f4; color: var(--muted); }

.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.row-form > div { flex: 1; min-width: 140px; }

.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: radial-gradient(circle at top, #eef0ff, var(--bg) 60%); }
.login-box { background: var(--panel); padding: 36px 32px; border-radius: 16px; border: 1px solid var(--border); width: 320px; box-shadow: var(--shadow-md); text-align: center; }
.login-box .logo { margin: 0 auto 14px; }
.login-box h2 { margin: 0 0 18px; font-size: 17px; text-align: left; }
.login-box label { text-align: left; }
.msg { font-size: 13px; margin-top: 8px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }
.thumb { height: 34px; border-radius: 4px; border: 1px solid var(--border); }
.muted { color: var(--muted); }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
[hidden] { display: none !important; }

/* ---------------- Toasts & modal ---------------- */
#toast-wrap { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #14181f; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow-md); max-width: 320px; animation: toast-in .15s ease-out; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.4); display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 20px; width: 340px; box-shadow: var(--shadow-md); }
.modal h3 { margin: 0 0 8px; font-size: 15px; }
.modal p { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; }

.table-wrap { overflow-x: auto; }
.badge-warn { display: inline-block; background: var(--warn-soft); color: var(--warn); font-size: 11px; padding: 2px 7px; border-radius: 999px; margin-left: 6px; }
.search-input { max-width: 280px; margin-bottom: 12px; }

/* ---------------- Empty states ---------------- */
.empty-state { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty-icon { font-size: 26px; margin-bottom: 8px; opacity: .55; }

/* ---------------- Loading skeleton ---------------- */
.skeleton { background: linear-gradient(90deg, #eef0f4 25%, #f7f8fb 37%, #eef0f4 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: 8px; }
.skeleton-row { height: 14px; margin: 12px 0; }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------------- Trend chart ---------------- */
.trend-chart { width: 100%; height: 160px; display: block; }
.trend-chart .bar-imp { fill: var(--accent); opacity: .9; }
.trend-chart .bar-clk { fill: var(--ok); }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* ---------------- Drag & drop upload ---------------- */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; background: var(--bg); }
.dropzone.dz-over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 26px; margin-bottom: 6px; }
.dz-link { color: var(--accent); text-decoration: underline; }
.dz-thumb { max-height: 90px; border-radius: 8px; border: 1px solid var(--border); display: block; margin: 0 auto 8px; }
.dz-info { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.dz-match { color: var(--ok); font-weight: 600; }
.dz-mismatch { color: var(--warn); font-weight: 600; }

@media (max-width: 720px) {
  main { padding: 14px; }
  .row-form { flex-direction: column; align-items: stretch; }
  .row-form > div { min-width: 0; }
  header { flex-direction: column; align-items: flex-start; gap: 8px; }
}
