:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --morning: #0284c7;
  --morning-dark: #0369a1;
  --morning-soft: #e0f2fe;
  --morning-border: #bae6fd;

  --afternoon: #4f46e5;
  --afternoon-dark: #4338ca;
  --afternoon-soft: #e0e7ff;
  --afternoon-border: #c7d2fe;

  --in-color: #059669;
  --in-bg: #ecfdf5;
  --in-border: #a7f3d0;

  --out-color: #d97706;
  --out-bg: #fffbeb;
  --out-border: #fde68a;

  --err-color: #dc2626;
  --err-bg: #fef2f2;
  --err-border: #fecaca;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px -6px rgba(15, 23, 42, 0.08), 0 2px 6px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Top Navigation Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
}

.nav-tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.nav-tab.active-morning {
  background: var(--morning);
  color: #fff;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.25);
}

.nav-tab.active-afternoon {
  background: var(--afternoon);
  color: #fff;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
}

.nav-tab.active-report {
  background: #0f172a;
  color: #fff;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.2);
}

.clock-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.clock-time {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

.clock-date {
  font-size: 12px;
  color: var(--text-muted);
}

/* Main Container */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* Period Hero Banner */
.period-banner {
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: #fff;
  box-shadow: var(--shadow-md);
}

.period-banner.morning {
  background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 55%, #38bdf8 100%);
}

.period-banner.afternoon {
  background: linear-gradient(135deg, #4338ca 0%, #4f46e5 55%, #7c3aed 100%);
}

.period-banner-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.period-icon-circle {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.period-banner h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.period-banner p {
  margin: 4px 0 0;
  font-size: 14px;
  opacity: 0.92;
}

.period-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.pill-toggle:hover {
  background: rgba(255, 255, 255, 0.26);
}

/* Kiosk Grid Layout */
.kiosk-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.95fr);
  gap: 22px;
  align-items: start;
}

@media (max-width: 960px) {
  .kiosk-grid {
    grid-template-columns: 1fr;
  }
  .clock-box {
    align-items: flex-start;
  }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-body {
  padding: 24px;
}

/* Scan Form Card */
.scan-card {
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}

.scan-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.scan-form {
  display: flex;
  gap: 12px;
}

.scan-input {
  flex: 1;
  min-width: 0;
  height: 60px;
  padding: 0 20px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 1px;
  border: 2px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-subtle);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.scan-input::placeholder {
  font-family: 'IBM Plex Sans Thai', sans-serif;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text-soft);
}

.scan-input:focus {
  background: #fff;
  border-color: var(--accent, var(--morning));
  box-shadow: 0 0 0 4px var(--accent-ring, rgba(2, 132, 199, 0.16));
}

.scan-btn {
  height: 60px;
  padding: 0 26px;
  border: none;
  border-radius: 14px;
  background: var(--accent, var(--morning));
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.1s ease, filter 0.15s ease;
  white-space: nowrap;
}

.scan-btn:hover {
  filter: brightness(1.06);
}

.scan-btn:active {
  transform: scale(0.98);
}

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

.scan-hint {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* Status Display Card */
.status-card {
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: 310px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.status-card.state-idle {
  border-style: dashed;
  border-width: 2px;
  border-color: var(--border-strong);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.status-card.state-in {
  border: 2px solid var(--in-border);
  box-shadow: 0 12px 30px -10px rgba(5, 150, 105, 0.22);
}

.status-card.state-out {
  border: 2px solid var(--out-border);
  box-shadow: 0 12px 30px -10px rgba(217, 119, 6, 0.22);
}

.status-card.state-error {
  border: 2px solid var(--err-border);
  box-shadow: 0 12px 30px -10px rgba(220, 38, 38, 0.2);
}

.status-header-strip {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.state-in .status-header-strip {
  background: var(--in-bg);
  color: var(--in-color);
  border-bottom: 1px solid var(--in-border);
}

.state-out .status-header-strip {
  background: var(--out-bg);
  color: #b45309;
  border-bottom: 1px solid var(--out-border);
}

.state-error .status-header-strip {
  background: var(--err-bg);
  color: var(--err-color);
  border-bottom: 1px solid var(--err-border);
}

.status-big-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.1;
}

.status-timestamp {
  font-size: 20px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.8);
}

.status-content {
  padding: 26px 24px;
}

.idle-placeholder {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-muted);
}

.idle-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
  display: grid;
  place-items: center;
}

.idle-placeholder h2 {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--text);
}

.idle-placeholder p {
  margin: 0;
  font-size: 14px;
}

.student-identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.student-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.student-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.session-callout {
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--out-bg);
  border: 1px solid var(--out-border);
  color: #92400e;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.session-callout strong {
  font-size: 18px;
}

.hours-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 560px) {
  .hours-mini-grid {
    grid-template-columns: 1fr;
  }
  .scan-form {
    flex-direction: column;
  }
}

.hours-mini-box {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.hours-mini-box.highlight {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.hours-mini-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.hours-mini-box.highlight .hours-mini-label {
  color: #cbd5e1;
}

.hours-mini-value {
  font-size: 18px;
  font-weight: 700;
}

/* Animations */
@keyframes popIn {
  0% { transform: scale(0.97); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.animate-pop {
  animation: popIn 0.22s ease-out;
}

.animate-shake {
  animation: shake 0.35s ease-in-out;
}

/* Right Column KPIs & Activity */
.kpi-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
  margin-top: 4px;
  color: var(--text);
}

.kpi-value.green { color: var(--in-color); }
.kpi-value.amber { color: var(--out-color); }
.kpi-value.blue { color: var(--morning); }
.kpi-value.indigo { color: var(--afternoon); }

.kpi-sub {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 2px;
}

.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.activity-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  max-height: 450px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid #f1f5f9;
}

.activity-item:last-child {
  border-bottom: none;
}

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

.activity-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.activity-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-in {
  background: var(--in-bg);
  color: var(--in-color);
  border: 1px solid var(--in-border);
}

.badge-out {
  background: var(--out-bg);
  color: #b45309;
  border: 1px solid var(--out-border);
}

.badge-morning {
  background: var(--morning-soft);
  color: var(--morning-dark);
}

.badge-afternoon {
  background: var(--afternoon-soft);
  color: var(--afternoon-dark);
}

.badge-neutral {
  background: var(--bg);
  color: var(--text-muted);
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Home Hub Cards */
.hub-hero {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #334155 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.hub-hero h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 800;
}

.hub-hero p {
  margin: 0;
  color: #cbd5e1;
  max-width: 600px;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 900px) {
  .hub-grid {
    grid-template-columns: 1fr;
  }
}

.hub-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.hub-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.hub-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
}

.hub-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.hub-card p {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.hub-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
}

/* Report Page Styles */
.report-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .report-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 160px;
}

.filter-group.grow {
  flex: 1;
  min-width: 220px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.form-control:focus {
  border-color: var(--morning);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.14);
}

.btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: #0f172a;
  color: #fff;
}

.btn-primary:hover {
  background: #1e293b;
}

.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-outline:hover {
  background: var(--surface-subtle);
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
}

.quick-dates {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
}

.quick-date-chip {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.quick-date-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.quick-date-chip.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

/* Data Table */
.table-card {
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data-table th {
  text-align: left;
  padding: 13px 16px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

table.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

table.data-table tbody tr:hover {
  background: #f8fafc;
}

.time-cell-main {
  font-weight: 700;
  color: var(--text);
}

.time-cell-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}
