/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --card:         #1c2128;
  --border:       #30363d;
  --text:         #e6edf3;
  --muted:        #8b949e;
  --accent:       #388bfd;
  --accent-hover: #58a6ff;
  --green:        #3fb950;
  --red:          #f85149;
  --yellow:       #e3b341;
  --sidebar-w:    248px;
  --header-h:     52px;
  --panel-w:      420px;
  --radius:       6px;
  --transition:   200ms ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Typography helpers ─────────────────────────────────────────────────────── */
.text-muted  { color: var(--muted); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-sm     { font-size: 0.85rem; }
.hidden      { display: none !important; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
button { cursor: pointer; font: inherit; border: none; outline: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.875rem;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border: 1px solid var(--border);
  transition: color var(--transition), border-color var(--transition);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-full  { width: 100%; }
.btn-sm    { font-size: 0.8rem; padding: 0.3rem 0.6rem; }

.icon-btn {
  background: transparent;
  color: var(--muted);
  padding: 0.4rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,.06); }

/* hamburger */
.hamburger { flex-direction: column; gap: 4px; width: 32px; height: 32px; }
.hamburger span {
  display: block; width: 18px; height: 2px;
  background: var(--muted); border-radius: 2px;
  transition: background var(--transition);
}
.hamburger:hover span { background: var(--text); }

/* close × */
#close-panel-btn { font-size: 1.4rem; line-height: 1; width: 32px; height: 32px; }

/* ── Login modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 360px;
}

.login-box h2 { font-size: 1.25rem; margin-bottom: 0.25rem; }
.login-box .text-muted { font-size: 0.85rem; margin-bottom: 1.75rem; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.875rem;
  transition: border-color var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

input[readonly] { color: var(--muted); cursor: default; }

textarea { resize: vertical; min-height: 72px; }

select option { background: var(--surface); }

.msg {
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
.msg-success { background: rgba(63,185,80,.12); color: var(--green); border: 1px solid rgba(63,185,80,.25); }
.msg-error   { background: rgba(248,81,73,.12); color: var(--red);   border: 1px solid rgba(248,81,73,.25); }

/* ── Header ─────────────────────────────────────────────────────────────────── */
#header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
  gap: 1rem;
}

.header-left  { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

.app-name {
  font-weight: 700; font-size: 0.95rem;
  color: var(--text); white-space: nowrap;
}

.project-title {
  color: var(--muted); font-size: 0.85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.project-title::before { content: '/'; margin-right: 0.5rem; color: var(--border); }
.project-title:empty::before { display: none; }

.auth-info { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ── App layout ─────────────────────────────────────────────────────────────── */
#app { height: 100vh; display: flex; flex-direction: column; }

.app-layout {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: width var(--transition), opacity var(--transition);
}

.sidebar-inner { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }

.project-list { display: flex; flex-direction: column; gap: 0.25rem; }

.project-section-label {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
  padding: 0.5rem 0.5rem 0.25rem;
  margin-top: 0.5rem;
}

.project-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
  border: none; background: transparent; text-align: left; width: 100%;
}
.project-item:hover { background: rgba(255,255,255,.06); color: var(--text); }
.project-item.active { background: rgba(56,139,253,.15); color: var(--accent-hover); font-weight: 600; }

.project-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.dot-active   { background: var(--green); }
.dot-archived { background: var(--muted); }

/* sidebar collapsed */
body.sidebar-collapsed #sidebar { width: 0; overflow: hidden; opacity: 0; }

/* ── Main / Dashboard ───────────────────────────────────────────────────────── */
#main { flex: 1; overflow-y: auto; padding: 1.5rem; min-width: 0; }

.state-view {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 40vh; gap: 1rem; color: var(--muted);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stat cards ─────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.stat-card .label {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.35rem;
}
.stat-card .value {
  font-size: 1.6rem; font-weight: 700; line-height: 1.1;
}
.stat-card .sub {
  font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem;
}
.stat-card.vs-positive .value { color: var(--green); }
.stat-card.vs-negative .value { color: var(--red); }

/* ── Progress bar ───────────────────────────────────────────────────────────── */
.progress-section { margin-bottom: 1.5rem; }
.progress-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 0.4rem;
}
.progress-header .progress-label { font-size: 0.8rem; color: var(--muted); }
.progress-header .progress-pct   { font-size: 0.9rem; font-weight: 700; color: var(--text); }

.progress-track {
  height: 8px; background: var(--border); border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 99px;
  transition: width .5s ease;
}

/* ── Charts ─────────────────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.chart-card h3 { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: .06em; }
.chart-card canvas { max-height: 220px; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-section { margin-bottom: 1.5rem; }
.table-section h3 { font-size: 0.9rem; font-weight: 700; margin-bottom: 0.75rem; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }

thead tr { background: var(--surface); }
thead th {
  padding: 0.55rem 0.9rem; text-align: left;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid rgba(48,54,61,.5); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.025); }
tbody td { padding: 0.55rem 0.9rem; color: var(--text); }

.val-positive { color: var(--green); font-weight: 600; }
.val-negative { color: var(--red);   font-weight: 600; }
.val-muted    { color: var(--muted); }

.badge {
  display: inline-block;
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  padding: 0.1rem 0.4rem; border-radius: 3px; letter-spacing: .05em;
  margin-left: 0.35rem; vertical-align: middle;
}
.badge-warn { background: rgba(227,179,65,.15); color: var(--yellow); border: 1px solid rgba(227,179,65,.3); }

/* ── Entry panel ────────────────────────────────────────────────────────────── */
#panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
}

.side-panel {
  position: fixed; top: 0; right: 0;
  width: var(--panel-w); max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 201;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition);
}
.side-panel.open { transform: translateX(0); }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-header h3 { font-size: 1rem; font-weight: 700; }

.panel-body { flex: 1; overflow-y: auto; padding: 1.25rem; }

.form-section { margin-bottom: 0.5rem; }
.form-section h4 { font-size: 0.875rem; font-weight: 700; margin-bottom: 0.75rem; }

.section-divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* Incident row */
.incident-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem;
  margin-bottom: 0.75rem;
}
.incident-row-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.5rem;
}
.incident-row-header span { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }

.remove-incident-btn {
  background: transparent; border: none;
  color: var(--muted); font-size: 1.1rem; line-height: 1;
  cursor: pointer; padding: 0 0.2rem;
  transition: color var(--transition);
}
.remove-incident-btn:hover { color: var(--red); }

.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { --sidebar-w: 0px; }
  body:not(.sidebar-collapsed) #sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: 248px; z-index: 90; box-shadow: 4px 0 20px rgba(0,0,0,.5);
  }
  .side-panel { width: 100vw; }
  .charts-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  #main { padding: 1rem; }
}
