/* ===========================================================
   Personal Mail Manager (app name is configurable via APP_NAME) — Design System
   =========================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-contrast: #ffffff;

  --background: #f6f7fb;
  --surface: #ffffff;
  --surface-secondary: #f1f3f9;
  --text: #16181d;
  --text-secondary: #5b6270;
  --border: #e3e6ee;

  --danger: #dc2626;
  --danger-bg: #fdecec;
  --success: #16a34a;
  --success-bg: #eafaf0;
  --warning: #d97706;
  --warning-bg: #fff7e6;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);

  --topbar-height: 60px;
  --sidebar-width: 220px;
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-contrast: #0b0e14;

  --background: #0f1115;
  --surface: #171a21;
  --surface-secondary: #1e222b;
  --text: #edeef1;
  --text-secondary: #9aa1af;
  --border: #2a2f3a;

  --danger: #f87171;
  --danger-bg: #2a1414;
  --success: #4ade80;
  --success-bg: #0f2418;
  --warning: #fbbf24;
  --warning-bg: #2a2110;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--background);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.topbar-search { flex: 1; max-width: 480px; }

.topbar-search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-secondary);
  color: var(--text);
  font-size: 14px;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.admin-menu { display: flex; align-items: center; gap: 10px; }
.admin-name { color: var(--text-secondary); font-size: 13px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.icon-btn:hover { background: var(--surface-secondary); }

.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* ---------- Shell / sidebar ---------- */
.app-shell {
  display: flex;
  min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  flex-shrink: 0;
  transition: transform 0.2s ease, width 0.2s ease;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}
.sidebar-link:hover { background: var(--surface-secondary); }
.sidebar-link.active { background: var(--primary); color: var(--primary-contrast); }
.sidebar-link.disabled { color: var(--text-secondary); cursor: default; }
.sidebar-link.disabled:hover { background: transparent; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-secondary);
  color: var(--text-secondary);
}

.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
}

.page-header { margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 22px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-label { color: var(--text-secondary); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-hint { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }

.empty-state { color: var(--text-secondary); }
.empty-state strong { color: var(--text); }

/* ---------- Forms / buttons ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="search"], input[type="email"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-secondary); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }

/* ---------- Auth page ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--background);
}
.auth-theme-toggle { position: fixed; top: 16px; right: 16px; }
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.auth-brand { justify-content: center; margin-bottom: 24px; font-size: 18px; }

/* ---------- Settings / cards ---------- */
.card-title { margin: 0 0 6px; font-size: 16px; }
.card-title-sm { margin: 20px 0 10px; font-size: 14px; color: var(--text-secondary); }
.card-subtitle { margin: 0 0 16px; color: var(--text-secondary); font-size: 13px; }

.test-result {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  word-break: break-word;
}
.test-result-success { background: var(--success-bg); color: var(--success); }
.test-result-error { background: var(--danger-bg); color: var(--danger); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 480px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th { color: var(--text-secondary); font-weight: 600; }

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { border-left: 3px solid var(--success); }
.toast-danger { border-left: 3px solid var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar-search { display: none; }
  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 30;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 16px; }
  .toast-container { left: 16px; right: 16px; bottom: 16px; max-width: none; }
  .toast { width: 100%; }
  .btn-block-mobile { width: 100%; }
}

@media (max-width: 480px) {
  #testConnectionBtn { width: 100%; }
}
