:root {
  --brand: #be123c;
  --brand-dark: #9f1239;
  --bg: #f8fafc;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --ok: #059669;
  --warn: #d97706;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Noto Sans Thai', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

#loginScreen.active {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--card);
  border-radius: 1.25rem;
  padding: 2rem;
  width: 100%;
  max-width: 22rem;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
}

.brand { text-align: center; margin-bottom: 1.5rem; }
.brand h1 { margin: 0.5rem 0 0; font-size: 1.35rem; }
.brand p { margin: 0.25rem 0; color: var(--muted); font-size: 0.9rem; }

.lbl { display: block; font-size: 0.85rem; margin: 0.75rem 0 0.25rem; color: var(--muted); }
.inp {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  font-size: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: 0.65rem;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary {
  width: 100%;
  margin-top: 1rem;
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

.error { color: #dc2626; font-size: 0.9rem; margin-top: 0.75rem; }
.hidden { display: none !important; }

.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.app-header h1 { font-size: 1.1rem; margin: 0; flex: 1; min-width: 8rem; }
.app-header .user { font-size: 0.85rem; color: var(--muted); }

.nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
}
.nav a.active { background: #fff1f3; color: var(--brand); font-weight: 600; }

.app-main { flex: 1; padding: 1rem; max-width: 1100px; margin: 0 auto; width: 100%; }

.card {
  background: var(--card);
  border-radius: 1rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.card h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}
.stat {
  background: #f1f5f9;
  border-radius: 0.75rem;
  padding: 0.85rem;
}
.stat .val { font-size: 1.5rem; font-weight: 700; color: var(--brand); }
.stat .lbl { font-size: 0.8rem; color: var(--muted); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th,
table.data td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.data th { color: var(--muted); font-weight: 500; }
table.data tr:hover { background: #f8fafc; }
table.data a { color: var(--brand); text-decoration: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar select {
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  font-family: inherit;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.metric {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem;
}
.metric code { font-size: 0.75rem; color: var(--muted); }
.metric .value { font-size: 1.25rem; font-weight: 700; }

.score-form label {
  display: block;
  margin: 0.5rem 0 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.score-form input {
  width: 100%;
  max-width: 8rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.pilot-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.65rem 1rem;
  border-radius: 0.65rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.loading { text-align: center; padding: 2rem; color: var(--muted); }

@media (max-width: 640px) {
  .app-header { flex-direction: column; align-items: flex-start; }
}
