/* ── Copilot 365 Admin Panel CSS ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

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

:root {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface2:   #243047;
  --border:     #2d3f57;
  --accent1:    #199fd7;
  --accent2:    #8a50d8;
  --text:       #f1f5f9;
  --muted:      #94a3b8;
  --success:    #22c55e;
  --warning:    #f59e0b;
  --danger:     #ef4444;
  --sidebar-w:  260px;
  --header-h:   64px;
}

html { font-size: 16px; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

a { color: var(--accent1); text-decoration: none; }
a:hover { color: var(--accent2); }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.admin-layout { display: flex; flex-direction: column; min-height: 100vh; }

/* ─── Top Nav ────────────────────────────────────────────────────────────── */
.admin-topnav {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-right: 1.75rem;
  text-decoration: none;
}

.topnav-links {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex: 1;
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(25,159,215,0.18), rgba(138,80,216,0.18));
  color: var(--text);
  font-weight: 600;
}
.nav-icon { font-size: 0.95rem; display: flex; align-items: center; }
.metric-icon { font-size: 1.6rem; margin-bottom: 0.25rem; }

/* ─── Page sub-header ────────────────────────────────────────────────────── */
.admin-header {
  height: 52px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 2rem;
  flex-shrink: 0;
}

.header-title { font-size: 1.1rem; font-weight: 700; }

.header-user { font-size: 0.875rem; color: var(--muted); }

.btn-logout {
  display: flex; align-items: center; gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Page body */
.page-body { padding: 2rem; flex: 1; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 1rem;
}

/* Metric cards */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.metric-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.metric-value { font-size: 2.2rem; font-weight: 800; color: var(--text); }
.metric-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  color: white;
}
.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent1); }

.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--muted); margin-bottom: 0.35rem; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.875rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent1);
  box-shadow: 0 0 0 2px rgba(25,159,215,0.15);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--muted); opacity: 0.6; }
.form-textarea { resize: vertical; min-height: 120px; }
.form-select option { background: var(--surface); }

/* ─── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody tr.clickable { cursor: pointer; }

/* ─── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-new     { background: rgba(25,159,215,0.15); color: var(--accent1); }
.badge-read    { background: rgba(148,163,184,0.15); color: var(--muted); }
.badge-replied { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-archived{ background: rgba(245,158,11,0.15); color: var(--warning); }

/* ─── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tab {
  padding: 0.6rem 1rem;
  border-radius: 8px 8px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  font-family: inherit;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

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

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 260px;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: slideIn 0.25s ease;
}
.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.success .toast-icon { color: var(--success); }
.toast.error   { border-color: rgba(239,68,68,0.4); }
.toast.error   .toast-icon { color: var(--danger); }
.toast.info    { border-color: rgba(25,159,215,0.4); }
.toast.info    .toast-icon { color: var(--accent1); }

@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideOut { to { transform: translateX(120%); opacity: 0; } }

/* ─── Search ─────────────────────────────────────────────────────────────────── */
.search-bar {
  position: relative;
  margin-bottom: 1rem;
}
.search-bar input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.875rem 0.6rem 2.5rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
}
.search-bar input:focus { outline: none; border-color: var(--accent1); }
.search-bar .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

/* ─── Section Headers ────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.section-header h2 { font-size: 1.1rem; font-weight: 700; }

/* ─── Filter tabs (contacts) ─────────────────────────────────────────────────── */
.filter-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.filter-tab {
  padding: 0.35rem 0.875rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  transition: all 0.15s;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: linear-gradient(135deg, var(--accent1), var(--accent2)); border-color: transparent; color: white; }

/* ─── Contact side panel ─────────────────────────────────────────────────────── */
.contact-layout { display: grid; grid-template-columns: 1fr 380px; gap: 1.25rem; }

.contact-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.contact-detail-header { font-size: 0.9rem; font-weight: 700; color: var(--muted); }
.contact-field { font-size: 0.875rem; }
.contact-field strong { display: block; font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 0.2rem; }

.reply-box { display: flex; flex-direction: column; gap: 0.75rem; }
.reply-box textarea { min-height: 160px; }

/* ─── Page list ──────────────────────────────────────────────────────────────── */
.page-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 0.5rem;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
}
.page-list-item:hover { border-color: var(--accent1); background: rgba(25,159,215,0.05); }
.page-list-item.selected { border-color: var(--accent1); background: rgba(25,159,215,0.08); }
.page-item-name { font-weight: 600; font-size: 0.875rem; }
.page-item-path { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.page-item-date { font-size: 0.72rem; color: var(--muted); }

/* ─── Editor layout ──────────────────────────────────────────────────────────── */
.editor-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1.25rem; align-items: start; }
.editor-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }

/* CodeMirror dark overrides */
.CodeMirror { height: 500px !important; font-size: 13px !important; }
.CodeMirror, .CodeMirror-gutters { background: var(--bg) !important; border: 1px solid var(--border); border-radius: 8px; }

/* Quill editor dark */
.ql-toolbar { background: var(--surface2); border: 1px solid var(--border) !important; border-radius: 8px 8px 0 0; }
.ql-container { background: var(--bg); border: 1px solid var(--border) !important; border-radius: 0 0 8px 8px; min-height: 400px; }
.ql-editor { color: var(--text); min-height: 400px; }
.ql-stroke { stroke: var(--muted) !important; }
.ql-fill { fill: var(--muted) !important; }
.ql-picker-label { color: var(--muted) !important; }
.ql-picker-options { background: var(--surface) !important; border-color: var(--border) !important; }

/* ─── Chart container ────────────────────────────────────────────────────────── */
.chart-container { position: relative; height: 220px; }

/* ─── Settings layout ────────────────────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ─── Toggle ─────────────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.toggle {
  position: relative;
  width: 44px; height: 24px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent1); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }
.toggle-label { font-size: 0.875rem; font-weight: 500; }

/* ─── Loader ─────────────────────────────────────────────────────────────────── */
.loader {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--muted);
  gap: 0.75rem;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .admin-topnav { height: auto; flex-wrap: wrap; padding: 0.6rem 1rem; gap: 0.5rem; position: static; }
  .topnav-brand { margin-right: 0; }
  .topnav-links { order: 3; width: 100%; gap: 0.15rem; flex-wrap: wrap; padding-bottom: 0.4rem; }
  .topnav-right { order: 2; }
  .nav-item { font-size: 0.78rem; padding: 0.4rem 0.65rem; }
  .editor-layout { grid-template-columns: 1fr; }
  .contact-layout { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; opacity: 0.4; }
.empty-state p { font-size: 0.875rem; }

/* ─── Sitemap viewer ─────────────────────────────────────────────────────────── */
.sitemap-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.sitemap-stat { display: flex; flex-direction: column; gap: 0.2rem; }
.sitemap-stat-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.sitemap-stat-value { font-size: 1.1rem; font-weight: 700; }

/* ─── Login page ─────────────────────────────────────────────────────────────── */
.login-body { background: var(--bg); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  justify-content: center;
}
.login-logo .logo-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.login-logo span { font-size: 1.1rem; font-weight: 800; }
.login-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 1.5rem; }
.login-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  border-radius: 8px;
  padding: 0.65rem 0.875rem;
  font-size: 0.8rem;
  margin-bottom: 1rem;
  display: none;
}
.login-error.show { display: block; }

.qr-container { text-align: center; margin: 1rem 0; }
.qr-container img { border-radius: 8px; border: 4px solid white; }
.qr-secret { font-family: monospace; font-size: 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem; word-break: break-all; margin-top: 0.75rem; color: var(--muted); }

.btn-full { width: 100%; justify-content: center; padding: 0.7rem; font-size: 0.9rem; margin-top: 0.25rem; }

/* ─── Gradient text ──────────────────────────────────────────────────────────── */
.gradient-text {
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ─── Dashboard grid ─────────────────────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 1.25rem; margin-top: 1.25rem; }
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ─── Card header row (title + inline controls) ───────────────────────────── */
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.card-header-row .card-title { margin-bottom: 0; }

/* ─── Period select dropdown ──────────────────────────────────────────────── */
.period-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.3rem 2rem 0.3rem 0.65rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  white-space: nowrap;
  flex-shrink: 0;
}
.period-select:hover { border-color: var(--accent1); }
.period-select:focus { outline: none; border-color: var(--accent1); box-shadow: 0 0 0 2px rgba(25,159,215,0.15); }
.period-select option { background: var(--surface); color: var(--text); }
