/* ═══════════════════════════════════════════════
   fessable — Design System
   Clean, warm, mobile-first
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #FAFAF9;
  --surface: #F4F4F5;
  --card: #FFFFFF;
  --text: #18181B;
  --text-2: #71717A;
  --text-3: #A1A1AA;
  --border: #E4E4E7;
  --accent: #18181B;
  --green: #16A34A;
  --green-bg: #F0FDF4;
  --red: #DC2626;
  --red-bg: #FEF2F2;
  --amber: #D97706;
  --amber-bg: #FFFBEB;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
}

/* ── Dark Mode ── */
.dark {
  --bg: #0A0A0B;
  --surface: #18181B;
  --card: #1C1C1F;
  --text: #FAFAFA;
  --text-2: #A1A1AA;
  --text-3: #71717A;
  --border: #27272A;
  --accent: #FAFAFA;
  --green: #4ADE80;
  --green-bg: #052E16;
  --red: #F87171;
  --red-bg: #450A0A;
  --amber: #FBBF24;
  --amber-bg: #451A03;
}
.dark body,
.dark { color: #FAFAFA; }
.dark .topbar { border-color: #27272A; background: #0A0A0B; }
.dark .topbar-left .wordmark { color: #FAFAFA; }
.dark .card { background: #1C1C1F; border-color: #27272A; }
.dark p { color: #A1A1AA; }
.dark h1, .dark h2 { color: #FAFAFA; }
.dark .spinner { border-color: #27272A; border-top-color: #FAFAFA; }
.dark .spinner-lg { border-color: #27272A; border-top-color: #FAFAFA; }
.dark .loading-overlay { background: rgba(10,10,11,0.9); }
.dark .loading-overlay .loading-text { color: #FAFAFA; }
.dark .lightbox { background: rgba(0,0,0,0.98); }
.dark .lightbox .lb-close,
.dark .lightbox .lb-nav { background: rgba(255,255,255,0.15); color: #fff; }
.dark .lightbox .lb-close:hover,
.dark .lightbox .lb-nav:hover { background: rgba(255,255,255,0.25); }
.dark input[type="text"],
.dark input[type="password"],
.dark input[type="number"],
.dark input[type="search"],
.dark textarea,
.dark select {
  background: #27272A;
  border-color: #3F3F46;
  color: #FAFAFA;
}
.dark input:focus,
.dark textarea:focus {
  border-color: #FAFAFA;
}
.dark input::placeholder,
.dark textarea::placeholder {
  color: #71717A;
}
.dark label { color: #A1A1AA; }
.dark .btn-secondary {
  background: #27272A;
  border-color: #3F3F46;
  color: #FAFAFA;
}
.dark .btn-primary {
  background: #FAFAFA;
  color: #0A0A0B;
}
.dark .btn-secondary:hover:not(:disabled) {
  border-color: #52525B;
}
.dark .btn-ghost { color: #A1A1AA; }
.dark .btn-ghost:hover:not(:disabled) {
  background: #27272A;
  color: #FAFAFA;
}
.dark .badge-active { background: #052E16; color: #4ADE80; }
.dark .badge-inactive { background: #450A0A; color: #F87171; }
.dark .badge-pending { background: #451A03; color: #FBBF24; }
.dark .badge-approved { background: #052E16; color: #4ADE80; }
.dark .badge-rejected { background: #450A0A; color: #F87171; }
.dark .status-dot.online { background: #4ADE80; }
.dark .status-dot.offline { background: #F87171; }
.dark .toggle-track { background: #3F3F46; }
.dark .toggle-track::before { background: #FAFAFA; }
.dark .toggle input:checked + .toggle-track { background: #4ADE80; }
.dark .empty-state { color: #71717A; }
.dark .sheet-overlay { background: rgba(0,0,0,0.7); }
.dark .sheet-card,
.dark .popup-sheet { background: #1C1C1F; border-color: #27272A; }
.dark .popup-sheet { border-top-color: #27272A; }
.dark .popup-btn-ghost { background: #3F3F46; color: #FAFAFA; }
.dark a { color: inherit; }

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

/* ── Typography ── */
h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
p { color: var(--text-2); }

/* ── Layout ── */
.container {
  width: 100%;
  max-width: 480px;
  padding: 16px;
  flex: 1;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  width: 100%;
  max-width: 480px;
  border-bottom: 1px solid var(--border);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-left .wordmark {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.topbar-left svg {
  flex-shrink: 0;
}

/* ── Card ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* ── Inputs (16px to prevent iOS zoom) ── */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
textarea,
select {
  font-size: 16px !important;
}

input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
input:focus {
  border-color: var(--accent);
}
input::placeholder {
  color: var(--text-3);
}

textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  resize: none;
  line-height: 1.5;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
textarea:focus {
  border-color: var(--accent);
}
textarea::placeholder {
  color: var(--text-3);
}

/* ── Labels ── */
label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--text);
  color: var(--card);
}
.btn-primary:hover:not(:disabled) {
  opacity: 0.85;
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-3);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  opacity: 0.85;
}

.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  opacity: 0.85;
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.8125rem;
}

.btn-xs {
  padding: 5px 12px;
  font-size: 0.75rem;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
}
.badge-active {
  background: var(--green-bg);
  color: var(--green);
}
.badge-inactive {
  background: var(--red-bg);
  color: var(--red);
}
.badge-pending {
  background: var(--amber-bg);
  color: var(--amber);
}
.badge-approved {
  background: var(--green-bg);
  color: var(--green);
}
.badge-rejected {
  background: var(--red-bg);
  color: var(--red);
}

/* ── Status dot ── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }

/* ── Toggle switch ── */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  display: inline-block;
  cursor: pointer;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-track::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.toggle input:checked + .toggle-track {
  background: var(--green);
}
.toggle input:checked + .toggle-track::before {
  transform: translateX(20px);
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
  font-size: 0.875rem;
}

/* ── Utility ── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-2); }
.text-hint { color: var(--text-3); }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }

/* ── Bottom Sheet ── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s;
}
.sheet-overlay.hidden {
  display: none;
}
.sheet-card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 24px 16px 32px;
  animation: slideUp 0.25s ease;
  max-height: 85vh;
  overflow-y: auto;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox.hidden { display: none; }
.lightbox img {
  max-width: 95%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox .lb-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox .lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox .lb-nav.prev { left: 16px; }
.lightbox .lb-nav.next { right: 16px; }
.lightbox .lb-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: rgba(255,255,255,0.8);
  font-size: 0.8125rem;
  padding: 4px 12px;
  border-radius: var(--radius-full);
}
.lightbox.hidden { display: none; }

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(250,250,249,0.9);
  backdrop-filter: blur(8px);
}
.loading-overlay.hidden { display: none; }
.loading-overlay .loading-text {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}
.loading-overlay .progress-track {
  width: 60%;
  height: 3px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.loading-overlay .progress-bar {
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 0.3s;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .container {
    padding: 12px;
  }
}

/* ── Safe area (iOS) ── */
@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── Hide file input ── */
input[type="file"],
input[type="file"][id],
#fileInput {
  position: absolute !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  clip: rect(0,0,0,0) !important;
}

/* ── Theme toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-2);
  font-size: 1.125rem;
  transition: all 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--text-3);
  color: var(--text);
}
.dark .theme-toggle {
  border-color: #3F3F46;
  color: #A1A1AA;
}
.dark .theme-toggle:hover {
  border-color: #52525B;
  color: #FAFAFA;
}
