:root {
  --ink: #1D2733;
  --ink-soft: #4B5768;
  --slate: #2E3A4C;
  --slate-light: #3C4A60;
  --paper: #FBFAF7;
  --paper-line: #E4E0D6;
  --stamp-red: #B23B2E;
  --stamp-red-dark: #8F2E24;
  --ok-green: #3F6B4E;
  --sidebar-w: 300px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--slate);
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
}

h1,
h2 {
  font-family: 'Zilla Slab', serif;
  margin: 0;
}

.frame {
  display: flex;
  min-height: 100vh;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
}

.login-box {
  width: min(420px, calc(100% - 32px));
  background: #FBFAF7;
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand h1 {
  font-size: 24px;
  margin: 0;
}

.login-brand p {
  margin: 4px 0 0;
  color: #4b5563;
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
}

.login-form input {
  border: 1px solid #d6d3d1;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: 'IBM Plex Sans', sans-serif;
  outline: none;
}

.login-form input:focus {
  border-color: #b23b2e;
}

.login-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.login-note {
  margin-top: 18px;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.5;
}

/* ---------- Sidebar / ledger ---------- */

.ledger {
  width: var(--sidebar-w);
  height: 100vh;
  position: sticky;
  top: 0;
  flex-shrink: 0;
  background: var(--slate);
  background-image: linear-gradient(180deg, var(--slate) 0%, #26313F 100%);
  color: #E9E7DF;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.ledger-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(233, 231, 223, 0.15);
}

.mark {
  font-size: 26px;
  color: var(--stamp-red);
  transform: rotate(-8deg);
}

.ledger-head h1 {
  font-size: 22px;
  font-weight: 600;
  color: #F5F3EC;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 2px 0 0;
  font-size: 12px;
  color: #9BA7B7;
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ledger-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
}

.account-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.account-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
}

.account-card.active {
  background: rgba(178, 59, 46, 0.18);
  border-color: var(--stamp-red);
}

.account-card .acc-name {
  font-weight: 600;
  font-size: 14px;
  color: #F5F3EC;
}

.account-card .acc-email {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: #9BA7B7;
  margin-top: 3px;
  word-break: break-all;
}

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

.acc-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.acc-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--slate-light);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
}

.acc-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.account-card .acc-edit {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  color: #9BA7B7;
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.account-card:hover .acc-edit {
  opacity: 1;
}

.account-card .acc-edit:hover {
  color: #F5F3EC;
  text-decoration: underline;
}

.no-accounts {
  color: #8A96A6;
  font-size: 13px;
  padding: 10px 4px;
  line-height: 1.5;
}

.ghost-btn {
  background: none;
  border: 1px dashed rgba(233, 231, 223, 0.35);
  color: #D9D6CB;
  border-radius: 6px;
  padding: 10px 14px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.ghost-btn:hover {
  border-color: var(--stamp-red);
  color: #F5F3EC;
}

/* ---------- Desk / paper ---------- */

.desk {
  flex: 1;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.03), transparent 40%),
    var(--slate);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 32px;
  height: 100vh;
  overflow-y: auto;
}

.paper {
  position: relative;
  background: var(--paper);
  width: 100%;
  max-width: 680px;
  border-radius: 3px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35), 0 2px 0 rgba(0, 0, 0, 0.05);
  padding: 40px 44px 32px;
  overflow: hidden;
}

.paper::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, var(--stamp-red) 0 14px, transparent 14px 24px);
  opacity: 0.55;
}

.paper-corner {
  position: absolute;
  top: 18px;
  right: 24px;
  pointer-events: none;
}

.stamp {
  width: 92px;
  height: 92px;
  border: 3px solid var(--stamp-red);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--stamp-red);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  letter-spacing: 0.08em;
  transform: rotate(12deg) scale(0.7);
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.stamp.show {
  opacity: 0.9;
  transform: rotate(12deg) scale(1);
}

.stamp #stampText {
  font-size: 13px;
}

.stamp-date {
  font-size: 9px;
  margin-top: 4px;
}

.field-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--paper-line);
}

.field-row label {
  width: 78px;
  flex-shrink: 0;
  padding-top: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  font-weight: 600;
}

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

.field-row input[type="text"],
.field-row input[type="password"],
.field-row select,
.field-row textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 15px;
  color: var(--ink);
  padding: 8px 0;
  outline: none;
}

.field-row select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%234B5768' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 20px;
}

.body-row textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.55;
}

.field-row input::placeholder,
.field-row textarea::placeholder {
  color: #B7AF9E;
}

.attach-zone {
  flex: 1;
  padding: 4px 0;
}

.attach-zone input[type="file"] {
  font-size: 13px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink-soft);
}

.file-list {
  margin-top: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.send-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 24px;
}

.send-btn {
  background: var(--stamp-red);
  color: #FBFAF7;
  border: none;
  border-radius: 4px;
  padding: 12px 26px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.send-btn:hover {
  background: var(--stamp-red-dark);
}

.send-btn:active {
  transform: translateY(1px);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-line {
  font-size: 13px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink-soft);
}

/* Logout link styling */
.logout-link {
  color: #9BA7B7;
  font-size: 12px;
  text-decoration: none;
  font-weight: 500;
  margin-left: auto;
  padding: 4px 8px;
  border: 1px solid rgba(233, 231, 223, 0.15);
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}

.logout-link:hover {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.05);
}

/* Right-side collapsible Send History sidebar */
.history-panel-right {
  width: 380px;
  height: 100vh;
  position: sticky;
  top: 0;
  background: #232B36;
  border-left: 1px solid rgba(233, 231, 223, 0.12);
  display: flex;
  flex-direction: column;
  color: #E9E7DF;
  flex-shrink: 0;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease, border-color 0.3s ease;
  overflow: hidden;
}

.history-panel-right.collapsed {
  width: 0;
  border-left-color: transparent;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(233, 231, 223, 0.1);
  flex-shrink: 0;
}

.history-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #F5F3EC;
  margin: 0;
  font-family: 'Zilla Slab', serif;
}

.history-header .close-btn {
  background: none;
  border: none;
  color: #9BA7B7;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s ease;
}

.history-header .close-btn:hover {
  color: #FFFFFF;
}

.history-content-right {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-entry {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  color: #E9E7DF;
}

.history-entry .entry-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #9BA7B7;
  font-family: 'IBM Plex Mono', monospace;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 6px;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.history-entry .entry-summary {
  margin-top: 6px;
  line-height: 1.4;
  word-break: break-word;
}

.history-entry .entry-summary strong {
  color: #B7AF9E;
}

.history-entry .detail-toggle {
  margin-top: 8px;
  font-size: 12px;
  color: var(--stamp-red);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.history-entry .entry-details {
  margin-top: 8px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  padding-top: 8px;
  display: none;
  font-size: 12px;
}

.history-entry.open .entry-details {
  display: block;
}

.history-entry .detail-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  gap: 8px;
}

.history-entry .detail-row span:first-child {
  color: #9BA7B7;
}

.history-entry .entry-result {
  font-weight: 700;
}

.history-entry .entry-result.ok {
  color: var(--ok-green);
}

.history-entry .entry-result.bounced {
  color: #d16162;
}

.history-entry .entry-result.error {
  color: var(--stamp-red);
}

.status-line.ok {
  color: var(--ok-green);
}

.status-line.warn {
  color: #B97300;
}

.status-line.err {
  color: var(--stamp-red);
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 34, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  background: var(--paper);
  width: 100%;
  max-width: 420px;
  border-radius: 6px;
  padding: 28px 28px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.modal h2 {
  font-size: 19px;
  margin-bottom: 16px;
}

.modal-row {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.modal-row label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 600;
}

.modal-row .hint {
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
  color: #A79E8C;
}

.modal-row input,
.modal-row select {
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: 'IBM Plex Sans', sans-serif;
  outline: none;
  background: #fff;
}

.modal-row input:focus,
.modal-row select:focus {
  border-color: var(--stamp-red);
}

.modal-split {
  flex-direction: row;
  gap: 12px;
}

.modal-split>div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.modal-actions-right {
  display: flex;
  gap: 10px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--stamp-red);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
}

.text-btn:hover {
  text-decoration: underline;
}

.modal .ghost-btn {
  border-color: var(--paper-line);
  color: var(--ink-soft);
}

.modal .ghost-btn:hover {
  border-color: var(--ink-soft);
  color: var(--ink);
}

.modal-error {
  color: var(--stamp-red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

/* ---------- User Management Table ---------- */
#usersListContainer table {
  width: 100%;
  border-collapse: collapse;
}

#usersListContainer th,
#usersListContainer td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--paper-line);
  font-size: 14px;
}

#usersListContainer th {
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
}

#usersListBody tr:last-child td {
  border-bottom: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 800px) {
  .frame {
    flex-direction: column;
  }

  .ledger {
    width: 100%;
    padding: 20px 16px;
    max-height: 40vh;
  }

  .ledger-list {
    max-height: 160px;
  }

  .desk {
    padding: 24px 16px;
  }

  .paper {
    padding: 28px 22px 24px;
  }

  .field-row {
    flex-direction: column;
    gap: 6px;
    padding: 14px 0;
  }

  .field-row label {
    width: auto;
    padding-top: 0;
  }

  .paper-corner {
    top: 12px;
    right: 16px;
  }

  .stamp {
    width: 70px;
    height: 70px;
  }

  .stamp #stampText {
    font-size: 11px;
  }

  .send-row {
    flex-wrap: wrap;
    row-gap: 10px;
  }
}

@media (max-width: 480px) {
  .ledger-head h1 {
    font-size: 19px;
  }

  .paper {
    padding: 24px 16px 20px;
    max-width: 100%;
  }

  .paper::before {
    height: 4px;
  }

  .send-btn {
    width: 100%;
    text-align: center;
  }

  .status-line {
    width: 100%;
  }

  .modal {
    max-width: 92vw;
    padding: 22px 18px 16px;
    margin: 0 16px;
  }

  .modal-split {
    flex-direction: column;
    gap: 14px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 12px;
    align-items: stretch;
  }

  .modal-actions-right {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-actions-right .send-btn,
  .modal-actions-right .ghost-btn {
    width: 100%;
  }

  .text-btn {
    align-self: center;
  }

  .attach-zone input[type="file"] {
    width: 100%;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .stamp {
    transition: none;
  }
}

/* ---------- From Info and Rich Text Editor styles ---------- */

.compose-from-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.active-sender-placeholder {
  color: #B7AF9E;
  font-style: italic;
  font-size: 14px;
}

.compose-from-info .acc-avatar {
  width: 32px;
  height: 32px;
  border: 1px solid var(--paper-line);
  border-radius: 50%;
  object-fit: cover;
}

.compose-from-info .acc-avatar-placeholder {
  width: 32px;
  height: 32px;
  background: var(--slate-light);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  border-radius: 50%;
}

.compose-from-info .acc-details-horizontal {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.compose-from-info .acc-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}

.compose-from-info .acc-email {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
}

.compose-from-info .smtp-badge {
  background: var(--paper-line);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Sidebar SMTP Badge on alias cards */
.account-card .smtp-badge {
  background: rgba(255, 255, 255, 0.08);
  color: #9BA7B7;
  font-size: 9px;
  font-family: 'IBM Plex Mono', monospace;
  padding: 1px 5px;
  border-radius: 3px;
  margin-top: 4px;
  display: inline-block;
}

/* Rich Editor container and toolbar */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: #F4F0E6;
  border-bottom: 1px solid var(--paper-line);
}

.toolbar-btn {
  background: none;
  border: none;
  border-radius: 3px;
  padding: 5px 8px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.toolbar-btn:hover {
  background: var(--paper-line);
  color: var(--ink);
}

.toolbar-divider {
  width: 1px;
  height: 16px;
  background: var(--paper-line);
  margin: 0 4px;
}

.color-picker-wrapper {
  position: relative;
  display: inline-block;
}

.toolbar-btn-label {
  border-radius: 3px;
  padding: 5px 8px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}

.toolbar-btn-label:hover {
  background: var(--paper-line);
  color: var(--ink);
}

.color-picker-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.rich-editor {
  min-height: 220px;
  padding: 12px 14px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  outline: none;
  overflow-y: auto;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.rich-editor:empty::before {
  content: attr(placeholder);
  color: #B7AF9E;
  pointer-events: none;
  display: block;
}

/* Send History details body content styling */
.detail-body-title {
  margin-top: 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 600;
}

.detail-body-content {
  margin-top: 6px;
  background: #FBFAF7;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  padding: 12px 14px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  text-align: left;
}