:root {
      color-scheme: light;
      --bg: #f4f6f8;
      --surface: #ffffff;
      --surface-2: #f7f8fa;
      --surface-3: #eef1f4;
      --text: #14171b;
      --text-2: #59616c;
      --text-3: #89919c;
      --border: #dfe3e8;
      --border-strong: #cbd1d8;
      --accent: #256b36;
      --accent-soft: rgba(37,107,54,.10);
      --success: #12805c;
      --success-soft: rgba(18,128,92,.11);
      --danger: #c53939;
      --danger-soft: rgba(197,57,57,.10);
      --warning: #9a6700;
      --shadow: 0 10px 30px rgba(20,23,27,.07);
      --shadow-lg: 0 22px 70px rgba(20,23,27,.17);
      --radius: 18px;
      --radius-sm: 12px;
      --focus: 0 0 0 3px rgba(37,107,54,.18);
    }

    :root[data-theme="dark"] {
      color-scheme: dark;
      --bg: #0d1117;
      --surface: #151a21;
      --surface-2: #1a2029;
      --surface-3: #232b36;
      --text: #f2f5f7;
      --text-2: #a9b2bd;
      --text-3: #737d89;
      --border: #2a333e;
      --border-strong: #3a4654;
      --accent: #75cf88;
      --accent-soft: rgba(117,207,136,.13);
      --success: #54d3a8;
      --success-soft: rgba(84,211,168,.12);
      --danger: #ff7c7c;
      --danger-soft: rgba(255,124,124,.12);
      --warning: #f0bd55;
      --shadow: 0 12px 36px rgba(0,0,0,.24);
      --shadow-lg: 0 24px 80px rgba(0,0,0,.46);
      --focus: 0 0 0 3px rgba(117,207,136,.22);
    }

    * { box-sizing: border-box; }
    html { -webkit-text-size-adjust: 100%; }
    body {
      margin: 0;
      min-height: 100vh;
      background: var(--bg);
      color: var(--text);
      font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
    }
    button, input, select, textarea { font: inherit; }
    button { color: inherit; }
    button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
      outline: none;
      box-shadow: var(--focus);
    }

    .app-shell { min-height: 100vh; display: flex; flex-direction: column; }
    .topbar {
      position: sticky; top: 0; z-index: 50;
      backdrop-filter: blur(18px);
      background: color-mix(in srgb, var(--bg) 84%, transparent);
      border-bottom: 1px solid var(--border);
    }
    .topbar-inner {
      width: min(1180px, 100%);
      margin: 0 auto;
      min-height: 72px;
      padding: 12px 22px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
    }
    .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
    .brand-mark {
      width: 42px; height: 42px; border-radius: 13px;
      background: var(--text); color: var(--surface);
      display: grid; place-items: center;
      font-size: 12px; font-weight: 800; letter-spacing: .08em;
      box-shadow: var(--shadow);
      flex: 0 0 auto;
    }
    .brand-copy { min-width: 0; }
    .brand-title { font-size: 16px; font-weight: 750; letter-spacing: -.01em; white-space: nowrap; }
    .brand-sub { margin-top: 2px; color: var(--text-2); font-size: 12px; white-space: nowrap; }
    .header-actions { display: flex; align-items: center; gap: 8px; }
    .clock-box { text-align: right; margin-right: 6px; }
    .clock { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 720; }
    .date { color: var(--text-2); font-size: 11px; margin-top: 2px; }

    .icon-button, .secondary-button, .ghost-button {
      min-height: 40px;
      border: 1px solid var(--border);
      background: var(--surface);
      border-radius: 11px;
      cursor: pointer;
      transition: transform .15s ease, border-color .15s ease, background .15s ease;
    }
    .icon-button:hover, .secondary-button:hover, .ghost-button:hover { border-color: var(--border-strong); transform: translateY(-1px); }
    .icon-button { width: 42px; display: grid; place-items: center; font-size: 17px; }
    .secondary-button { padding: 0 14px; font-weight: 650; font-size: 13px; }
    .ghost-button { padding: 0 12px; color: var(--text-2); font-size: 13px; }

    main {
      width: min(1180px, 100%);
      margin: 0 auto;
      padding: 26px 22px 40px;
      flex: 1;
    }
    .intro {
      display: flex; justify-content: space-between; align-items: end; gap: 20px;
      margin-bottom: 18px;
    }
    .intro h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); letter-spacing: -.035em; line-height: 1.15; }
    .intro p { margin: 7px 0 0; color: var(--text-2); font-size: 14px; }
    .status-chip {
      display: inline-flex; align-items: center; gap: 7px;
      padding: 7px 10px;
      border: 1px solid var(--border);
      border-radius: 999px;
      font-size: 12px; color: var(--text-2);
      background: var(--surface);
      white-space: nowrap;
    }
    .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
    .status-chip.online .dot { background: var(--success); }
    .status-chip.offline .dot { background: var(--danger); }

    .layout { display: grid; grid-template-columns: minmax(0, .95fr) minmax(360px, 1.05fr); gap: 18px; align-items: start; }
    .stack { display: grid; gap: 14px; }
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 18px;
    }
    .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
    .eyebrow { color: var(--text-3); font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .13em; }
    .card-title { margin: 3px 0 0; font-size: 16px; font-weight: 760; }
    .hint { color: var(--text-2); font-size: 12px; line-height: 1.55; }

    label.field-label { display: block; color: var(--text-2); font-size: 12px; font-weight: 650; margin-bottom: 7px; }
    .field + .field { margin-top: 14px; }
    select, input, textarea {
      width: 100%;
      border: 1px solid var(--border);
      background: var(--surface-2);
      color: var(--text);
      border-radius: 12px;
      padding: 11px 12px;
      outline: none;
      transition: border-color .15s ease, background .15s ease;
    }
    select:focus, input:focus, textarea:focus { border-color: var(--accent); }
    textarea { min-height: 82px; resize: vertical; }
    input::placeholder, textarea::placeholder { color: var(--text-3); }

    .segmented {
      display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
      padding: 5px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border);
    }
    .segment {
      min-height: 44px; border: 0; border-radius: 10px; background: transparent;
      cursor: pointer; color: var(--text-2); font-weight: 760;
      transition: .15s ease;
    }
    .segment.active.in { background: var(--success-soft); color: var(--success); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--success) 38%, transparent); }
    .segment.active.out { background: var(--danger-soft); color: var(--danger); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger) 38%, transparent); }

    .employee-search { position: relative; }
    .employee-search input { padding-left: 38px; }
    .search-symbol { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
    .employee-list {
      margin-top: 9px;
      max-height: 278px;
      overflow: auto;
      display: grid;
      gap: 7px;
      scrollbar-width: thin;
    }
    .employee-button {
      width: 100%; text-align: left;
      border: 1px solid var(--border); background: var(--surface-2);
      border-radius: 12px; padding: 10px 12px; cursor: pointer;
      display: flex; align-items: center; gap: 10px;
      transition: .15s ease;
    }
    .employee-button:hover { border-color: var(--border-strong); transform: translateY(-1px); }
    .employee-button.selected { border-color: var(--accent); background: var(--accent-soft); }
    .avatar {
      width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
      display: grid; place-items: center; position: relative; overflow: hidden;
      background: var(--surface-3); color: var(--text-2); font-weight: 800; font-size: 13px;
    }
    .avatar-fallback { position: relative; z-index: 1; }
    .avatar-photo {
      position: absolute; inset: 0; z-index: 2;
      width: 100%; height: 100%; object-fit: cover;
      opacity: 0; transition: opacity .15s ease;
    }
    .avatar-photo.loaded { opacity: 1; }
    .employee-meta { min-width: 0; flex: 1; }
    .employee-name { font-size: 13px; font-weight: 720; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .employee-sub { margin-top: 2px; font-size: 11px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .selected-panel {
      display: none;
      border: 1px solid var(--accent);
      background: var(--accent-soft);
      border-radius: 14px; padding: 12px;
      align-items: center; justify-content: space-between; gap: 12px;
      margin-bottom: 10px;
    }
    .selected-panel.show { display: flex; }
    .selected-panel strong { display: block; font-size: 14px; }
    .selected-panel small { display: block; color: var(--text-2); margin-top: 2px; }

    .camera-frame {
      position: relative;
      width: 100%;
      aspect-ratio: 4/3;
      overflow: hidden;
      background: #080b0f;
      border-radius: 16px;
      border: 1px solid var(--border);
    }
    video, .snapshot { width: 100%; height: 100%; object-fit: cover; }
    video { display: none; transform: scaleX(-1); }
    .snapshot { display: none; }
    canvas { display: none; }
    .camera-placeholder {
      position: absolute; inset: 0;
      display: grid; place-items: center;
      text-align: center; color: #88929f;
      padding: 24px;
    }
    .camera-placeholder .camera-icon { width: 54px; height: 42px; border: 2px solid #64707e; border-radius: 12px; margin: 0 auto 13px; position: relative; opacity: .75; }
    .camera-placeholder .camera-icon::before { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid #64707e; border-radius: 50%; left: 50%; top: 50%; transform: translate(-50%,-50%); }
    .camera-placeholder .camera-icon::after { content: ""; position: absolute; width: 15px; height: 6px; border: 2px solid #64707e; border-bottom: 0; border-radius: 5px 5px 0 0; top: -8px; left: 9px; }
    .camera-live-badge {
      position: absolute; top: 10px; left: 10px;
      padding: 6px 9px; border-radius: 999px;
      background: rgba(8,11,15,.70); color: #e9edf2;
      font-size: 11px; backdrop-filter: blur(8px);
      display: none;
    }
    .camera-live-badge.show { display: block; }
    .camera-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
    .camera-actions button { min-height: 43px; }

    .readiness { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 13px; }
    .ready-item {
      border: 1px solid var(--border); background: var(--surface-2);
      border-radius: 11px; padding: 9px 10px;
    }
    .ready-item span { display: block; color: var(--text-3); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
    .ready-item strong { display: block; margin-top: 4px; font-size: 11px; font-weight: 720; }
    .ready-item.good strong { color: var(--success); }
    .ready-item.bad strong { color: var(--danger); }

    .submit-wrap { position: sticky; bottom: 12px; z-index: 20; margin-top: 14px; }
    .submit-button {
      width: 100%; min-height: 54px;
      border: 0; border-radius: 15px;
      font-weight: 820; font-size: 15px;
      cursor: pointer;
      box-shadow: var(--shadow-lg);
      transition: transform .15s ease, filter .15s ease, opacity .15s ease;
    }
    .submit-button.in { background: var(--success); color: #fff; }
    .submit-button.out { background: var(--danger); color: #fff; }
    .submit-button:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
    .submit-button:not(:disabled):hover { transform: translateY(-1px); filter: brightness(1.04); }

    .theme-switch {
      display: inline-flex; align-items: center; gap: 2px;
      padding: 3px; border: 1px solid var(--border);
      background: var(--surface); border-radius: 12px;
    }
    .theme-icon-btn {
      width: 34px; height: 34px; border: 0; border-radius: 9px;
      display: grid; place-items: center; padding: 0;
      background: transparent; color: var(--text-2); cursor: pointer;
    }
    .theme-icon-btn:hover { background: var(--surface-2); color: var(--text); }
    .theme-icon-btn.active { background: var(--text); color: var(--surface); box-shadow: var(--shadow); }
    .theme-icon-btn svg {
      width: 18px; height: 18px; fill: none; stroke: currentColor;
      stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
    }

    .modal-backdrop {
      position: fixed; inset: 0; z-index: 100;
      background: rgba(0,0,0,.55);
      backdrop-filter: blur(7px);
      display: none; align-items: center; justify-content: center;
      padding: 18px;
    }
    .modal-backdrop.open { display: flex; }
    .modal {
      width: min(540px, 100%);
      max-height: min(90vh, 760px);
      overflow: auto;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 22px;
      box-shadow: var(--shadow-lg);
      padding: 20px;
    }
    .modal h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
    .modal p { margin: 7px 0 16px; color: var(--text-2); font-size: 13px; line-height: 1.55; }
    .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
    .modal-actions button { min-height: 42px; }
    .primary-small { border: 0; background: var(--accent); color: white; border-radius: 11px; padding: 0 15px; font-weight: 740; cursor: pointer; }
    .danger-small { border: 0; background: var(--danger); color: white; border-radius: 11px; padding: 0 15px; font-weight: 740; cursor: pointer; }

    .register-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .register-grid .full { grid-column: 1 / -1; }
    .mini-camera { aspect-ratio: 16/10; }

    .toast-stack {
      position: fixed; right: 18px; bottom: 18px; z-index: 200;
      width: min(390px, calc(100vw - 36px));
      display: grid; gap: 9px;
      pointer-events: none;
    }
    .toast {
      pointer-events: auto;
      border: 1px solid var(--border);
      background: var(--surface);
      border-radius: 14px;
      padding: 12px 14px;
      box-shadow: var(--shadow-lg);
      display: flex; gap: 10px; align-items: flex-start;
      animation: toast-in .22s ease both;
    }
    @keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
    .toast-mark { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; background: var(--accent); }
    .toast.success .toast-mark { background: var(--success); }
    .toast.error .toast-mark { background: var(--danger); }
    .toast-title { font-size: 13px; font-weight: 760; }
    .toast-detail { color: var(--text-2); font-size: 12px; line-height: 1.45; margin-top: 2px; }

    .upload-center {
      position: fixed; left: 50%; top: 50%; transform: translate(-50%,-50%);
      z-index: 150; width: min(420px, calc(100vw - 32px));
      display: grid; gap: 9px; pointer-events: none;
    }
    .upload-card {
      background: color-mix(in srgb, var(--surface) 96%, transparent);
      border: 1px solid var(--border);
      border-radius: 16px;
      box-shadow: var(--shadow-lg);
      padding: 14px 15px;
      display: flex; align-items: center; gap: 11px;
      backdrop-filter: blur(16px);
    }
    .spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: 0 0 auto; }
    @keyframes spin { to { transform: rotate(360deg); } }
    .upload-card.done .spinner { animation: none; border: 0; background: var(--success); }
    .upload-card.error .spinner { animation: none; border: 0; background: var(--danger); }
    .upload-card strong { display: block; font-size: 13px; }
    .upload-card small { display: block; color: var(--text-2); margin-top: 2px; font-size: 11px; }

    .empty { padding: 18px 10px; text-align: center; color: var(--text-3); font-size: 12px; }
    .visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

    @media (max-width: 880px) {
      .layout { grid-template-columns: 1fr; }
      .intro { align-items: flex-start; }
    }
    @media (max-width: 620px) {
      .topbar-inner { padding: 10px 13px; min-height: 64px; }
      .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
      .brand-title { font-size: 14px; }
      .brand-sub { font-size: 10px; }
      .clock-box { display: none; }
      .theme-switch { flex: 0 0 auto; }
      .theme-icon-btn { width: 32px; height: 32px; }
      .theme-icon-btn svg { width: 17px; height: 17px; }
      .secondary-button { padding: 0 10px; }
      main { padding: 18px 12px 32px; }
      .intro { margin-bottom: 13px; }
      .intro p { font-size: 12px; }
      .intro .status-chip { display: none; }
      .card { padding: 14px; border-radius: 15px; }
      .readiness { grid-template-columns: 1fr; }
      .register-grid { grid-template-columns: 1fr; }
      .register-grid .full { grid-column: auto; }
      .submit-wrap { bottom: max(10px, env(safe-area-inset-bottom)); }
      .toast-stack { right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); width: calc(100vw - 20px); }
    }
  
/* V6 interaction polish */
button, .panel, .employee-button, .ready-item, .status-chip, select, input, textarea {
  transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .18s ease, border-color .18s ease, background-color .18s ease, color .18s ease, opacity .18s ease;
}
@media (hover:hover) {
  button:not(:disabled):hover { transform:translateY(-2px); }
  button:not(:disabled):active { transform:translateY(0) scale(.985); }
  .panel:hover { transform:translateY(-2px); box-shadow:0 18px 48px rgba(0,0,0,.12); }
  .employee-button:hover { transform:translateY(-2px); box-shadow:0 10px 24px rgba(0,0,0,.12); }
  .ready-item:hover { transform:translateY(-1px); border-color:var(--border-strong); }
}
@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after { animation-duration:.01ms!important; animation-iteration-count:1!important; transition-duration:.01ms!important; scroll-behavior:auto!important; }
}
.hint-spaced{margin-top:6px}


/* Automatic mode hides the manual selector and its field label. */
#attendanceTypePicker[hidden], .field:has(> #attendanceTypePicker[hidden]) { display:none!important; }

/* Links styled as buttons use the same theme and geometry as native buttons. */
a.secondary-button, a.icon-button, a.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
a.secondary-button, a.secondary-button:visited, a.icon-button, a.icon-button:visited { color: var(--text); }
a.ghost-button, a.ghost-button:visited { color: var(--text-2); }
a.secondary-button:focus-visible, a.icon-button:focus-visible, a.ghost-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Keep the employee picker bounded in its own card. */
#employeeList {
  max-block-size: clamp(8rem, 30vh, 15rem);
  max-block-size: clamp(8rem, 30dvh, 15rem);
  min-inline-size: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  padding: 2px;
  gap: 6px;
}
#employeeList .employee-button { min-block-size: 44px; min-inline-size: 0; }
#employeeList :is(.employee-name, .employee-sub),
#selectedPanel :is(#selectedName, #selectedMeta) {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.4;
}
#selectedPanel > div { min-inline-size: 0; }
#selectedPanel button { flex: 0 0 auto; min-block-size: 44px; }
#employeeList .employee-button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.registration-link { min-block-size: 44px; }
@media (max-width: 620px) {
  #employeeList .employee-button { padding: 6px 8px; gap: 8px; }
  #employeeList .avatar { inline-size: 30px; block-size: 30px; }
  #employeeSearch { min-block-size: 44px; font-size: 1rem; }
  #employeeList .employee-name { font-size: .875rem; }
  #employeeList .employee-sub { font-size: .75rem; }
}
html[data-density="compact"] #employeeList { gap: 4px; }
html[data-density="compact"] #employeeList .employee-button { padding-block: 5px; }
