:root {
  --bg: #171A15;
  --surface: #20241C;
  --surface-alt: #262B21;
  --border: #3A4235;
  --text: #ECE8DD;
  --text-muted: #93A085;
  --muted-accent: #7C8570;
  --gold: #C9A227;
  --rust: #B5502E;
  --good: #6E9B4A;
  --bad: #B5502E;

  --cat-obedience: #5B8FB0;
  --cat-detection: #C9A227;
  --cat-tracking: #6E9B4A;
  --cat-protection: #B5502E;
  --cat-socialization: #9575B5;

  --font-display: "Oswald", sans-serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    linear-gradient(180deg, rgba(255,255,255,0.02), transparent 200px);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: 0.02em; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 6px 22px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }

.brand-tag {
  position: relative;
  width: 44px; height: 44px;
  background: linear-gradient(155deg, var(--gold), #8f7317);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 rgba(0,0,0,0.35);
  flex-shrink: 0;
}
.brand-hole { position: absolute; top: 5px; left: 5px; width: 7px; height: 7px; background: var(--surface); border-radius: 50%; box-shadow: inset 0 1px 2px rgba(0,0,0,0.5); }
.brand-mark { font-family: var(--font-display); font-weight: 700; font-size: 15px; color: #1A1D19; letter-spacing: 0.03em; }
.brand-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.brand-sub { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); letter-spacing: 0.03em; margin-top: 2px; }

#nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  font-family: var(--font-body); font-size: 13.5px; font-weight: 500;
  padding: 10px 12px; border-radius: var(--radius); cursor: pointer; text-align: left;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active { background: var(--surface-alt); color: var(--gold); border-color: var(--border); }
.nav-icon { width: 16px; text-align: center; opacity: 0.8; }

.sidebar-footer { padding-top: 14px; border-top: 1px solid var(--border); }
.status-dot { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.status-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted-accent); }
.status-dot.ok::before { background: var(--good); }
.status-dot.err::before { background: var(--bad); }

/* ---------- Main ---------- */
.main { padding: 28px 36px 60px; max-width: 1180px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 24px; }
.page-date { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* ---------- Dashboard tiles ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.tile {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px 14px; overflow: hidden;
}
.tile-tag { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--gold); }
.tile-value { font-family: var(--font-display); font-size: 30px; font-weight: 600; line-height: 1; }
.tile-label { margin-top: 6px; font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dash-card-wide { grid-column: 1 / -1; }
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.dash-card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 10px; }
.dash-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dash-list li { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.dash-list li:last-child { border-bottom: none; }
.dash-list-training li { justify-content: flex-start; }
.dash-list-training li > span:nth-child(2) { flex: 1; }

/* ---------- Panels / forms / tables ---------- */
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.pill {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  font-size: 12.5px; font-family: var(--font-body); font-weight: 500;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.pill.active { background: var(--gold); color: #1A1D19; border-color: var(--gold); font-weight: 600; }

.entity-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; }
.history-panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { font-size: 16px; }

.btn { font-family: var(--font-body); font-size: 13px; font-weight: 600; border-radius: 6px; padding: 8px 14px; border: 1px solid var(--border); cursor: pointer; background: var(--surface-alt); color: var(--text); }
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--gold); color: #1A1D19; border-color: var(--gold); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); margin-left: auto; }
.btn-add { font-size: 12.5px; }

.entity-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 14px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.entity-form.hidden { display: none; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); }
.field-inline { max-width: 280px; margin-bottom: 16px; }
.field span { font-weight: 500; }
.field input, .field select, .field textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 5px; padding: 8px 10px; font-family: var(--font-body); font-size: 13px;
}
.field textarea { resize: vertical; min-height: 40px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.field-wide { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; margin-top: 4px; }

.date-input-wrap { display: flex; gap: 6px; }
.date-input-wrap input { flex: 1; min-width: 0; }
.today-btn {
  padding: 8px 12px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: var(--gold); color: #1A1D19; border: 1px solid var(--gold);
}
.today-btn:hover { filter: brightness(1.08); }

.search-row { margin-bottom: 14px; }
.search-input {
  width: 100%; max-width: 340px; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 9px 12px; font-family: var(--font-body); font-size: 13px;
}
.search-input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.search-input::placeholder { color: var(--text-muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: var(--surface-alt); }
.row-actions { text-align: right; }
.link { background: none; border: none; color: var(--gold); font-size: 12px; cursor: pointer; font-weight: 600; }

.badge {
  --badge-color: var(--muted-accent);
  display: inline-block; font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  padding: 3px 8px; border-radius: 4px; color: var(--badge-color);
  background: color-mix(in srgb, var(--badge-color) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--badge-color) 45%, transparent);
}

.loading, .empty { color: var(--text-muted); font-size: 13px; padding: 14px 2px; }
.muted { color: var(--text-muted); }
.subhead { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 18px 0 8px; }

/* ---------- Performance history bars ---------- */
.hist-summary { display: flex; flex-direction: column; gap: 10px; }
.hist-row { display: grid; grid-template-columns: 130px 1fr 70px 90px; align-items: center; gap: 10px; }
.hist-cat { font-size: 12.5px; font-weight: 600; }
.hist-bar-track { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 4px; height: 10px; overflow: hidden; }
.hist-bar-fill { height: 100%; border-radius: 4px 0 0 4px; }
.hist-avg { font-family: var(--font-mono); font-size: 12px; }
.hist-count { font-size: 11px; text-align: right; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--bad); color: #F0B8A8; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { border-bottom: none; margin-bottom: 0; padding-bottom: 6px; }
  #nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main { padding: 20px; }
  .dash-grid { grid-template-columns: 1fr; }
  .hist-row { grid-template-columns: 100px 1fr 60px; }
  .hist-count { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
