/* =========================================================
   PhilGEPS Scraper – Dark Government Dashboard
   ========================================================= */

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg-900:   #0d0f14;
  --bg-800:   #151921;
  --bg-700:   #1c2230;
  --bg-600:   #242d3e;
  --bg-500:   #2d3a50;

  --border:   #2d3a50;
  --border-lt: #374560;

  --text:     #e2e8f0;
  --text-muted: #8896b0;
  --text-dim:   #556280;

  --accent:   #3b82f6;
  --accent-hover: #2563eb;

  --green:    #22c55e;
  --green-bg: rgba(34,197,94,.12);
  --yellow:   #eab308;
  --yellow-bg: rgba(234,179,8,.12);
  --red:      #ef4444;
  --red-bg:   rgba(239,68,68,.12);
  --blue:     #60a5fa;
  --blue-bg:  rgba(96,165,250,.12);
  --gray:     #94a3b8;
  --gray-bg:  rgba(148,163,184,.12);

  --radius:   8px;
  --radius-lg: 12px;
  --shadow:   0 2px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);

  --nav-w:    220px;
  --nav-h:    56px;
}

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

html { font-size: 15px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-900);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg-800);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.nav-logo {
  font-size: 1.4rem;
  color: var(--accent);
}

.nav-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
  margin-left: auto;
  align-items: center;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--bg-600);
  color: var(--text);
  text-decoration: none;
}

.nav-links a.nav-logout:hover {
  background: var(--red-bg);
  color: var(--red);
}

.nav-icon { font-size: 0.9rem; }
.nav-sep { width: 1px; height: 24px; background: var(--border); margin: 0 0.25rem; }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  margin-left: auto;
}

/* ── Page Wrapper ───────────────────────────────────────── */
.page-wrapper {
  padding: calc(var(--nav-h) + 1.5rem) 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Flash Messages ─────────────────────────────────────── */
.flash-container { margin-bottom: 1rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}
.flash-info    { background: var(--blue-bg); border: 1px solid var(--blue); color: var(--blue); }
.flash-success { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.flash-error   { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }

/* ── Alerts (inline) ────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
}
.alert-error   { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }
.alert-success { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }

/* ── Toast ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.25s ease;
  max-width: 360px;
}
.toast-success { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.toast-error   { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }
.toast-info    { background: var(--blue-bg); border: 1px solid var(--blue); color: var(--blue); }

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

/* ── Page Header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.page-meta {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.page-actions { display: flex; gap: 0.5rem; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  line-height: 1;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  text-decoration: none;
  color: #fff;
}

.btn-ghost {
  background: var(--bg-600);
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-500);
  color: var(--text);
  text-decoration: none;
}

.btn-full { width: 100%; justify-content: center; }
.btn-sm   { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* ── Health Bar ─────────────────────────────────────────── */
.health-bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.health-item  { display: flex; align-items: center; gap: 0.5rem; }
.health-label { font-size: 0.8rem; color: var(--text-muted); }
.health-sep   { flex: 1; }

.health-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-ok      { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-fail    { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.dot-unknown { background: var(--gray); }

/* ── Toggle Switch ──────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-500);
  border-radius: 20px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Scrape Banner ──────────────────────────────────────── */
.scrape-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--yellow-bg);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  color: var(--yellow);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stats Grid ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.stat-card:hover { border-color: var(--border-lt); }

.stat-icon { font-size: 1.75rem; line-height: 1; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }

.stat-green { border-left: 3px solid var(--green); }
.stat-yellow { border-left: 3px solid var(--yellow); }
.stat-red { border-left: 3px solid var(--red); }
.stat-blue { border-left: 3px solid var(--blue); }
.stat-gray { border-left: 3px solid var(--gray); }

/* ── Timing Row ─────────────────────────────────────────── */
.timing-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.timing-card {
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.timing-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.timing-value { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Section ─────────────────────────────────────────────── */
.section { margin-bottom: 1.5rem; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-title { font-size: 1rem; font-weight: 600; }

.alerts-list {
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.alert-item {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }
.alert-item.alert-error { background: var(--red-bg); color: var(--red); }

.alert-time { color: var(--text-dim); white-space: nowrap; }
.alert-msg  { flex: 1; }

.empty-state {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.875rem;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem;
}

.filter-tab {
  padding: 0.35rem 0.85rem;
  border-radius: 5px;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.filter-tab:hover { color: var(--text); text-decoration: none; }
.filter-tab.active {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.search-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.search-input {
  padding: 0.4rem 0.75rem;
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  width: 240px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* ── Table ──────────────────────────────────────────────── */
.table-wrapper {
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  margin-bottom: 1rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table thead { background: var(--bg-700); }
.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-700); }

.td-num   { color: var(--text-dim); text-align: right; }
.td-name  { max-width: 280px; }
.td-ref   { font-family: monospace; font-size: 0.8rem; color: var(--text-muted); }
.td-date  { white-space: nowrap; color: var(--text-muted); font-size: 0.8rem; }
.td-notes { max-width: 240px; color: var(--text-muted); }
.td-empty { text-align: center; color: var(--text-dim); padding: 2rem; }

.project-link { color: var(--text); }
.project-link:hover { color: var(--accent); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red    { background: var(--red-bg); color: var(--red); }
.badge-blue   { background: var(--blue-bg); color: var(--blue); }
.badge-gray   { background: var(--gray-bg); color: var(--gray); }

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.page-btn {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  background: var(--bg-800);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: background 0.15s;
}
.page-btn:hover { background: var(--bg-600); color: var(--text); text-decoration: none; }
.page-active { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; }
.page-ellipsis { color: var(--text-dim); padding: 0 0.25rem; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-700);
}

.card-title { font-size: 0.95rem; font-weight: 600; }

.card-body { padding: 1.25rem; }

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── Setup page misc ────────────────────────────────────── */
.setup-steps {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.setup-steps li strong { color: var(--text); }

.code-block {
  display: block;
  background: var(--bg-900);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--text-muted);
  white-space: pre;
}

.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.link { color: var(--accent); }

/* ── Login Page ─────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-800);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-header { text-align: center; margin-bottom: 2rem; }
.login-logo { font-size: 3rem; line-height: 1; margin-bottom: 0.5rem; color: var(--accent); }
.login-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-subtitle { font-size: 0.8rem; color: var(--text-muted); }

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-footer { margin-top: 1.5rem; text-align: center; font-size: 0.75rem; color: var(--text-dim); }

/* ── Form Elements ──────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }

.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }

.form-input {
  padding: 0.6rem 0.85rem;
  background: var(--bg-700);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-dim); }

.input-group { position: relative; display: flex; }
.input-group .form-input { padding-right: 2.5rem; }
.input-toggle {
  position: absolute;
  right: 0;
  top: 0; bottom: 0;
  width: 2.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { flex-wrap: wrap; height: auto; padding: 0.75rem 1rem; }

  .nav-toggle { display: block; }

  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    padding-bottom: 0.5rem;
    margin-left: 0;
    gap: 0.15rem;
  }
  .nav-links.open { display: flex; }
  .nav-sep { display: none; }

  .page-wrapper { padding-top: 4rem; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .timing-row { grid-template-columns: 1fr; }
  .setup-grid { grid-template-columns: 1fr; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .search-form { margin-left: 0; }
  .search-input { width: 100%; }

  .table-wrapper { border-radius: var(--radius); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
