:root {
  --bg: #0d0d0f;
  --bg2: #131316;
  --bg3: #1a1a1f;
  --bg4: #222228;
  --border: #2a2a33;
  --border2: #35353f;
  --text: #e8e8f0;
  --text2: #9090a8;
  --text3: #55556a;
  --accent: #7c6af7;
  --accent2: #5e4fd4;
  --green: #3dd68c;
  --red: #f25757;
  --yellow: #f5c842;
  --font-mono: 'JetBrains Mono', monospace;
  --font-display: 'Syne', sans-serif;
  --radius: 8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 100vh;
}

/* ── LOGIN ── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 30% 40%, #1a1440 0%, var(--bg) 60%);
}
.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  width: 360px;
  display: flex; flex-direction: column; gap: 16px; align-items: center;
}
.login-logo {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}
.login-title { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.login-sub { color: var(--text3); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; margin-top: -8px; }
.field-group { display: flex; flex-direction: column; gap: 10px; width: 100%; }

/* ── FIELDS ── */
.field {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 14px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
.field:focus { border-color: var(--accent); }
.field::placeholder { color: var(--text3); }
textarea.field { resize: vertical; min-height: 180px; }

/* ── BUTTONS ── */
.btn-primary {
  background: var(--accent);
  border: none; border-radius: var(--radius);
  color: #fff; cursor: pointer;
  font-family: var(--font-mono); font-size: 13px;
  padding: 10px 20px;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent2); }
.btn-primary:active { transform: scale(.98); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text2);
  cursor: pointer;
  font-family: var(--font-mono); font-size: 13px;
  padding: 10px 20px;
  transition: border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-icon {
  background: transparent; border: none;
  color: var(--text3); cursor: pointer; font-size: 14px;
  padding: 4px 8px; border-radius: 4px;
  transition: color .15s, background .15s;
}
.btn-icon:hover { color: var(--text); background: var(--bg4); }
.btn-icon.danger:hover { color: var(--red); }

/* ── APP LAYOUT ── */
.app { display: flex; min-height: 100vh; }
.hidden { display: none !important; }

/* ── SIDEBAR ── */
.sidebar {
  width: 180px; flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 24px 12px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-logo {
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  padding: 0 8px; margin-bottom: 28px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  background: transparent; border: none;
  color: var(--text2); cursor: pointer;
  font-family: var(--font-mono); font-size: 12px;
  padding: 9px 12px; border-radius: var(--radius);
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--bg4); color: var(--accent); }
.nav-logout {
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text3); cursor: pointer;
  font-family: var(--font-mono); font-size: 11px;
  padding: 8px 12px; text-align: center;
  transition: border-color .15s, color .15s;
}
.nav-logout:hover { border-color: var(--red); color: var(--red); }

/* ── MAIN ── */
.main-content { flex: 1; overflow: auto; padding: 32px 36px; }
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.page-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.search-bar { margin-bottom: 16px; }

/* ── FOLDER CARDS ── */
.folders-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.folder-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: clip; /* clip (not hidden) — preserves sticky positioning in children */
  transition: border-color .15s;
}
.folder-card:hover { border-color: var(--border2); }

.folder-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  gap: 14px;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}
.folder-header:hover { background: var(--bg3); }

.folder-icon {
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  transition: transform .15s;
}
.folder-card.open .folder-icon { transform: rotate(90deg); }

.folder-email {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-password {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  flex-shrink: 0;
}

.folder-badge {
  background: var(--bg4);
  border-radius: 99px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  flex-shrink: 0;
}

.folder-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.folder-body {
  display: none;
  border-top: 1px solid var(--border);
}
.folder-card.open .folder-body { display: block; }

.folder-body-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.folder-body-toolbar-actions { display: flex; gap: 8px; }

.folder-search {
  flex: 1;
  max-width: 280px;
}

/* ── TABLE ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--bg3); }
.data-table th {
  padding: 11px 14px; text-align: left;
  color: var(--text3); font-size: 11px;
  letter-spacing: 1px; text-transform: uppercase;
  font-weight: 500; border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.col-resizer {
  position: absolute;
  right: 0; top: 0;
  width: 6px; height: 100%;
  cursor: col-resize;
  z-index: 1;
}
.col-resizer::after {
  content: '';
  position: absolute;
  right: 2px; top: 20%; bottom: 20%;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
  opacity: 0;
  transition: opacity .15s;
}
.data-table th:hover .col-resizer::after,
.col-resizer:hover::after { opacity: 1; }
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text2); font-size: 12px;
  vertical-align: middle;
  overflow: hidden;
  white-space: nowrap;
  max-width: 0;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg3); color: var(--text); }
.data-table .mono { font-family: var(--font-mono); }
.td-actions { display: flex; gap: 4px; }
.empty-row { text-align: center; color: var(--text3); padding: 32px; }

/* Sticky Actions column — no explicit width so it fills remaining space */
.data-table th:last-child {
  position: sticky; right: 0;
  background: var(--bg3);
  box-shadow: -4px 0 8px var(--bg);
  z-index: 2;
  width: auto;
}
.data-table td:last-child {
  position: sticky; right: 0;
  background: var(--bg2);
  box-shadow: -4px 0 8px var(--bg);
  width: auto;
  overflow: visible; /* allow flex buttons to breathe */
}
.data-table tbody tr:hover td:last-child { background: var(--bg3); }


.copy-value {
  appearance: none;
  background: transparent;
  border: none;
  color: inherit;
  cursor: copy;
  font: inherit;
  max-width: 100%;
  width: 100%;
  overflow: hidden;
  padding: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-value:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.muted-value { color: var(--text3); }

.anticode-cell {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .5px;
}

.badge {
  display: inline-block;
  padding: 2px 8px; border-radius: 99px; font-size: 11px;
}
.badge-green { background: rgba(61,214,140,.15); color: var(--green); }
.badge-red { background: rgba(242,87,87,.15); color: var(--red); }
.badge-gray { background: var(--bg4); color: var(--text3); }

.balance-positive { color: var(--green); }
.balance-negative { color: var(--red); }
.balance-zero { color: var(--text3); }

.usage-cell { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.usage-count {
  min-width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--bg4); color: var(--accent);
  font-size: 11px; font-weight: 700;
}

/* ── STATS ── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 28px;
}
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 18px;
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.stat-val {
  font-family: var(--font-display);
  font-size: clamp(18px, 2.2vw, 28px); font-weight: 700;
  color: var(--accent); line-height: 1.15;
  max-width: 100%; overflow-wrap: anywhere;
}
.stat-lbl { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }

.charts-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.chart-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.chart-title { font-size: 12px; color: var(--text2); margin-bottom: 16px; letter-spacing: 1px; text-transform: uppercase; }

/* ── MODALS ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 12px; width: 440px; max-width: 95vw; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-wide { width: 620px; }
.modal-xl { width: 860px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text3);
  cursor: pointer; font-size: 16px; padding: 4px;
  transition: color .15s; flex-shrink: 0;
}
.modal-close:hover { color: var(--red); }
.modal-body { padding: 20px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.modal-footer {
  padding: 16px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0;
}

.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 11px; color: var(--text2); letter-spacing: .5px; }
.hint { color: var(--text3); font-size: 10px; }

/* ── USAGES ── */
.usage-add-row { display: flex; gap: 10px; }
.usages-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.usage-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.usage-info { display: flex; flex-direction: column; gap: 3px; }
.usage-label { font-size: 12px; color: var(--text); }
.usage-times { font-size: 11px; color: var(--text3); }
.usage-timer { font-size: 12px; font-weight: 600; }
.usage-timer.active { color: var(--green); }
.usage-timer.expired { color: var(--red); }

/* ── BULK / EXPORT ── */
.bulk-hint { font-size: 11px; color: var(--text3); line-height: 1.6; }
.bulk-hint code { color: var(--accent); background: var(--bg3); padding: 1px 5px; border-radius: 3px; }
.bulk-area { font-size: 12px; line-height: 1.6; }
.bulk-result { margin-top: 10px; padding: 12px; background: var(--bg3); border-radius: var(--radius); font-size: 12px; line-height: 1.6; }
.export-fields {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;
}
.export-fields label {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2);
  cursor: pointer; padding: 10px 12px;
}
.export-fields input { accent-color: var(--accent); }
.export-output { min-height: 220px; }

/* ── DOCS ── */
.docs-wrap { display: flex; flex-direction: column; gap: 20px; }
.endpoint-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.endpoint-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
.endpoint-header:hover { background: var(--bg3); }
.method-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 4px; flex-shrink: 0; letter-spacing: .5px; }
.method-get { background: rgba(61,214,140,.15); color: var(--green); }
.method-post { background: rgba(124,106,247,.15); color: var(--accent); }
.method-patch { background: rgba(245,200,66,.15); color: var(--yellow); }
.method-delete { background: rgba(242,87,87,.15); color: var(--red); }
.endpoint-path { font-family: var(--font-mono); font-size: 13px; color: var(--text); }
.endpoint-desc { color: var(--text3); font-size: 12px; margin-left: auto; }
.endpoint-body { padding: 18px; display: none; }
.endpoint-body.open { display: block; }
.endpoint-body pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 14px; overflow-x: auto;
  font-size: 12px; line-height: 1.6; color: var(--text2);
}
.endpoint-section { margin-bottom: 12px; }
.endpoint-section-title { font-size: 10px; color: var(--text3); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.auth-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; padding: 3px 9px; border-radius: 99px; margin-bottom: 12px; }
.auth-jwt { background: rgba(124,106,247,.15); color: var(--accent); }
.auth-apikey { background: rgba(245,200,66,.15); color: var(--yellow); }
.auth-none { background: var(--bg4); color: var(--text3); }

/* ── MISC ── */
.error-msg { color: var(--red); font-size: 11px; min-height: 16px; }

.toast {
  position: fixed; bottom: 28px; right: 28px;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 12px 18px;
  font-size: 13px; z-index: 9999;
  animation: slideUp .2s ease;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

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

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── SIDEBAR API KEY ── */
.sidebar-apikey {
  margin-bottom: 12px; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
}
.apikey-label { font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text3); margin-bottom: 5px; }
.apikey-row { display: flex; align-items: center; gap: 6px; }
.apikey-val { font-family: var(--font-mono); font-size: 10px; color: var(--accent); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apikey-copy { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 14px; padding: 2px 4px; flex-shrink: 0; transition: color .15s; }
.apikey-copy:hover { color: var(--accent); }

/* ── SETTINGS ── */
.settings-grid { display: flex; flex-direction: column; gap: 20px; }
.settings-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  display: flex; flex-direction: column; gap: 14px; max-width: 680px;
}
.settings-card-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.settings-desc { font-size: 12px; color: var(--text2); line-height: 1.6; }
.settings-desc code { color: var(--accent); background: var(--bg3); padding: 1px 6px; border-radius: 3px; }
.apikey-display-row { display: flex; gap: 10px; align-items: center; }
.apikey-display-row .field { font-size: 12px; color: var(--accent); letter-spacing: .5px; }
.settings-warn { font-size: 11px; color: var(--yellow); line-height: 1.6; }
.settings-pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 16px;
  font-size: 11px; line-height: 1.8; color: var(--text2);
  overflow-x: auto; white-space: pre;
}
.language-row { max-width: 220px; }

/* ── EMAILS MODAL ── */
.modal-emails-wide { width: 760px; max-height: 85vh; }
.emails-list { display: flex; flex-direction: column; overflow-y: auto; max-height: calc(85vh - 80px); }
.emails-loading { color: var(--text3); font-size: 12px; padding: 20px 22px; }
.emails-empty { color: var(--text3); font-size: 12px; padding: 20px 22px; }
.email-item { border-bottom: 1px solid var(--border); transition: background .1s; }
.email-item:last-child { border-bottom: none; }
.email-item:hover { background: var(--bg3); }
.email-item-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; cursor: pointer; gap: 12px; user-select: none;
}
.email-subject-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.email-subject { font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-item-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.email-date { font-size: 11px; color: var(--text3); white-space: nowrap; }
.email-kind-badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 99px; flex-shrink: 0; }
.kind-code { background: rgba(61,214,140,.15); color: var(--green); }
.kind-declined { background: rgba(242,87,87,.15); color: var(--red); }
.kind-other { background: var(--bg4); color: var(--text3); }
.email-meta-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 22px 10px; }
.email-meta-chip { font-size: 11px; padding: 3px 10px; border-radius: 6px; }
.chip-code { background: rgba(61,214,140,.12); color: var(--green); }
.chip-code strong { font-size: 13px; letter-spacing: 1px; }
.chip-amount { background: rgba(245,200,66,.12); color: var(--yellow); }
.chip-reason { background: var(--bg4); color: var(--text2); max-width: 500px; }
.email-body-wrap { padding: 0 22px 14px; }
.email-item.collapsed .email-body-wrap { display: none; }
.email-item.collapsed .email-meta-row { display: none; }
.email-body {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px 14px; font-size: 11px; line-height: 1.7; color: var(--text2);
  white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow-y: auto;
}
.email-delete { opacity: 0; transition: opacity .15s; }
.email-item:hover .email-delete { opacity: 1; }

/* ── EMPTY FOLDERS ── */
.folders-empty {
  text-align: center;
  color: var(--text3);
  padding: 60px 20px;
  font-size: 13px;
}
.folders-empty span { font-size: 32px; display: block; margin-bottom: 12px; }

@media (max-width: 720px) {
  .page-header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .modal-xl { width: 98vw; }
}
