* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: #f5f6f8;
  color: #1a1a1a;
  min-height: 100vh;
}
.screen { display: none; }
.screen.active { display: block; }

/* Login */
#login-screen.active {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ff6b9d 0%, #845EC2 100%);
}
.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
  min-width: 360px;
}
.login-card h1 { font-size: 28px; margin-bottom: 8px; }
.login-card .subtitle { color: #666; margin-bottom: 24px; }
.login-card .hint { color: #999; font-size: 12px; margin-top: 16px; }
.error-msg { background: #fee; color: #c00; padding: 10px; border-radius: 6px; margin-top: 12px; font-size: 13px; }
.loading-msg { background: #e3f2fd; color: #1565c0; padding: 10px; border-radius: 6px; margin-top: 12px; font-size: 13px; }
.google-signin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 12px 20px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  background: #fff;
  color: #3c4043;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.15s;
}
.google-signin-btn:hover {
  background: #f8f9fa;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.google-signin-btn:active { background: #eee; }
.google-signin-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Dashboard layout */
#dashboard-screen.active { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: 60px 1fr; min-height: 100vh; }
.topbar {
  grid-column: 1 / -1;
  background: #1a1a2e;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 { font-size: 18px; }
.badge { background: #ff6b9d; color: #fff; padding: 2px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right img { width: 32px; height: 32px; border-radius: 50%; }
.btn-link { background: transparent; color: #ff6b9d; border: none; cursor: pointer; font-size: 14px; }

.sidenav { background: #fff; border-right: 1px solid #e0e0e0; padding: 16px 0; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px;
  color: #555;
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 14px;
  transition: all 0.15s;
}
.nav-item:hover { background: #f5f6f8; color: #1a1a1a; }
.nav-item.active { background: #ffe4ef; color: #ff6b9d; border-left-color: #ff6b9d; font-weight: 600; }
.pill { background: #ff6b9d; color: #fff; padding: 1px 8px; border-radius: 10px; font-size: 11px; }

.content { padding: 24px 32px; overflow-y: auto; }
.section-content { display: none; }
.section-content.active { display: block; }
.section-content h2 { margin-bottom: 16px; }
.section-content h3 { margin: 24px 0 12px; font-size: 16px; color: #555; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border-left: 4px solid #845EC2;
}
.stat-card.stat-green { border-left-color: #00C97A; }
.stat-card.stat-yellow { border-left-color: #FFB400; }
.stat-card.stat-red { border-left-color: #FF4757; }
.stat-label { font-size: 12px; color: #777; margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; }

.stats-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stats-row .stat-card { flex: 1; min-width: 140px; }

/* Tables */
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-row select, .filter-row input {
  padding: 8px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 13px;
}
.data-table { width: 100%; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid #eee; }
.data-table th { background: #f8f9fb; font-weight: 600; color: #555; font-size: 12px; text-transform: uppercase; }
.data-table tr:hover { background: #fafbfc; }
.status-active { color: #00C97A; font-weight: 600; }
.status-pending { color: #FFB400; font-weight: 600; }
.status-expired { color: #FF4757; font-weight: 600; }
.status-free { color: #888; font-weight: 500; }
.status-approved { color: #00C97A; font-weight: 600; }
.status-rejected { color: #FF4757; font-weight: 600; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger, .btn-success {
  padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; border: none;
}
.btn-primary { background: #ff6b9d; color: #fff; }
.btn-primary:hover { background: #ff4d8a; }
.btn-secondary { background: #eee; color: #333; }
.btn-secondary:hover { background: #ddd; }
.btn-danger { background: #FF4757; color: #fff; }
.btn-success { background: #00C97A; color: #fff; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* Slips grid */
.slips-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.slip-card {
  background: #fff; border-radius: 12px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: transform 0.15s;
}
.slip-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
.slip-card img { width: 100%; height: 200px; object-fit: cover; display: block; }
.slip-card .slip-info { padding: 12px; font-size: 12px; }
.slip-card .slip-info b { display: block; margin-bottom: 4px; font-size: 13px; }

/* Settings form */
.settings-form { background: #fff; padding: 24px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); margin-bottom: 16px; }
.settings-form .setting-row { margin-bottom: 16px; }
.settings-form label { display: block; font-size: 12px; color: #666; margin-bottom: 4px; font-weight: 600; }
.settings-form input, .settings-form textarea, .settings-form select {
  width: 100%; padding: 8px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
}
.settings-form .setting-desc { font-size: 11px; color: #999; margin-top: 2px; }

/* Modal */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 100; align-items: center; justify-content: center; }
.modal.active { display: flex; }
.modal-content { background: #fff; border-radius: 12px; padding: 24px; min-width: 400px; max-width: 90vw; max-height: 90vh; overflow-y: auto; }
.modal-large { min-width: 600px; }
.modal-content h3 { margin-bottom: 16px; }
.modal-content label { display: block; margin-bottom: 12px; font-size: 13px; }
.modal-content input, .modal-content textarea, .modal-content select {
  width: 100%; padding: 8px 12px; margin-top: 4px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.slip-image-large { max-width: 100%; max-height: 60vh; border-radius: 8px; margin: 12px 0; display: block; }

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; }
.toast {
  background: #1a1a2e; color: #fff; padding: 12px 20px; border-radius: 8px;
  margin-top: 8px; font-size: 14px;
  animation: slideIn 0.3s ease-out;
  max-width: 350px;
}
.toast.success { background: #00C97A; }
.toast.error { background: #FF4757; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============================================ */
/* Mobile Responsive (max-width: 768px)        */
/* ============================================ */
@media (max-width: 768px) {
  /* Topbar — compact */
  .topbar {
    padding: 0 12px;
    height: 56px;
    flex-wrap: nowrap;
  }
  .topbar-left h1 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-left { gap: 6px; min-width: 0; flex: 0 1 auto; }
  .topbar-right {
    gap: 8px;
    flex: 0 0 auto;
  }
  .topbar-right #me-email {
    display: none; /* ซ่อน email บนมือถือ */
  }
  .topbar-right img { width: 28px; height: 28px; }
  .badge { font-size: 10px; padding: 1px 6px; }

  /* Dashboard layout — stack ทุกอย่าง */
  #dashboard-screen.active {
    grid-template-columns: 1fr;
    grid-template-rows: 56px auto 1fr;
  }

  /* Sidebar — horizontal scroll bar */
  .sidenav {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .sidenav::-webkit-scrollbar { height: 4px; }
  .sidenav::-webkit-scrollbar-thumb { background: #ddd; }
  .nav-item {
    flex: 0 0 auto;
    padding: 12px 14px;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    font-size: 13px;
  }
  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: #ff6b9d;
  }
  .pill { margin-left: 4px; }

  /* Content — full width */
  .content {
    padding: 16px 12px;
  }
  .content h2 { font-size: 18px; margin-bottom: 12px; }
  .content h3 { font-size: 14px; margin: 16px 0 8px; }

  /* Stat cards — full width stack */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .stat-card {
    padding: 14px;
  }
  .stat-value {
    font-size: 22px;
  }
  .stats-row {
    flex-direction: column;
    gap: 8px;
  }
  .stats-row .stat-card { min-width: 100%; }

  /* Tables — horizontal scroll wrapper */
  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    font-size: 12px;
  }
  .data-table th, .data-table td {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* Filter rows — wrap */
  .filter-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Slip cards */
  .slips-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .slip-card img { height: 240px; }

  /* Modal */
  .modal-content {
    min-width: 90vw;
    max-width: 95vw;
    padding: 16px;
  }
  .modal-large { min-width: 95vw; }
  .modal-actions {
    flex-wrap: wrap;
  }
  .modal-actions button { flex: 1; min-width: 90px; }

  /* Settings form */
  .settings-form { padding: 16px; }

  /* Buttons */
  .btn-small { font-size: 11px; padding: 3px 8px; }
  .btn-primary, .btn-secondary, .btn-danger, .btn-success { font-size: 12px; padding: 6px 12px; }
}

/* ============================================ */
/* Small phones (max-width: 380px)             */
/* ============================================ */
@media (max-width: 380px) {
  .topbar-left h1 { font-size: 13px; }
  .badge { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
}
