:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --sidebar: #1e293b;
  --sidebar-hover: #334155;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue-soft: #dbeafe;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  color: #fff; font-weight: 700; font-size: 20px; letter-spacing: .3px;
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  display: grid; place-items: center; font-size: 18px;
}
.nav { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: #cbd5e1; text-decoration: none; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a .ico { font-size: 18px; width: 22px; text-align: center; }
.sidebar .foot { margin-top: auto; padding: 16px 20px; font-size: 12px; color: #64748b; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.content { padding: 24px 28px; width: 100%; }

/* ---------- Cards / KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.pos .value { color: var(--green); }
.kpi.neg .value { color: var(--red); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn.export { white-space: nowrap; }
.panel-body { padding: 0; }
.panel-body.pad { padding: 20px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 12px 16px; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: #f8fafc;
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.route { white-space: nowrap; }
.route .arrow { color: var(--muted); margin: 0 6px; }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.planned { background: var(--blue-soft); color: #1d4ed8; }
.badge.in_progress { background: var(--amber-soft); color: #b45309; }
.badge.done { background: var(--green-soft); color: #15803d; }
.badge.cancelled { background: var(--red-soft); color: #b91c1c; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f5f9; }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.icon-btn { border: none; background: transparent; cursor: pointer; font-size: 16px; padding: 5px 7px; border-radius: 7px; color: var(--muted); }
.icon-btn:hover { background: #f1f5f9; color: var(--text); }

/* ---------- Forms ---------- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px;
  box-shadow: 0 20px 50px rgba(15,23,42,.3); animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s ease; }
.toast.error { background: var(--red); }

/* ---------- Mobile ---------- */
.menu-toggle { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
