:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface-alt: #1a2236;
  --accent: #c9a84c;
  --accent-light: #e8c97a;
  --text: #f0ede6;
  --muted: #8a9bb0;
  --border: #1e2d45;
  --success: #4caf82;
  --error: #e05c5c;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; max-width: 100%; position: relative; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; cursor: pointer; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px 28px; display: flex; flex-direction: column; gap: 14px;
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; }
.login-sub { color: var(--muted); font-size: 14px; margin-top: -8px; margin-bottom: 6px; }
.login-card input, .login-card button {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: 15px;
}
.login-card button { background: var(--accent); color: #1a1300; font-weight: 600; border: none; }
.login-error { color: var(--error); font-size: 13px; text-align: center; }

/* ── App shell ─────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.sidebar {
  grid-row: 1 / 3; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 6px;
}
.sidebar .brand { padding: 4px 10px 16px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  padding: 10px 12px; border-radius: 10px; color: var(--muted); font-size: 14.5px; font-weight: 500;
  display: flex; align-items: center; gap: 11px;
}
.sidebar nav a .ico { font-size: 15px; width: 18px; text-align: center; }
.sidebar nav a:hover { background: var(--surface-alt); color: var(--text); }
.sidebar nav a.active { background: var(--surface-alt); color: var(--accent); }
.logout { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 9px; border-radius: 10px; font-size: 13px; }
.logout:hover { color: var(--error); border-color: var(--error); }

.topbar {
  grid-column: 2; display: flex; align-items: center; gap: 12px; padding: 0 24px;
  border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.topbar #view-title { font-weight: 600; font-size: 16px; flex: 1; }
.menu-btn { display: none; background: transparent; border: none; color: var(--text); font-size: 20px; }
.refresh { background: transparent; border: 1px solid var(--border); color: var(--muted); width: 34px; height: 34px; border-radius: 9px; font-size: 16px; }
.refresh:hover { color: var(--accent); border-color: var(--accent); }

.main { grid-column: 2; padding: 24px; overflow-x: hidden; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.err-banner { color: var(--error); background: rgba(224,92,92,0.1); border: 1px solid var(--error); padding: 12px 16px; border-radius: 10px; }

/* ── Cards & grid ──────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head img { width: 38px; height: 38px; border-radius: 9px; }
.page-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.page-head p { color: var(--muted); font-size: 13px; margin-top: 1px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
}
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat .sub { color: var(--accent); font-size: 12px; margin-top: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; min-width: 0; }
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 14px; color: var(--text); }
.card h3 .muted { color: var(--muted); font-weight: 400; }
/* min-width:0 lets grid children shrink so the inner .table-wrap can scroll
   instead of the card overflowing the viewport (and getting clipped). */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col > * { min-width: 0; }

/* ── Tables ────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--surface-alt); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.clickable { cursor: pointer; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.gold { background: rgba(201,168,76,0.16); color: var(--accent-light); }
.pill.green { background: rgba(76,175,130,0.16); color: var(--success); }
.pill.red { background: rgba(224,92,92,0.16); color: var(--error); }
.pill.grey { background: var(--surface-alt); color: var(--muted); }
.pill.roast { background: var(--error); color: #fff; box-shadow: 0 0 0 1px rgba(224,92,92,0.4); }
.pill.dim { opacity: 0.55; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

/* ── Funnel bars ───────────────────────────────────────────────────────── */
.funnel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.funnel-row .label { width: 150px; font-size: 13px; color: var(--muted); }
.funnel-row .bar-track { flex: 1; background: var(--surface-alt); border-radius: 6px; height: 26px; overflow: hidden; }
.funnel-row .bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-light)); border-radius: 6px; }
.funnel-row .val { width: 110px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ── Search ────────────────────────────────────────────────────────────── */
.search { width: 100%; max-width: 360px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; margin-bottom: 16px; }

/* ── Drawer ────────────────────────────────────────────────────────────── */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(560px, 100%);
  background: var(--bg); border-left: 1px solid var(--border); padding: 24px; overflow-y: auto;
  animation: slidein 0.18s ease;
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.drawer-head .x { background: var(--surface-alt); border: none; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; font-size: 16px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; margin: 14px 0; }
.kv .k { color: var(--muted); }
.timeline { font-size: 12.5px; }
.timeline li { list-style: none; padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.timeline .t { color: var(--muted); width: 120px; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.tabs { display: flex; gap: 6px; margin: 16px 0 10px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 12px; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.feedback-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; font-size: 13.5px; }
.feedback-item .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Fixed-height wrapper stops the Chart.js responsive-resize feedback loop
   (canvas grows → parent grows → canvas grows…) on desktop and mobile alike. */
.chart-box { position: relative; height: 300px; width: 100%; }
.chart-box canvas { position: absolute; inset: 0; }

/* ── Rezil Köpek popup ─────────────────────────────────────────────────── */
.roast-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.62); padding: 24px; }
.roast-card {
  background: var(--surface); border: 1px solid var(--error); border-radius: 18px; padding: 30px 26px;
  max-width: 400px; text-align: center; box-shadow: 0 0 50px rgba(224,92,92,0.35); animation: pop 0.22s ease;
}
.roast-emoji { font-size: 56px; line-height: 1; }
.roast-card h3 { color: var(--error); margin: 12px 0 8px; font-size: 21px; }
.roast-card p { color: var(--text); font-size: 14.5px; line-height: 1.55; margin-bottom: 20px; }
.roast-close { background: var(--error); color: #fff; border: none; padding: 11px 22px; border-radius: 11px; font-weight: 700; font-size: 14px; cursor: pointer; }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }

/* Shame stage: image + "Ben rezilim" / runaway "Rezil değilim". */
.shame-img { width: 100%; max-width: 320px; border-radius: 12px; margin-bottom: 18px; display: block; }
.shame-btns { display: flex; gap: 12px; justify-content: center; align-items: center; }
.shame-yes { background: var(--error); color: #fff; border: none; padding: 11px 22px; border-radius: 11px; font-weight: 700; font-size: 14px; cursor: pointer; }
.shame-no {
  background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border);
  padding: 11px 22px; border-radius: 11px; font-weight: 600; font-size: 14px; z-index: 101;
  touch-action: none; user-select: none;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 232px; z-index: 40; transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,0.5); }
  .topbar, .main { grid-column: 1; }
  .menu-btn { display: block; }
  .two-col { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .chart-box { height: 240px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .stat .v { font-size: 22px; }
  .drawer-panel { padding: 18px; }
  .kv { grid-template-columns: 110px 1fr; }
}
