:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef3fb;
  --text: #172033;
  --muted: #64748b;
  --border: #dbe3ef;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --success: #15803d;
  --warning: #b45309;
  --danger: #dc2626;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
}

.view {
  width: 100%;
}

.auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card h1,
.teacher-shell h1,
.student-shell h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.auth-card p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

label {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
}

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

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 700;
}

.btn.primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border);
}

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.student-shell {
  width: min(540px, 100%);
  margin: 0 auto;
  padding: 16px 16px 96px;
}

.teacher-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.teacher-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.stack {
  display: grid;
  gap: 12px;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.photo-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 150px;
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.photo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-box button {
  position: absolute;
  right: 8px;
  bottom: 8px;
}

.location-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  word-break: break-word;
}

.plan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.plan-row:last-child {
  border-bottom: 0;
}

.plan-main {
  min-width: 0;
}

.plan-main strong {
  display: block;
}

.plan-main span {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.pending {
  background: #e2e8f0;
  color: #475569;
}

.badge.checked-in,
.badge.warning {
  background: #fef3c7;
  color: var(--warning);
}

.badge.checked-out,
.badge.done {
  background: #dcfce7;
  color: var(--success);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stats-grid div {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--muted);
  background: #fbfdff;
}

.stats-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 22px;
}

.student-list {
  display: grid;
  gap: 8px;
}

.student-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  text-align: left;
}

.student-row:hover {
  border-color: var(--primary);
}

.detail-box {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.photo-link,
.photo-missing {
  display: block;
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-soft);
  color: var(--primary);
  text-decoration: none;
  text-align: center;
}

.photo-link img {
  width: 100%;
  height: 120px;
  border-radius: 6px;
  object-fit: cover;
  margin-bottom: 8px;
}

.photo-missing {
  color: var(--muted);
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row input {
  flex: 1;
}

.camera-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #020617;
  padding: 16px;
}

.camera-modal video {
  width: 100%;
  height: 100%;
  max-height: calc(100dvh - 110px);
  object-fit: contain;
  background: #000;
  border-radius: var(--radius);
}

.camera-modal canvas {
  display: none;
}

.camera-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding-top: 16px;
}

.capture-btn {
  width: 62px;
  height: 62px;
  border: 5px solid #cbd5e1;
  border-radius: 50%;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 30;
  transform: translate(-50%, -120px);
  max-width: min(420px, calc(100% - 32px));
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  padding: 12px 18px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease;
}

.toast.show {
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 760px) {
  .teacher-layout,
  .photo-grid,
  .action-grid,
  .record-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }
}
