/* =====================================================
   WeatherGrid Maintenance App — Design System
   ===================================================== */

/* --- Tokens --- */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Gray scale */
  --gray-50: #fafafa;
  --gray-100: #f4f4f5;
  --gray-200: #e4e4e7;
  --gray-300: #d4d4d8;
  --gray-400: #a1a1aa;
  --gray-500: #71717a;
  --gray-600: #52525b;
  --gray-700: #3f3f46;
  --gray-800: #27272a;
  --gray-900: #18181b;

  /* Primary */
  --blue-500: #2563eb;
  --blue-100: #dbeafe;
  --blue-ring: rgba(37,99,235,0.12);

  /* Status: Working */
  --green-50: #f0fdf4;
  --green-600: #15803d;
  --green-200: #bbf7d0;
  --green-500: #22c55e;

  /* Status: Needs Repair */
  --orange-50: #fff7ed;
  --orange-600: #ea580c;
  --orange-700: #c2410c;
  --orange-800: #9a3412;
  --orange-900: #7c2d12;
  --orange-200: #fed7aa;

  /* Status: Replaced */
  --blue-50: #eff6ff;
  --blue-700: #1d4ed8;
  --blue-200: #bfdbfe;

  /* Danger */
  --red-500: #ef4444;

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;
  --r-pill: 999px;
  --r-phone: 44px;

  /* Shadows */
  --shadow-phone: 0 30px 80px -20px rgba(24,24,27,0.35), 0 10px 30px -10px rgba(24,24,27,0.2);
  --shadow-card: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-dropdown: 0 8px 24px -4px rgba(24,24,27,0.14), 0 2px 8px -2px rgba(24,24,27,0.08);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 150ms;
  --dur-mid: 250ms;
  --dur-slow: 350ms;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: var(--font);
  color: var(--gray-900);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--gray-100);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* --- Stage & Phone Frame --- */
.stage {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px;
  background:
    radial-gradient(circle at 20% 0%, var(--gray-200) 0%, transparent 40%),
    radial-gradient(circle at 80% 100%, var(--gray-200) 0%, transparent 40%),
    var(--gray-50);
}

.phone {
  width: 390px;
  height: 844px;
  background: #ffffff;
  border-radius: var(--r-phone);
  border: 10px solid var(--gray-900);
  box-shadow: var(--shadow-phone);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* --- Status Bar --- */
.status-bar {
  height: 44px;
  min-height: 44px;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  position: relative;
  flex-shrink: 0;
}
.notch {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 110px; height: 28px;
  background: var(--gray-900);
  border-radius: 20px;
}
.status-right { display: flex; gap: 6px; align-items: center; }

/* --- App Container --- */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* --- App Header --- */
.app-header {
  padding: 14px 20px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  width: 36px; height: 36px;
  background: var(--blue-500);
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.brand-name { font-size: 15px; font-weight: 600; color: var(--gray-900); letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--gray-500); font-weight: 500; }
.header-icons { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  border: 1px solid var(--gray-200);
  background: #ffffff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  position: relative;
  color: var(--gray-600);
  transition: background var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--gray-100); }
.icon-btn:active { transform: scale(0.95); }
.badge-dot {
  position: absolute; top: 7px; right: 7px;
  width: 8px; height: 8px;
  background: var(--red-500);
  border: 2px solid #fff;
  border-radius: 50%;
}

/* --- Scrollable Content Area --- */
.screen-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.screen-scroll::-webkit-scrollbar { width: 0; }

/* --- Context Row / Breadcrumb --- */
.context-row {
  padding: 14px 20px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
}
.breadcrumb { font-size: 12px; color: var(--gray-500); display: flex; align-items: center; gap: 6px; }
.breadcrumb strong { color: var(--gray-900); font-weight: 600; }
.breadcrumb-link { cursor: pointer; }
.breadcrumb-link:hover { color: var(--blue-500); }
.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--green-50); color: var(--green-600);
  border: 1px solid var(--green-200);
  padding: 4px 8px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 500;
}
.sync-pill .dot { width: 6px; height: 6px; background: var(--green-500); border-radius: 50%; }

/* --- Page Title --- */
.page-title-block { padding: 24px 20px 8px; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; color: var(--gray-900); margin-bottom: 4px; }
.page-desc { font-size: 13px; color: var(--gray-500); line-height: 1.5; }

/* --- Tabs --- */
.tabs {
  display: flex; gap: 4px;
  margin: 16px 20px 0;
  padding: 4px;
  background: var(--gray-100);
  border-radius: var(--r-md);
  border: 1px solid var(--gray-200);
}
.tab {
  flex: 1;
  padding: 7px 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--gray-700); }
.tab.active {
  background: #ffffff;
  color: var(--gray-900);
  box-shadow: var(--shadow-card);
}

/* --- Tab Content --- */
.tab-content {
  animation: fadeIn var(--dur-fast) var(--ease);
}

/* --- Form --- */
.form-section { padding: 24px 20px 16px; }
.field { margin-bottom: 18px; }
.field-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-900);
  margin-bottom: 6px;
}
.field-label .req { color: var(--red-500); margin-left: 2px; }
.field-hint { font-size: 11px; color: var(--gray-400); font-weight: 400; transition: color var(--dur-fast) var(--ease); }
.field-hint.hint-error { color: var(--red-500); font-weight: 500; }
.field-wrap { position: relative; }

/* --- Select / Dropdown Trigger --- */
.select {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--gray-900);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.select:hover { border-color: var(--gray-300); }
.select.placeholder { color: var(--gray-400); }
.select.focused {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--blue-ring);
}
.select .val { display: flex; align-items: center; gap: 8px; }
.select .chev { color: var(--gray-500); display: flex; align-items: center; }
.select-placeholder { color: var(--gray-400); }

.avatar-mini {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--blue-500); color: white;
  font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* --- Dropdown Panel --- */
.dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #ffffff;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-dropdown);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.dropdown-panel.dropdown-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.dropdown-option {
  padding: 9px 12px;
  font-size: 13px;
  color: var(--gray-900);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--dur-fast) var(--ease);
}
.dropdown-option:hover { background: var(--gray-50); }
.dropdown-option.dropdown-selected { background: var(--blue-100); color: var(--blue-500); font-weight: 500; }
.dropdown-emoji { font-size: 14px; line-height: 1; }
.dropdown-icon-prefix { display: flex; align-items: center; color: var(--gray-600); }

/* --- Status Segmented Control --- */
.status-group {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.status-opt {
  border: 1px solid var(--gray-200);
  background: #ffffff;
  border-radius: var(--r-md);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.status-opt:hover { background: var(--gray-50); }
.status-opt:active { transform: scale(0.97); }
.status-opt .ico {
  width: 28px; height: 28px;
  margin: 0 auto 6px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--gray-100);
  color: var(--gray-500);
  transition: all var(--dur-fast) var(--ease);
}
.status-opt .label {
  font-size: 12px; font-weight: 500; color: var(--gray-600);
  transition: all var(--dur-fast) var(--ease);
}

/* Selected status states */
.status-opt.selected[data-status="working"] {
  border-color: var(--green-200);
  background: var(--green-50);
}
.status-opt.selected[data-status="working"] .ico { background: var(--green-600); color: white; }
.status-opt.selected[data-status="working"] .label { color: var(--green-600); font-weight: 600; }

.status-opt.selected[data-status="needs_repair"] {
  border-color: var(--orange-600);
  background: var(--orange-50);
}
.status-opt.selected[data-status="needs_repair"] .ico { background: var(--orange-600); color: white; }
.status-opt.selected[data-status="needs_repair"] .label { color: var(--orange-800); font-weight: 600; }

.status-opt.selected[data-status="replaced"] {
  border-color: var(--blue-200);
  background: var(--blue-50);
}
.status-opt.selected[data-status="replaced"] .ico { background: var(--blue-700); color: white; }
.status-opt.selected[data-status="replaced"] .label { color: var(--blue-700); font-weight: 600; }

/* --- Textarea --- */
.textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--gray-900);
  min-height: 84px;
  resize: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea::placeholder { color: var(--gray-400); }
.textarea:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-ring); }
.char-count { font-size: 11px; color: var(--gray-400); margin-top: 4px; text-align: right; transition: color var(--dur-fast) var(--ease); }
.char-count.char-limit { color: var(--red-500); font-weight: 600; }

/* --- Alert Banner --- */
.alert {
  background: var(--orange-50);
  border: 1px solid var(--orange-200);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex; gap: 10px;
  margin-top: 8px;
  color: var(--orange-600);
  animation: fadeIn var(--dur-mid) var(--ease);
}
.alert svg { flex-shrink: 0; }
.alert-text { font-size: 12px; color: var(--orange-800); line-height: 1.5; }
.alert-text strong { color: var(--orange-900); }

/* --- Submit Area --- */
.submit-area {
  padding: 16px 20px 24px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.meta-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  font-size: 11px; color: var(--gray-500);
}
.meta-row .lock { display: flex; align-items: center; gap: 6px; }
.btn-primary {
  width: 100%;
  background: var(--gray-900);
  color: white;
  border: none;
  border-radius: var(--r-md);
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn-primary:hover { background: var(--gray-800); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--gray-600);
  border: none;
  padding: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 4px;
  transition: color var(--dur-fast) var(--ease);
}
.btn-secondary:hover { color: var(--gray-900); }
.btn-secondary:active { transform: scale(0.98); }

/* --- Recent Activity --- */
.recent {
  padding: 16px 20px 20px;
  background: #ffffff;
  border-top: 1px solid var(--gray-200);
}
.recent-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.recent-title { font-size: 12px; font-weight: 600; color: var(--gray-900); text-transform: uppercase; letter-spacing: 0.04em; }
.view-all { font-size: 12px; color: var(--blue-500); font-weight: 500; cursor: pointer; }
.view-all:hover { text-decoration: underline; }

.log-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
  animation: fadeSlideIn var(--dur-mid) var(--ease) both;
}
.log-item:last-child { border-bottom: none; }
.log-ico {
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  background: var(--gray-100);
  color: var(--gray-600);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.log-info { flex: 1; min-width: 0; }
.log-title { font-size: 13px; font-weight: 500; color: var(--gray-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-meta { font-size: 11px; color: var(--gray-500); margin-top: 1px; }
.log-tag {
  font-size: 10px; font-weight: 600;
  padding: 2px 6px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
  flex-shrink: 0;
}
.tag-working { background: var(--green-50); color: var(--green-600); border: 1px solid var(--green-200); }
.tag-repair { background: var(--orange-50); color: var(--orange-700); border: 1px solid var(--orange-200); }
.tag-replaced { background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--blue-200); }

/* --- Bottom Nav --- */
.bottom-nav-area {
  flex-shrink: 0;
  background: #ffffff;
}
.bottom-nav {
  display: flex;
  justify-content: space-around;
  padding: 10px 16px 6px;
  border-top: 1px solid var(--gray-200);
  background: #ffffff;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10px;
  color: var(--gray-400);
  font-weight: 500;
  cursor: pointer;
  padding: 4px 10px;
  transition: color var(--dur-fast) var(--ease);
}
.nav-item:active { transform: scale(0.95); }
.nav-item.active { color: var(--gray-900); }
.nav-item.active svg { color: var(--blue-500); }
.home-indicator {
  width: 134px; height: 5px;
  background: var(--gray-900);
  border-radius: 3px;
  margin: 6px auto 8px;
}

/* --- History Table --- */
.history-table-wrap {
  padding: 16px 20px 20px;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.history-table th {
  text-align: left;
  padding: 8px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
}
.history-table td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-900);
  font-size: 12px;
  vertical-align: middle;
}
.history-table tbody tr:last-child td { border-bottom: none; }
.hist-eq { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.hist-date { color: var(--gray-500); white-space: nowrap; font-size: 11px; }

/* --- History Empty State --- */
.history-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 20px;
  text-align: center;
}
.empty-state-icon { color: var(--gray-300); margin-bottom: 12px; }
.empty-state-text { font-size: 14px; font-weight: 600; color: var(--gray-700); margin-bottom: 4px; }
.empty-state-hint { font-size: 12px; color: var(--gray-500); }
.empty-state { padding: 24px 0; text-align: center; font-size: 13px; color: var(--gray-500); }

/* --- Login Screen --- */
.login-screen {
  flex: 1;
  padding: 0 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.login-brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 40px;
}
.login-title {
  font-size: 22px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.02em;
  margin-bottom: 6px;
  text-align: center;
}
.login-subtitle {
  font-size: 13px; color: var(--gray-500);
  margin-bottom: 28px;
  text-align: center;
}
.login-cards {
  width: 100%;
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 28px;
}
.login-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-xl);
  cursor: pointer;
  background: #ffffff;
  transition: all var(--dur-fast) var(--ease);
  animation: fadeSlideIn var(--dur-mid) var(--ease) both;
}
.login-card:hover { border-color: var(--gray-300); background: var(--gray-50); }
.login-card.selected {
  border-color: var(--blue-500);
  background: #f0f5ff;
  box-shadow: 0 0 0 3px var(--blue-ring);
}
.login-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.login-card-info { flex: 1; }
.login-card-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.login-card-role { font-size: 12px; color: var(--gray-500); margin-top: 1px; }
.login-radio {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--gray-300);
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}
.login-card.selected .login-radio {
  border-color: var(--blue-500);
  background: var(--blue-500);
}
.login-card.selected .login-radio::after {
  content: '';
  position: absolute;
  top: 4px; left: 4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: white;
}
.login-btn {
  width: 100%;
  background: var(--gray-900);
  color: white;
  border: none;
  border-radius: var(--r-md);
  padding: 13px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.login-btn:hover { background: var(--gray-800); }
.login-btn:active { transform: scale(0.98); }
.login-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* --- Toast --- */
.toast {
  margin-top: 24px;
  padding: 10px 20px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: white;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity var(--dur-mid) var(--ease), transform var(--dur-mid) var(--ease);
  box-shadow: 0 4px 16px rgba(24,24,27,0.18);
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-exit { opacity: 0; transform: translateY(-8px); }
.toast-info { background: var(--gray-800); }
.toast-success { background: #059669; }
.toast-error { background: var(--red-500); }

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

.form-animate {
  animation: slideUp var(--dur-slow) var(--ease);
}

/* Scrollbar */
.dropdown-panel::-webkit-scrollbar { width: 4px; }
.dropdown-panel::-webkit-scrollbar-track { background: transparent; }
.dropdown-panel::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
