:root {
  color-scheme: light;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  --ink: #18231f;
  --muted: #65756f;
  --line: #cfdad4;
  --panel: #eef4f0;
  --surface: #f9fcfa;
  --sidebar-bg: #21302b;
  --sidebar-text: #f4faf7;
  --accent: #2d8f79;
  --accent-2: #3f77bd;
  --warning: #b46827;
  --shadow: rgba(23, 32, 28, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf5f1;
  --muted: #9fb0aa;
  --line: #24342f;
  --panel: #0f1714;
  --surface: #141f1b;
  --sidebar-bg: #090f0d;
  --sidebar-text: #ffffff;
  --accent: #42b99f;
  --accent-2: #6da6e8;
  --warning: #d78b46;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--panel);
  color: var(--ink);
}

:root[data-theme="dark"] body {
  background: #0b1110;
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--panel);
}

.login-card {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 60px var(--shadow);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 10px;
}

.login-card input,
.password-dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.login-card button,
.password-dialog button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #07100d;
  cursor: pointer;
  font-weight: 700;
}

.login-card .secondary-auth {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: #e07a5f;
  font-size: 13px;
}

.form-error.success {
  color: #42b99f;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width, 280px) 6px var(--list-width, 420px) 6px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

:root[data-theme="dark"] .sidebar {
  background: #090f0d;
  border-right: 1px solid var(--line);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  font-weight: 800;
}

.brand span {
  display: block;
  color: #b8c9c2;
  font-size: 13px;
  margin-top: 2px;
}

.theme-toggle {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #eef8f4;
  min-height: 40px;
  cursor: pointer;
}

.user-box {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.profile-menu {
  position: relative;
}

.profile-button {
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #eef8f4;
  padding: 9px;
  cursor: pointer;
  text-align: left;
}

.profile-button > span:first-child {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #07100d;
  font-weight: 800;
}

.profile-button strong,
.profile-button small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-button small {
  color: #b8c9c2;
}

.profile-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 40px var(--shadow);
}

.profile-dropdown button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.profile-dropdown button:hover {
  background: var(--panel);
}

.user-box span {
  color: #b8c9c2;
  font-size: 13px;
}

.user-box button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #eef8f4;
  cursor: pointer;
}

.alias-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.alias-form input:first-child,
.alias-address-field {
  grid-column: 1 / -1;
}

.alias-form input,
.toolbar input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
}

.alias-address-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.alias-address-field input {
  border: 0;
  border-radius: 0;
}

.alias-address-field span {
  color: var(--muted);
  padding-right: 10px;
  white-space: nowrap;
  font-size: 13px;
}

.alias-form button,
.toolbar button,
.message-actions button {
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  cursor: pointer;
  min-height: 40px;
}

.alias-form button {
  width: 100%;
}

nav,
.alias-list {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.folder-list {
  display: grid;
  gap: 6px;
}

.rule-box,
.add-address-box {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.rule-box summary,
.add-address-box summary {
  cursor: pointer;
  font-weight: 700;
}

.add-address-box summary {
  display: flex;
  align-items: center;
  gap: 8px;
}

.add-address-box summary span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: #07100d;
}

.add-address-box .alias-form {
  margin-top: 10px;
}

.rule-box form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.rule-box input,
.rule-box select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--ink);
}

.filter-aliases {
  display: grid;
  gap: 6px;
  max-height: 150px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--surface);
}

.filter-aliases label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 13px;
}

.filter-aliases span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-box button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #07100d;
  cursor: pointer;
  font-weight: 700;
}

.filter-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: #b8c9c2;
  font-size: 12px;
}

.nav-item,
.alias-button,
.account-button,
.account-folder {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dfe9e4;
  text-align: left;
  padding: 10px;
  cursor: pointer;
}

.nav-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.nav-item strong {
  color: #b8c9c2;
  font-size: 13px;
  font-weight: 700;
}

.nav-item.active,
.alias-button.active,
.account-button.active,
.account-folder.active {
  background: rgba(255, 255, 255, 0.12);
}

.alias-button {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.account-group {
  display: grid;
  gap: 4px;
}

.account-button {
  display: grid;
  grid-template-columns: 14px 10px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-weight: 700;
}

.account-button[draggable="true"] {
  cursor: grab;
}

.account-button.drag-over {
  outline: 1px solid var(--accent);
}

.account-button .chevron {
  color: #b8c9c2;
  font-size: 12px;
}

.account-folders {
  display: grid;
  gap: 2px;
  padding-left: 28px;
}

.account-folder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 7px 9px;
  color: #c7d8d1;
  font-size: 13px;
}

.account-folder strong {
  color: #b8c9c2;
}

.alias-button[draggable="true"] {
  cursor: grab;
}

.alias-button.drag-over {
  outline: 1px solid var(--accent);
}

.alias-name {
  min-width: 0;
}

.alias-name strong,
.alias-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.dot.has-unread {
  background: #42b99f !important;
  box-shadow: 0 0 0 4px rgba(66, 185, 159, 0.12);
}

.resize-handle {
  background: var(--line);
  cursor: col-resize;
  min-width: 6px;
  transition: background 0.15s ease;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--accent);
}

.mail-list-panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 44px 44px;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: relative;
}

.notification-bell {
  position: relative;
}

.notification-bell.has-new {
  animation: bellPulse 900ms ease both;
}

.notification-bell span {
  position: absolute;
  right: -5px;
  top: -5px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #42b99f;
  color: #07100d;
  font-size: 11px;
  font-weight: 800;
}

@keyframes bellPulse {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-10deg);
  }
  55% {
    transform: rotate(10deg);
  }
}

.refresh-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  background: transparent;
}

.refresh-progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
  opacity: 0.9;
  transition: width 0.2s linear;
}

.mail-list {
  overflow: auto;
  max-height: calc(100vh - 69px);
}

.mail-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  padding: 14px;
  display: grid;
  gap: 8px;
  cursor: pointer;
  transform-origin: top center;
}

.mail-item.is-new {
  animation: mailIn 520ms ease both;
}

@keyframes mailIn {
  0% {
    opacity: 0;
    transform: translateY(-10px) scale(0.985);
    background: rgba(66, 185, 159, 0.18);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.mail-item:hover,
.mail-item.active {
  background: #eef7f3;
}

:root[data-theme="dark"] .mail-item:hover,
:root[data-theme="dark"] .mail-item.active {
  background: #1b2a25;
}

.mail-item.unread .subject {
  font-weight: 800;
}

.mail-meta,
.mail-foot,
.message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.mail-meta span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subject {
  color: var(--ink);
  line-height: 1.25;
}

.preview {
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: white;
}

:root[data-theme="dark"] .pill {
  background: #0f1714;
}

.message-panel {
  min-width: 0;
  background: var(--surface);
  padding: 28px;
  overflow: auto;
  max-height: 100vh;
  color: var(--ink);
}

.empty-state {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h1 {
  color: var(--ink);
  margin: 0 0 8px;
}

.message-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 22px;
}

.message-header h1 {
  font-size: 28px;
  margin: 0 0 12px;
  line-height: 1.2;
}

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

.message-actions button {
  padding: 0 12px;
  background: var(--accent-2);
}

.message-actions button.warning {
  background: var(--warning);
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.6;
  max-width: 860px;
  color: var(--ink);
}

.message-html-render {
  width: 100%;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 14px;
  overflow: auto;
}

.message-html-render,
.message-html-render * {
  color: var(--ink) !important;
  background-color: transparent !important;
}

.message-html-render a {
  display: inline-block;
  margin-top: 10px;
}

.message-html-render .email-footer {
  display: block;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted) !important;
  font-size: 13px;
}

.message-html-render img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: zoom-in;
}

.attachments {
  display: grid;
  gap: 10px;
  margin-top: 22px;
  max-width: 720px;
}

.attachments h2 {
  margin: 0;
  font-size: 18px;
}

.attachment-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
}

.attachment-item:hover {
  border-color: var(--accent);
}

.attachment-item small {
  color: var(--muted);
}

.attachment-item.inline {
  border-style: dashed;
}

.image-viewer {
  width: min(96vw, 1200px);
  height: min(92vh, 900px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050807;
  color: white;
  padding: 0;
}

.image-viewer::backdrop {
  background: rgba(0, 0, 0, 0.78);
}

.image-viewer-toolbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.image-viewer-toolbar div {
  display: flex;
  gap: 8px;
}

.image-viewer-toolbar a,
.image-viewer-toolbar button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  text-decoration: none;
  padding: 7px 10px;
  cursor: pointer;
}

.image-viewer img {
  width: 100%;
  height: calc(100% - 52px);
  object-fit: contain;
  display: block;
}

.password-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(100%, 420px);
}

.password-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.password-dialog form {
  display: grid;
  gap: 12px;
  padding: 22px;
}

.password-dialog h2 {
  margin: 0 0 4px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions button:first-child {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 50px var(--shadow);
}

.context-menu button {
  width: 100%;
  display: block;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0 10px;
  cursor: pointer;
}

.context-menu button:hover {
  background: var(--panel);
}

.context-menu button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.55;
}

.context-menu button:disabled:hover {
  background: transparent;
}

.context-menu .danger {
  color: #f0a078;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: 420px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 50px var(--shadow);
}

.toast button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #07100d;
  padding: 7px 10px;
  cursor: pointer;
}

.admin-dialog {
  width: min(94vw, 980px);
  height: min(88vh, 780px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.admin-body {
  display: grid;
  grid-template-columns: 280px 1fr 1fr;
  gap: 12px;
  padding: 14px;
  overflow: auto;
}

.admin-card {
  display: grid;
  align-content: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.admin-card h2 {
  margin: 0;
  font-size: 16px;
}

.admin-card input,
.admin-card button {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 10px;
}

.admin-card button {
  background: var(--accent);
  color: #07100d;
  border: 0;
  cursor: pointer;
}

.admin-row {
  display: grid;
  gap: 4px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.admin-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-actions button {
  min-height: 30px;
  font-size: 12px;
}

.admin-limits {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .resize-handle {
    display: none;
  }

  .message-panel {
    grid-column: 1 / -1;
    min-height: 48vh;
  }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .message-panel {
    max-height: none;
  }
}
