/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #52A051;
  --primary-dark: #3d7a3d;
  --secondary: #A1527B;
  --success: #52A051;
  --warning: #e8a827;
  --danger: #c53929;
  --bg: #f9f1ec;
  --card-bg: #ffffff;
  --text: #2d2a27;
  --text-secondary: #6b6560;
  --border: #e4dbd4;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 0;
}

/* ===== App Container ===== */
#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ===== Views ===== */
.view {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  min-height: 100dvh;
  width: 100%;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Card ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  width: 100%;
  text-align: center;
}

/* ===== Logo ===== */
.logo {
  color: var(--primary);
  margin-bottom: 12px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 24px;
  width: 100%;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(82, 160, 81, 0.3);
}

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

.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(82, 160, 81, 0.3);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(161, 82, 123, 0.3);
}

.btn-warning {
  background: var(--warning);
  color: #fff;
  box-shadow: 0 2px 8px rgba(232, 168, 39, 0.3);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(197, 57, 41, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 2px solid var(--border);
  margin-top: 8px;
}

.btn-lg {
  padding: 16px 24px;
  font-size: 1.1rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:active {
  background: rgba(0,0,0,0.05);
}

/* ===== Hint & Error ===== */
.hint {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 16px;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  padding: 8px 12px;
  background: #fce8e6;
  border-radius: var(--radius-sm);
}

.hidden {
  display: none !important;
}

/* ===== Spinner ===== */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Camera ===== */
.camera-container {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.captured-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.capture-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 10;
  border-radius: var(--radius);
}

.capture-loading .spinner {
  border-color: rgba(255,255,255,0.3);
  border-top-color: #fff;
}

.face-frame {
  width: 180px;
  height: 220px;
  border: 3px dashed rgba(255,255,255,0.6);
  border-radius: 20px;
}

.camera-actions {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ===== Dashboard Header ===== */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 0 16px;
}

.user-name {
  font-weight: 700;
  font-size: 1.1rem;
  display: block;
}

.user-status-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-top: 4px;
}

.user-status-badge.off {
  background: #e4dbd4;
  color: #6b6560;
}

.user-status-badge.working {
  background: #dff0de;
  color: #3d7a3d;
}

.user-status-badge.paused {
  background: #fef3d5;
  color: #8a6d1b;
}

.user-status-badge.error {
  background: #fce8e6;
  color: #c53929;
}

/* ===== Stats ===== */
.dashboard-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card.full {
  grid-column: 1 / -1;
}

.stat-card.accent {
  background: var(--primary);
  color: #fff;
}

.stat-card.accent .stat-label {
  opacity: 0.85;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.7;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ===== Overtime Banner ===== */
.overtime-banner {
  background: #fef3d5;
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: #5c3b00;
  width: 100%;
}

/* ===== Action Grid ===== */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.action-grid .btn {
  padding: 20px 12px;
  font-size: 1rem;
  flex-direction: column;
  gap: 8px;
  border-radius: var(--radius);
  min-height: 90px;
}

.action-grid .btn svg {
  width: 28px;
  height: 28px;
}

.action-grid .btn:only-child {
  grid-column: 1 / -1;
}

/* ===== Last Action ===== */
.last-action {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 70vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal h3 {
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.reason-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.reason-btn {
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.reason-btn:active {
  border-color: var(--primary);
  background: #ecf3eb;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  z-index: 200;
  animation: toastIn 0.3s ease;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}

.toast.hidden {
  display: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Responsive Desktop ===== */
@media (min-width: 481px) {
  #app {
    min-height: auto;
    margin: 20px auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: 95dvh;
    overflow-y: auto;
  }

  .view {
    min-height: auto;
    padding: 24px;
  }
}