:root {
  --bg: #040d1a;
  --bg-deep: #020712;
  --panel: #071426;
  --panel-alt: #0a1830;
  --border: rgba(80, 140, 200, 0.25);
  --text: #c8dff0;
  --text-dim: #5f80a3;
  --text-faint: #3a5570;
  --accent: #64b5d9;
  --accent-bright: #9adcff;
  --accent-glow: rgba(100, 180, 255, 0.35);
  --selected: #0f2840;
  --unread-dot: #7ab3d8;
  --danger: #ff6b81;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse at 20% 20%, rgba(40, 70, 140, 0.25), transparent 60%),
              radial-gradient(ellipse at 80% 60%, rgba(60, 40, 120, 0.18), transparent 55%),
              var(--bg-deep);
}

#starfield::before, #starfield::after {
  content: "";
  position: absolute;
  inset: 0;
  background-repeat: repeat;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, #bcd8ff 100%, transparent),
    radial-gradient(1px 1px at 30% 70%, #9adcff 100%, transparent),
    radial-gradient(1.5px 1.5px at 55% 15%, #ffffff 100%, transparent),
    radial-gradient(1px 1px at 70% 45%, #bcd8ff 100%, transparent),
    radial-gradient(1.5px 1.5px at 85% 80%, #ffffff 100%, transparent),
    radial-gradient(1px 1px at 45% 90%, #9adcff 100%, transparent),
    radial-gradient(1.5px 1.5px at 95% 30%, #bcd8ff 100%, transparent),
    radial-gradient(1px 1px at 15% 55%, #ffffff 100%, transparent);
  background-size: 260px 260px;
  animation: twinkle 6s ease-in-out infinite alternate;
  opacity: 0.8;
}

#starfield::after {
  background-size: 340px 340px;
  animation-duration: 9s;
  animation-delay: 2s;
  opacity: 0.5;
}

@keyframes twinkle {
  from { opacity: 0.35; }
  to { opacity: 0.9; }
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: rgba(6, 16, 30, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(4px);
}

#brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 15px;
  color: var(--accent-bright);
  text-shadow: 0 0 12px var(--accent-glow);
}

#brand-mark { font-size: 18px; }

#topbar-actions, #topbar-actions-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#search-wrap {
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px;
}
#search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(100, 180, 255, 0.12);
}
#search-icon { font-size: 13px; color: var(--text-faint); flex-shrink: 0; }
#search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}
#search-input::placeholder { color: var(--text-faint); }
#search-wrap .icon-btn { width: 22px; height: 22px; font-size: 11px; }

#identity {
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#identity-name { color: var(--text); font-weight: 600; }

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

.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

.primary-btn {
  background: linear-gradient(180deg, #2f6fb0, #1c4c85);
  color: #eaf4ff;
  border: 1px solid rgba(120, 180, 255, 0.4);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 0 14px rgba(50, 120, 220, 0.25);
}
.primary-btn:hover { filter: brightness(1.15); }

.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
}
.secondary-btn:hover { background: var(--selected); }

.icon-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 16px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  color: var(--accent-bright);
  background: var(--panel-alt);
  border-color: var(--border);
}

#body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#sidebar {
  width: 200px;
  flex-shrink: 0;
  background: rgba(7, 20, 38, 0.75);
  border-right: 1px solid var(--border);
  padding: 14px 0;
}

#folder-list, #contacts-nav { list-style: none; margin: 0; padding: 0; }

#contacts-nav {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.folder-item:hover { background: var(--panel-alt); color: var(--text); }

.folder-item-icon-label { display: flex; align-items: center; gap: 8px; }

.folder-item.active {
  background: var(--selected);
  color: var(--accent-bright);
  border-left-color: var(--accent);
}

.folder-count {
  background: rgba(100, 180, 255, 0.15);
  color: var(--accent-bright);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.folder-count.zero { display: none; }

#message-list-pane {
  width: 340px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#message-list-header {
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

#message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.message-item {
  padding: 12px 18px;
  border-bottom: 1px solid rgba(80, 140, 200, 0.12);
  cursor: pointer;
}
.message-item:hover { background: var(--panel-alt); }
.message-item.selected { background: var(--selected); }

.message-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.message-from {
  font-size: 13.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-item.unread .message-from,
.message-item.unread .message-subject {
  color: var(--text);
  font-weight: 700;
}

.message-date {
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}

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

.message-snippet {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--unread-dot);
  box-shadow: 0 0 6px var(--unread-dot);
  margin-right: 6px;
}

#reading-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(4, 10, 20, 0.4);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  gap: 10px;
  font-size: 13px;
}
.empty-icon { font-size: 36px; color: var(--text-faint); }

#reading-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#reading-toolbar {
  display: flex;
  gap: 10px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.menu-wrap { position: relative; margin-left: auto; }

.menu-icon-btn {
  width: 44px;
  height: 44px;
  font-size: 26px;
  color: var(--accent-bright);
  background: rgba(100, 180, 255, 0.1);
  border: 1px solid rgba(100, 180, 255, 0.3);
}
.menu-icon-btn:hover {
  background: rgba(100, 180, 255, 0.22);
  box-shadow: 0 0 14px rgba(100, 180, 255, 0.35);
}

.dropdown {
  position: absolute;
  right: 0;
  top: 50px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 10;
  min-width: 210px;
  overflow: hidden;
}
.dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 14px;
  font-size: 13px;
}
.dropdown button .icon { color: var(--text-dim); }
.dropdown button:hover { background: var(--selected); }
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

#reading-header { padding: 18px 22px 10px; border-bottom: 1px solid rgba(80,140,200,0.12); }
#reading-subject { margin: 0 0 10px; font-size: 19px; color: var(--accent-bright); font-weight: 700; }
.reading-meta { display: flex; flex-direction: column; gap: 3px; }
.meta-row { font-size: 12.5px; color: var(--text-dim); }
.meta-label { color: var(--text-faint); margin-right: 6px; }

#reading-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #06101e;
}

#reply-box {
  border-top: 1px solid var(--border);
  background: rgba(7, 20, 38, 0.85);
  max-height: 45vh;
  overflow-y: auto;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 14, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 0 40px rgba(30, 80, 160, 0.35);
  width: min(640px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  color: var(--accent-bright);
}

#source-content {
  margin: 0;
  padding: 18px;
  overflow: auto;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.mail-form {
  display: flex;
  flex-direction: column;
  padding: 16px 22px;
  gap: 10px;
}

.mail-form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.mail-form-label {
  width: 56px;
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--text-faint);
}

.mail-form-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 4px 0;
}
.mail-form-input::placeholder { color: var(--text-faint); }

.mail-form-toggles {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  padding: 0;
}
.link-btn:hover { color: var(--accent-bright); text-decoration: underline; }

.mail-form-body {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  padding: 10px 0 0;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
}

.mail-form-actions { display: flex; gap: 8px; margin-top: 4px; }

.form-error {
  color: var(--danger);
  font-size: 12px;
}

#contact-detail-emails {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.contact-email-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
}

.contact-email-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-faint);
  min-width: 70px;
}

.contact-email-value {
  font-size: 13px;
  color: var(--accent-bright);
  font-family: "SF Mono", Consolas, monospace;
}

.hidden { display: none !important; }
