:root {
  --bg: #0a0a0b;
  --bg-elevated: #141416;
  --bg-hover: #1c1c1f;
  --border: #26262a;
  --text: #e8e8ea;
  --text-dim: #8a8a90;
  --orange: #ff7a1a;
  --orange-bright: #ff9142;
  --orange-glow: rgba(255, 122, 26, 0.25);
  --danger: #e5484d;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  height: 100%;
}

a { color: var(--orange); }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea {
  font-family: inherit;
}

/* ---------- LOGIN ---------- */

.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 122, 26, 0.06), transparent 60%),
    var(--bg);
}

.login-card {
  width: 340px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 0 40px rgba(255, 122, 26, 0.05);
}

.login-card h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.login-card .subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-glow);
}

.btn-primary {
  width: 100%;
  background: var(--orange);
  border: none;
  border-radius: 6px;
  color: #0a0a0b;
  font-weight: 600;
  padding: 11px;
  font-size: 14px;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--orange-bright); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.error-message {
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.3);
  color: #ff8a8d;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

.error-message.visible { display: block; }

/* ---------- APP LAYOUT ---------- */

.app {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header .logo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 8px var(--orange);
}

.sidebar-header h1 {
  font-size: 14px;
  margin: 0;
  font-weight: 600;
}

.mailbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.mailbox-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.mailbox-item:hover { background: var(--bg-hover); color: var(--text); }
.mailbox-item.active {
  background: var(--bg-hover);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--orange);
}

.mailbox-item .delete-btn {
  opacity: 0;
  color: var(--text-dim);
  background: none;
  border: none;
  font-size: 14px;
  padding: 2px 4px;
}
.mailbox-item:hover .delete-btn { opacity: 1; }
.mailbox-item .delete-btn:hover { color: var(--danger); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 9px;
  font-size: 13px;
  text-align: center;
}
.btn-secondary:hover { border-color: var(--orange); color: var(--orange-bright); }

.btn-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px;
}
.btn-logout:hover { color: var(--danger); }

.mail-list-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px;
  font-size: 12px;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--orange-bright);
  border-bottom-color: var(--orange);
}

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

.mailbox-item .key-btn {
  opacity: 0;
  color: var(--text-dim);
  background: none;
  border: none;
  font-size: 12px;
  padding: 2px 4px;
}
.mailbox-item:hover .key-btn { opacity: 1; }
.mailbox-item .key-btn:hover { color: var(--orange-bright); }

.contact-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.contact-row .contact-info { display: flex; flex-direction: column; }
.contact-row .contact-email { color: var(--text-dim); font-size: 11px; }

.contact-row .delete-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
}
.contact-row .delete-btn:hover { color: var(--danger); }

/* ---------- MAIL LIST ---------- */

.mail-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mail-list-header h2 {
  font-size: 13px;
  margin: 0;
  color: var(--text-dim);
  font-weight: 500;
  word-break: break-all;
}

.mail-list {
  flex: 1;
  overflow-y: auto;
}

.mail-list-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.mail-list-item:hover { background: var(--bg-hover); }
.mail-list-item.active { background: var(--bg-hover); box-shadow: inset 2px 0 0 var(--orange); }

.mail-list-item .from {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.mail-list-item.unread .from { color: var(--orange-bright); }

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

.mail-list-item .date {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------- MAIL DETAIL ---------- */

.mail-detail-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-detail-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.mail-detail-header .subject {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 8px;
}

.mail-detail-header .meta {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}

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

.mail-detail-body iframe {
  width: 100%;
  min-height: 400px;
  border: none;
  background: white;
  border-radius: 6px;
}

.mail-detail-body pre {
  white-space: pre-wrap;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.6;
}

.attachments {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.attachment-chip:hover { border-color: var(--orange); color: var(--orange-bright); }

/* ---------- MODAL ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 15px;
  margin: 0 0 16px;
}

.modal .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  resize: vertical;
  min-height: 120px;
}

.modal .field textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-glow);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary { flex: 1; }

.toolbar-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
}
.toolbar-btn:hover { border-color: var(--orange); color: var(--orange-bright); }

.mail-detail-toolbar {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
