/* ═══════════════════════════════════════════════════════════════════
   Store Locator Admin — Premium Dark SaaS Theme
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #1e2130;
  --bg-hover: #262a3a;
  --bg-input: #151822;
  --border: #2a2e3f;
  --border-focus: #6366f1;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --sidebar-width: 260px;
  --transition: all 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── LOGIN PAGE ─────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0f1117 0%, #1a1035 50%, #0f1117 100%);
}

.login-bg-shapes { position: absolute; inset: 0; pointer-events: none; }

.shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: float 8s ease-in-out infinite;
}
.shape-1 { width: 400px; height: 400px; background: #6366f1; top: -100px; right: -100px; }
.shape-2 { width: 300px; height: 300px; background: #8b5cf6; bottom: -50px; left: -50px; animation-delay: -3s; }
.shape-3 { width: 200px; height: 200px; background: #3b82f6; top: 50%; left: 50%; animation-delay: -5s; }

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-30px) scale(1.05); }
}

.login-container { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 20px; }

.login-card {
  background: rgba(30, 33, 48, 0.7);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: 20px;
  padding: 48px 36px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  font-size: 28px; color: white;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}
.login-header h1 { font-size: 1.5rem; font-weight: 700; }
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }

.login-form .form-group { margin-bottom: 20px; }
.login-form label {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; font-weight: 500; color: var(--text-secondary);
  margin-bottom: 8px;
}
.login-form label i { font-size: 0.8rem; color: var(--accent); }

.login-form input {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 0.95rem; transition: var(--transition);
  font-family: inherit;
}
.login-form input:focus {
  outline: none; border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.login-form input::placeholder { color: var(--text-muted); }

.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 44px; }
.toggle-password {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.9rem; transition: var(--transition);
}
.toggle-password:hover { color: var(--accent); }

.btn-login {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none; border-radius: var(--radius-sm);
  color: white; font-size: 1rem; font-weight: 600;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 8px;
  transition: var(--transition); font-family: inherit;
}
.btn-login:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.login-footer { text-align: center; margin-top: 24px; color: var(--text-muted); font-size: 0.8rem; }

/* ── ALERTS ─────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px;
  font-size: 0.9rem; margin-bottom: 20px;
}
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3); color: #fca5a5; }
.alert-success { background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.3); color: #6ee7b7; }

/* ── APP LAYOUT ─────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width); background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; transition: var(--transition);
}

.sidebar-header {
  padding: 20px; display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.05rem;
}
.sidebar-logo i {
  color: var(--accent); font-size: 1.2rem;
}
.sidebar-toggle {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 1.1rem; display: none;
}

.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none;
  font-size: 0.9rem; font-weight: 500; transition: var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: rgba(99, 102, 241, 0.12); color: var(--accent);
}
.nav-item i { width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; margin-bottom: 8px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 0.85rem;
}
.user-info { display: flex; flex-direction: column; overflow: hidden; }
.user-email { font-size: 0.78rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: capitalize; }

.logout-btn:hover { color: var(--danger) !important; }

/* ── MAIN CONTENT ───────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  max-width: calc(100vw - var(--sidebar-width));
  min-width: 0;        /* critical: prevents flex child from blowing past viewport */
  width: 0;            /* force flex to compress; flex:1 handles the actual sizing */
  overflow-x: hidden;  /* clip at this boundary so inner containers can scroll */
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 32px; flex-wrap: wrap; gap: 16px;
}
.page-header h1 { font-size: 1.75rem; font-weight: 700; }
.page-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }

/* ── BUTTONS ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  border: none; text-decoration: none; transition: var(--transition);
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }

.btn-secondary { background: var(--bg-hover); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; transition: var(--transition);
  font-size: 0.8rem; background: transparent;
}
.btn-edit { color: var(--accent); }
.btn-edit:hover { background: rgba(99, 102, 241, 0.15); }
.btn-delete { color: var(--danger); }
.btn-delete:hover { background: rgba(239, 68, 68, 0.15); }

/* ── STATS CARDS ────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px; margin-bottom: 40px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  display: flex; align-items: center; gap: 16px;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }

.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: white; flex-shrink: 0;
}
.stat-value { font-size: 1.5rem; font-weight: 700; display: block; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* ── QUICK ACTIONS ──────────────────────────────────────────────── */
.quick-actions h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 16px; }
.actions-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.action-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  text-decoration: none; color: var(--text-primary);
  transition: var(--transition);
}
.action-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.action-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(99, 102, 241, 0.12);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 1.1rem; margin-bottom: 12px;
}
.action-card h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; }
.action-card p { font-size: 0.8rem; color: var(--text-muted); }

/* ── SEARCH BAR ─────────────────────────────────────────────────── */
.search-bar { margin-bottom: 24px; }
.search-form { display: flex; gap: 12px; align-items: center; }
.search-input-wrapper {
  flex: 1; position: relative;
}
.search-input-wrapper i {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 0.9rem;
}
.search-input-wrapper input {
  width: 100%; padding: 10px 16px 10px 40px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 0.9rem; transition: var(--transition); font-family: inherit;
}
.search-input-wrapper input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── DATA TABLE ─────────────────────────────────────────────────── */
.table-container {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;        /* horizontal scroll lives HERE */
  -webkit-overflow-scrolling: touch; /* smooth momentum scroll on iOS */
  width: 100%;             /* fill available column width */
}
.data-table { width: 100%; min-width: 700px; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  text-align: left; padding: 14px 16px;
  background: var(--bg-secondary); color: var(--text-muted);
  font-weight: 600; font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.data-table tbody tr { transition: var(--transition); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.td-id { color: var(--text-muted); font-size: 0.8rem; }
.td-name { font-weight: 500; }
.td-coord { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.8rem; color: var(--text-secondary); }
.td-actions { white-space: nowrap; }

/* ── SORTABLE COLUMN HEADERS ────────────────────────────────────── */
.th-sortable { padding: 0 !important; }
.sort-link {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 16px;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}
.sort-link:hover { color: var(--text-primary); }
.sort-link.sort-active { color: var(--accent); }
.sort-icon { font-size: 0.65rem; flex-shrink: 0; }
.sort-icon--inactive { opacity: 0.3; }

.empty-state {
  text-align: center !important; padding: 48px 16px !important;
  color: var(--text-muted);
}
.empty-state i { font-size: 2rem; margin-bottom: 12px; display: block; }

/* ── PAGINATION ─────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; margin-top: 24px;
}
.page-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-secondary); text-decoration: none;
  font-size: 0.85rem; transition: var(--transition);
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ── FORM CONTAINER ─────────────────────────────────────────────── */
.form-container {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px;
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px; margin-bottom: 32px;
}

.record-form .form-group, .settings-form .form-group { margin-bottom: 20px; }
.record-form label, .settings-form label {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; font-weight: 500; color: var(--text-secondary);
  margin-bottom: 8px;
}
.record-form label i, .settings-form label i { color: var(--accent); font-size: 0.8rem; }
.field-type {
  font-size: 0.7rem; color: var(--text-muted);
  background: var(--bg-hover); padding: 2px 6px;
  border-radius: 4px; margin-left: auto;
}

.record-form input, .record-form textarea,
.settings-form input, .settings-form textarea {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 0.9rem; transition: var(--transition); font-family: inherit;
}
.record-form input:focus, .record-form textarea:focus,
.settings-form input:focus, .settings-form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}
.record-form textarea { resize: vertical; }

.form-actions {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 12px; padding-top: 20px; border-top: 1px solid var(--border);
}
.form-hint { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 6px; }

/* ── SETTINGS ───────────────────────────────────────────────────── */
.settings-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px;
}
.settings-card-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.settings-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #00a1e0, #0070d2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: white; flex-shrink: 0;
}
.settings-card-header h2 { font-size: 1.1rem; font-weight: 600; }
.settings-card-header p { font-size: 0.85rem; color: var(--text-secondary); margin-top: 2px; }

/* ── MODAL ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); width: 90%; max-width: 480px;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5);
}
.modal-header { padding: 24px 24px 0; }
.modal-header h2 { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.modal-body { padding: 20px 24px; color: var(--text-secondary); font-size: 0.9rem; }
.modal-footer { padding: 0 24px 24px; display: flex; justify-content: flex-end; gap: 10px; }

/* ── SPINNER ────────────────────────────────────────────────────── */
.sync-progress { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px 0; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RESPONSIVE ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }

  /* Sidebar overlay — tapping outside closes it */
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }
  .sidebar-overlay.visible { display: block; }

  .main-content {
    margin-left: 0;
    padding: 16px;
    max-width: 100vw;   /* full viewport on mobile */
    overflow-x: hidden;
  }

  .search-form {
    flex-wrap: wrap;
  }
  .search-input-wrapper {
    width: 100%;
    flex: none;
  }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }

  /* Table scrolls horizontally inside its container */
  .table-container {
    border-radius: var(--radius-sm);
  }
}
