/* ═════════════════════════════════════════════════════════════════════
   Cloudflare Site Manager — Design System
   ═════════════════════════════════════════════════════════════════════ */

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

:root {
  /* Surface */
  --bg-body:     #0d1117;
  --bg-card:     #161b22;
  --bg-card-hover: #1c2333;
  --bg-modal:    #161b22;
  --bg-input:    #0d1117;
  --bg-toolbar:  #161b22;
  --bg-header:   #0d1117;

  /* Borders */
  --border:      #30363d;
  --border-card: #21262d;

  /* Text */
  --text:        #e6edf3;
  --text-dim:    #8b949e;
  --text-muted:  #6e7681;

  /* Accent */
  --accent:      #3b82f6;
  --accent-bg:   rgba(59, 130, 246, 0.12);
  --accent-text: #3b82f6;

  /* Status */
  --green:       #3fb950;
  --green-bg:    rgba(63, 185, 80, 0.12);
  --red:         #f85149;
  --red-bg:      rgba(248, 81, 73, 0.12);
  --yellow:      #d29922;
  --yellow-bg:   rgba(210, 153, 34, 0.12);
  --blue:        #58a6ff;
  --blue-bg:     rgba(88, 166, 255, 0.12);

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(0,0,0,.3);
  --shadow-modal: 0 8px 40px rgba(0,0,0,.6);

  /* Radius */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

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

/* ── Light Theme ───────────────────────────────────────────────────── */
:root[data-theme="light"] {
  --bg-body:     #f6f8fa;
  --bg-card:     #ffffff;
  --bg-card-hover: #f0f4f8;
  --bg-modal:    #ffffff;
  --bg-input:    #f6f8fa;
  --bg-toolbar:  #ffffff;
  --bg-header:   #ffffff;

  --border:      #d0d7de;
  --border-card: #d8dee4;

  --text:        #1f2328;
  --text-dim:    #656d76;
  --text-muted:  #8b949e;

  --shadow-card: 0 1px 3px rgba(31,35,40,.08);
  --shadow-modal: 0 8px 40px rgba(0,0,0,.15);

  --accent-bg: rgba(59, 130, 246, 0.1);
  --green-bg:  rgba(38, 166, 65, 0.1);
  --red-bg:    rgba(207, 34, 46, 0.1);
  --yellow-bg: rgba(191, 135, 0, 0.1);
  --blue-bg:   rgba(9, 105, 218, 0.1);
}

/* ── Base ───────────────────────────────────────────────────────────── */
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background: var(--bg-body);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--normal) var(--ease), color var(--normal) var(--ease);
}

/* ── Header ─────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--normal) var(--ease);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
  flex-shrink: 0;
}
.logo-icon svg { width: 100%; height: 100%; }

.header-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.accent { color: var(--accent); font-weight: 700; }

.header-subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: -1px;
}

.header-actions {
  display: flex;
  gap: 6px;
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--fast) var(--ease);
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
  border-color: var(--border);
}
.btn-icon:hover { background: var(--bg-card-hover); }
.btn-icon svg { width: 18px; height: 18px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-outline {
  border-color: var(--border);
  background: transparent;
}
.btn-outline:hover { background: var(--bg-card-hover); }

.btn-purge {
  background: var(--red-bg);
  color: var(--red);
  border-color: transparent;
  font-weight: 600;
}
.btn-purge:hover { background: var(--red); color: #fff; }

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
}

.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  font-weight: 600;
}

/* ── Theme Icons ────────────────────────────────────────────────────── */
[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: block; }

/* ── Toolbar ────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 73px; /* header height */
  z-index: 90;
  flex-wrap: wrap;
  transition: background var(--normal) var(--ease);
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 420px;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--fast) var(--ease), background var(--normal) var(--ease);
  outline: none;
}
.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.search-box input::placeholder { color: var(--text-muted); }

.stats-pills {
  display: flex;
  gap: 8px;
}

.pill {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.pill-active {
  color: var(--green);
  background: var(--green-bg);
  border-color: transparent;
}
.pill-healthy {
  color: var(--green);
  background: var(--green-bg);
  border-color: transparent;
}
.pill-down {
  color: var(--red);
  background: var(--red-bg);
  border-color: transparent;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Loading ────────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 20px;
  gap: 16px;
  color: var(--text-dim);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error ──────────────────────────────────────────────────────────── */
.error-state {
  display: flex;
  justify-content: center;
  padding: 80px 20px;
}
.error-card {
  text-align: center;
  max-width: 400px;
  padding: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.error-card svg { width: 48px; height: 48px; color: var(--red); margin-bottom: 16px; }
.error-card h2 { font-size: 1.1rem; margin-bottom: 6px; }
.error-card p { color: var(--text-dim); margin-bottom: 20px; font-size: 0.9rem; }

/* ── Empty ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h2 { font-size: 1.1rem; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.9rem; }

/* ── Sites Grid ─────────────────────────────────────────────────────── */
.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  padding: 20px 28px 40px;
}

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

/* ── Site Card ──────────────────────────────────────────────────────── */
.site-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all var(--normal) var(--ease);
  box-shadow: var(--shadow-card);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.site-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-domain {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  line-height: 1.3;
}

.card-status {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  border-radius: 20px;
}
.status-active { background: var(--green-bg); color: var(--green); }
.status-pending { background: var(--yellow-bg); color: var(--yellow); }
.status-moved { background: var(--blue-bg); color: var(--blue); }
.status-initializing { background: var(--yellow-bg); color: var(--yellow); }
.status-paused { background: var(--red-bg); color: var(--red); }
.status-deactivated { background: var(--red-bg); color: var(--red); }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.card-meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.card-meta-item svg { width: 14px; height: 14px; flex-shrink: 0; }

.card-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}

.card-actions .btn-sm {
  padding: 6px 4px;
  font-size: 0.76rem;
  min-width: 0;
  white-space: nowrap;
}

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s var(--ease);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  animation: slideUp 0.25s var(--ease);
  transition: max-width 0.2s var(--ease), max-height 0.2s var(--ease);
}

/* Modo tela cheia */
.modal.modal-fullscreen {
  max-width: 96vw;
  max-height: 94vh;
}
.modal.modal-fullscreen .modal-body {
  padding: 32px;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ── Modal Detail Sections ──────────────────────────────────────────── */
.detail-section {
  margin-bottom: 20px;
}
.detail-section:last-child { margin-bottom: 0; }

.detail-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 20px;
}
@media (max-width: 500px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.detail-label { color: var(--text-dim); font-weight: 500; white-space: nowrap; }
.detail-value { color: var(--text); text-align: right; word-break: break-all; }

.detail-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.cache-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
@media (max-width: 500px) { .cache-stats-grid { grid-template-columns: 1fr 1fr; } }

.cache-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  transition: background var(--normal) var(--ease);
}
.cache-stat-number {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.1;
}
.cache-stat-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow-modal);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 400px;
  animation: slideIn 0.3s var(--ease);
}

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

.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--blue); }

.toast svg { width: 20px; height: 20px; flex-shrink: 0; }
.toast-success svg { color: var(--green); }
.toast-error svg { color: var(--red); }
.toast-info svg { color: var(--blue); }

/* ── Filters Bar ─────────────────────────────────────────────────────── */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 28px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  transition: background var(--normal) var(--ease);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
}

.filter-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: all var(--fast) var(--ease);
  font-family: inherit;
  white-space: nowrap;
}
.filter-chip:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}
.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

@media (max-width: 700px) {
  .filters-bar {
    gap: 10px;
    padding: 10px 16px;
  }
  .filter-group {
    gap: 4px;
  }
  .filter-chip {
    padding: 3px 9px;
    font-size: 0.73rem;
  }
}

/* ── Utility ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
