:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --ok: #16a34a;
  --err: #dc2626;
  --line: #e5e7eb;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

a { color: var(--brand); text-decoration: none; }
.muted { color: var(--muted); font-size: 0.9rem; }
.err { color: var(--err); min-height: 1.2em; margin-top: 0.5rem; font-size: 0.9rem; }

button {
  background: var(--brand);
  color: #fff;
  border: 0;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button:hover { background: var(--brand-2); }
button:active { transform: translateY(1px); }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
button.danger { background: var(--err); }
button.danger:hover { background: #b91c1c; }

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 0.95rem;
  outline: none;
  transition: border 0.15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }

label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; letter-spacing: 0.3px; }

.container {
  max-width: 1100px;
  margin: 1.2rem auto;
  padding: 0 1rem;
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0.1rem 0 0.8rem; font-size: 1.05rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stat span {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat b { display: block; font-size: 1.6rem; margin-top: 0.25rem; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  align-items: center;
}
.span2 { grid-column: span 2; }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 0.6rem; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
tr:hover td { background: #fafbff; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}
.badge.ok { background: #dcfce7; color: #166534; }
.badge.no { background: #fee2e2; color: #991b1b; }

/* Login page */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 20% 0%, #eef2ff, transparent),
    radial-gradient(1000px 600px at 80% 100%, #e0e7ff, transparent),
    var(--bg);
}
.auth-body .card { width: min(380px, 92vw); }
.auth-body h1 { margin: 0 0 0.25rem; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff;
  padding: 1.2rem;
  border-radius: var(--radius);
  width: min(520px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
}

/* Chart canvas */
canvas { max-width: 100%; }

/* Mobile */
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid, .grid-2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .container { margin: 0.6rem auto; }
  .topbar { padding: 0.7rem 1rem; }
  .stat b { font-size: 1.3rem; }
}