/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --amber: #f59e0b;
  --amber-light: #fef3c7;
  --amber-border: #fbbf24;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* --- Login Page --- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}

.login-container {
  width: 100%;
  max-width: 420px;
  padding: 24px;
}

.login-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 48px 32px;
  text-align: center;
}

.login-logo { margin-bottom: 20px; }

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--gray-500);
  margin-bottom: 32px;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 32px;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  color: var(--gray-700);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
}

.google-btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
  box-shadow: var(--shadow);
}

.login-note {
  margin-top: 20px;
  font-size: 13px;
  color: var(--gray-500);
}

.error-msg {
  background: #fef2f2;
  color: var(--error);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 20px;
  font-size: 14px;
}

/* --- App Header --- */
.app-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name {
  font-size: 14px;
  color: var(--gray-700);
  font-weight: 500;
}

.user-pic {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.logout-btn {
  font-size: 13px;
  color: var(--gray-500);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  transition: all 0.15s;
}

.logout-btn:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* --- Name Input Bar --- */
.name-input-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid var(--gray-200);
}

.name-input-bar label {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
}

.counter-name-input {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 15px;
  color: var(--gray-900);
  min-height: 44px;
  outline: none;
}

.counter-name-input:focus {
  border-color: var(--primary);
}

.load-btn {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  transition: background 0.15s;
}

.load-btn:hover {
  background: var(--primary-dark);
}

/* --- Stats Bar --- */
.stats-bar {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid var(--gray-200);
}

.stat {
  flex: 1;
  text-align: center;
  padding: 8px;
  background: var(--gray-50);
  border-radius: 8px;
}

.stat-num {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
}

.stat-label {
  font-size: 12px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-recheck .stat-num { color: var(--amber); }

/* --- Date Tabs --- */
.date-tabs-wrapper {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 8px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.date-tabs {
  display: flex;
  gap: 8px;
  min-width: max-content;
}

.date-tab {
  padding: 8px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  min-height: 40px;
}

.date-tab:hover { border-color: var(--primary); color: var(--primary); }

.date-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* --- Sections --- */
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-700);
  padding: 16px 16px 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recheck-title { color: var(--amber); }

.table-section {
  padding-bottom: 80px;
}

/* --- Table --- */
.table-wrapper {
  overflow-x: auto;
  padding: 0 16px;
  -webkit-overflow-scrolling: touch;
}

.item-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.item-table thead {
  background: var(--gray-100);
}

.item-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-700);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  border-bottom: 2px solid var(--gray-200);
}

.item-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.item-table tbody tr:hover {
  background: var(--gray-50);
}

.item-table tbody tr.row-exit {
  opacity: 0;
  transition: opacity 0.3s;
}

.recheck-table tbody tr {
  background: var(--amber-light);
}

.recheck-table tbody tr:hover {
  background: #fde68a;
}

.recheck-row {
  background: var(--amber-light);
}

.td-desc {
  max-width: 250px;
  word-break: break-word;
}

.td-qty {
  font-weight: 700;
  font-size: 15px;
}

.rack-badge {
  display: inline-block;
  font-weight: 700;
  color: var(--primary);
  background: #eff6ff;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 13px;
}

.cycle-badge {
  display: inline-block;
  background: var(--gray-100);
  color: var(--gray-700);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-ok {
  background: #d1fae5;
  color: #065f46;
}

.status-recheck {
  background: #fef2f2;
  color: #dc2626;
  font-weight: 700;
}

.status-saving {
  background: #dbeafe;
  color: #1e40af;
}

.row-saved {
  animation: flashGreen 1.5s ease-out;
}

@keyframes flashGreen {
  0% { background: #d1fae5; }
  100% { background: transparent; }
}

.qty-input {
  width: 80px;
  padding: 8px 10px;
  border: 2px solid var(--gray-200);
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
  min-height: 40px;
}

.qty-input:focus { border-color: var(--primary); }

.submit-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
  white-space: nowrap;
}

.submit-btn:hover { background: var(--primary-dark); }
.submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.final-submit-btn {
  background: var(--amber);
}

.final-submit-btn:hover { background: #d97706; }

/* --- Loading --- */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--gray-500);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Empty State --- */
.empty-state {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--gray-500);
  text-align: center;
}

.empty-state p { margin-top: 12px; font-size: 15px; }

/* --- Chat FAB --- */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  z-index: 200;
}

.chat-fab:hover { transform: scale(1.1); }

/* --- Chat Modal --- */
.chat-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}

.chat-modal-content {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--gray-200);
}

.chat-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.chat-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--gray-500);
  cursor: pointer;
  padding: 4px 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.bot {
  background: var(--gray-100);
  color: var(--gray-700);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-200);
}

.chat-input-area input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  min-height: 44px;
}

.chat-input-area input:focus { border-color: var(--primary); }

.chat-send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-send-btn:disabled { opacity: 0.5; }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 400;
  animation: toastIn 0.2s ease-out;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--error); color: white; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* --- Admin Link in Header --- */
.admin-link {
  font-size: 13px;
  color: white;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--primary);
  font-weight: 600;
  transition: background 0.15s;
}

.admin-link:hover {
  background: var(--primary-dark);
}

.back-link {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--primary);
  font-weight: 500;
  transition: all 0.15s;
}

.back-link:hover {
  background: var(--primary);
  color: white;
}

/* --- Admin Panel --- */
.admin-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 16px;
  padding: 20px;
}

.admin-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 16px;
}

.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.admin-card-header .admin-card-title {
  margin-bottom: 0;
}

.user-count {
  font-size: 13px;
  color: var(--gray-500);
  font-weight: 500;
}

/* --- Add User Form --- */
.add-user-form .form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-group {
  flex: 1;
  min-width: 150px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  color: var(--gray-900);
  min-height: 44px;
  outline: none;
  background: white;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
}

.add-btn {
  padding: 10px 24px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  transition: background 0.15s;
}

.add-btn:hover {
  background: #15803d;
}

/* --- Admin Table --- */
.admin-table .td-email {
  font-size: 13px;
  color: var(--gray-500);
}

.admin-table .td-date {
  font-size: 13px;
  color: var(--gray-500);
  white-space: nowrap;
}

.role-select {
  padding: 6px 10px;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  background: white;
  min-height: 34px;
}

.role-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.role-select.badge-admin {
  color: var(--primary);
  border-color: #bfdbfe;
  background: #eff6ff;
}

.role-select.badge-user {
  color: var(--gray-700);
  border-color: var(--gray-200);
  background: var(--gray-50);
}

.status-toggle {
  padding: 6px 14px;
  border: none;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 30px;
}

.status-toggle:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-toggle.badge-active {
  background: #d1fae5;
  color: #065f46;
}

.status-toggle.badge-active:hover:not(:disabled) {
  background: #fef2f2;
  color: var(--error);
}

.status-toggle.badge-inactive {
  background: #fef2f2;
  color: var(--error);
}

.status-toggle.badge-inactive:hover:not(:disabled) {
  background: #d1fae5;
  color: #065f46;
}

.delete-btn {
  padding: 6px 14px;
  border: 1px solid var(--error);
  border-radius: 6px;
  background: white;
  color: var(--error);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 34px;
}

.delete-btn:hover:not(:disabled) {
  background: var(--error);
  color: white;
}

.delete-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* --- Tablet / Desktop --- */
@media (min-width: 768px) {
  .chat-modal { align-items: center; }

  .chat-modal-content {
    border-radius: 16px;
    max-height: 60vh;
  }
}
