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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22263a;
  --border: #2a2e3e;
  --border-focus: #6366f1;
  --text: #e4e4e7;
  --text-dim: #9ca3af;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.2);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.2);
  --orange: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-hover: #f0f0f3;
  --border: #e0e0e6;
  --border-focus: #6366f1;
  --text: #1a1a2e;
  --text-dim: #6b7280;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.18);
  --green: #16a34a;
  --green-glow: rgba(22, 163, 74, 0.12);
  --red: #dc2626;
  --red-glow: rgba(220, 38, 38, 0.12);
  --orange: #d97706;
}

[data-theme="light"] .logo h1 {
  background: linear-gradient(135deg, #6366f1, #4f46e5, #4338ca);
  -webkit-background-clip: text;
  background-clip: text;
}

[data-theme="light"] .conn-group {
  background: #f9fafb;
}

[data-theme="light"] .conn-group input {
  background: #fff;
}

[data-theme="light"] .btn .spinner {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: #4f46e5;
}

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

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

/* ── Header ── */
.header {
  text-align: center;
  padding: 40px 0 32px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* ── Header Actions ── */
.header-actions {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
  padding: 0;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.logo svg {
  color: var(--accent);
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #818cf8, #6366f1, #4f46e5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 400;
}

/* ── Header Top ── */
.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
  position: relative;
}

/* ── Language Selector ── */
.lang-selector {
  position: relative;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.lang-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  min-width: 160px;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.lang-dropdown.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  text-align: left;
}

.lang-option:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  transition: border-color var(--transition);
}

.card:hover {
  border-color: #3a3e52;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

.card-title svg {
  color: var(--accent);
  flex-shrink: 0;
}

/* ── Presets ── */
.preset-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.preset-btn:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.preset-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.preset-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.preset-dot.gmail { background: #ea4335; }
.preset-dot.outlook { background: #0078d4; }
.preset-dot.yandex { background: #fc0; }
.preset-dot.custom { background: #9ca3af; }

/* ── Connection Grid ── */
.connection-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

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

.conn-group {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.conn-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 12px;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.field-small { flex: 0 0 80px; }
.field-tiny { flex: 0 0 56px; }

label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all var(--transition);
  width: 100%;
}

input:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

.conn-group input {
  background: var(--surface);
}

/* ── Credentials ── */
.credentials {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.hint {
  font-size: 11px;
  color: var(--text-dim);
}

.hint a {
  color: var(--accent);
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

/* ── Toggle ── */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: var(--transition);
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .slider {
  background: var(--accent);
}

.toggle input:checked + .slider::before {
  transform: translateX(20px);
  background: #fff;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.tab svg {
  flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

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

.btn-secondary:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.btn-outline {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  width: auto;
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.btn-danger-outline:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-glow);
}

/* ── Connection Actions ── */
.conn-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ── Test Result Spans ── */
.test-ok {
  color: var(--green);
}

.test-fail {
  color: var(--red);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ── Loader ── */
.btn .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Results ── */
.result {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  animation: slideUp 0.3s ease;
}

.result.success {
  background: var(--green-glow);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: var(--green);
}

.result.error {
  background: var(--red-glow);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--red);
}

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

/* ── Email List ── */
#email-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: all var(--transition);
  animation: slideUp 0.3s ease;
}

.email-item:hover {
  border-color: #3a3e52;
}

.email-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  gap: 12px;
  user-select: none;
}

.email-header:hover {
  background: var(--surface-hover);
}

.email-meta {
  flex: 1;
  min-width: 0;
}

.email-from {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-subject {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-date {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.email-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.email-body.open {
  display: block;
}

.email-body-content {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 13px;
  color: var(--text-dim);
  max-height: 300px;
  overflow-y: auto;
  margin-top: 12px;
  word-break: break-word;
}

.email-body-content img {
  max-width: 100%;
  height: auto;
}

.email-chevron {
  color: var(--text-dim);
  transition: transform var(--transition);
  flex-shrink: 0;
}

.email-item.expanded .email-chevron {
  transform: rotate(180deg);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 24px var(--green-glow);
}

.toast.error {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 24px var(--red-glow);
}

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

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ── Panel spacing ── */
.panel .field + .field {
  margin-top: 14px;
}

.panel .btn {
  margin-top: 20px;
}
