:root {
  color-scheme: light;
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-muted: #f3efe9;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #ece7e0;
  --line-soft: #f4eee6;
  --line-strong: #ded6cb;
  --primary: #ea580c;
  --primary-strong: #c2410c;
  --primary-soft: #fff1e8;
  --accent: #16a34a;
  --danger: #d92d20;
  --sidebar: #1c1917;
  --sidebar-soft: #292524;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 8px 24px -12px rgba(28, 25, 23, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes drawerIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(340px, 0.92fr) minmax(420px, 1.08fr);
  background: var(--bg);
  animation: fadeIn 280ms ease-out;
}

.auth-visual {
  padding: 38px;
  color: white;
  background:
    linear-gradient(145deg, rgba(28, 25, 23, 0.98), rgba(41, 37, 36, 0.96)),
    linear-gradient(45deg, rgba(234, 88, 12, 0.2), rgba(22, 163, 74, 0.12));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 42px;
}

.brand-lockup,
.app-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-lockup strong,
.app-logo strong {
  display: block;
  font-size: 16px;
  letter-spacing: 0;
}

.brand-lockup span,
.app-logo span {
  display: block;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

.brand-mark,
.app-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: white;
  font-weight: 900;
}

.auth-preview {
  max-width: 560px;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
  animation: slideUp 420ms ease-out 80ms both;
}

.preview-top {
  height: 12px;
  width: 94px;
  margin-bottom: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.3);
}

.preview-line {
  height: 13px;
  width: 68%;
  margin-bottom: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.preview-line.wide {
  width: 86%;
}

.preview-message {
  display: flex;
  gap: 14px;
  margin-top: 28px;
  padding: 15px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.preview-message > span {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
}

.preview-message strong {
  display: block;
}

.preview-message p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.68);
}

.auth-panel {
  display: grid;
  place-items: center;
  padding: 34px;
}

.auth-card {
  width: min(450px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: slideUp 360ms ease-out both;
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 30px;
  letter-spacing: 0;
}

.auth-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 22px;
  border-radius: 8px;
  background: var(--surface-muted);
}

.mode-tabs button {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

.mode-tabs button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field label {
  color: #44403c;
  font-size: 13px;
  font-weight: 750;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.field textarea {
  min-height: 190px;
  padding: 12px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.14);
}

.domain-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.domain-input input {
  border: 0;
  box-shadow: none;
}

.domain-input span {
  padding: 0 12px;
  color: var(--muted);
  white-space: nowrap;
}

.primary-btn,
.ghost-btn,
.icon-btn,
.compose-btn,
.nav-item {
  min-height: 40px;
  border-radius: 8px;
  font-weight: 800;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.primary-btn {
  width: 100%;
  background: var(--primary);
  color: white;
}

.primary-btn.compact {
  width: auto;
  min-width: 104px;
  padding: 0 18px;
}

.primary-btn:hover,
.compose-btn:hover {
  background: var(--primary-strong);
  transform: translateY(-1px);
}

.ghost-btn {
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: white;
}

.icon-btn {
  width: 40px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
}

.icon-btn:hover {
  background: var(--primary-soft);
  color: var(--primary-strong);
  transform: translateY(-1px);
}

.icon-btn.dark {
  color: rgba(255, 255, 255, 0.76);
}

.icon-btn.dark:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(330px, 420px) minmax(0, 1fr);
  overflow: hidden;
  animation: fadeIn 220ms ease-out;
}

.sidebar {
  padding: 18px;
  background: var(--sidebar);
  color: white;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: slideInLeft 260ms ease-out both;
}

.compose-btn {
  width: 100%;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

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

.nav-item {
  width: 100%;
  padding: 0 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.68);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--sidebar-soft);
  color: white;
  transform: translateX(2px);
}

.account-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.account-email {
  display: block;
  overflow: hidden;
  color: white;
  font-size: 13px;
  font-weight: 850;
  text-overflow: ellipsis;
}

.account-plan {
  display: block;
  margin: 3px 0 12px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 12px;
}

.mail-list-pane {
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 260ms ease-out 40ms both;
}

.pane-header {
  min-height: 78px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pane-header h2 {
  margin: 0;
  font-size: 22px;
}

.pane-header span {
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  min-height: 42px;
  margin: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  gap: 9px;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--ink);
}

.message-list {
  overflow: auto;
}

.message-row {
  width: 100%;
  min-height: 94px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  transition: background-color 140ms ease, transform 140ms ease;
}

.message-row:hover,
.message-row.active {
  background: var(--primary-soft);
  transform: translateX(2px);
}

.message-row.unread .row-from,
.message-row.unread .row-subject {
  font-weight: 900;
}

.row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row-from,
.row-subject,
.row-snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-from {
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.row-time {
  color: var(--muted);
  font-size: 12px;
}

.row-subject {
  margin-top: 8px;
  color: #2d3344;
}

.row-snippet {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.read-pane {
  background: #fbfcff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 300ms ease-out 80ms both;
}

.read-header {
  min-height: 78px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.read-folder {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.read-header h2 {
  margin: 0;
  max-width: 760px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 22px;
}

.message-body {
  padding: 24px;
  overflow: auto;
}

.message-meta {
  max-width: 900px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.message-meta > div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.message-meta > div:last-child {
  border-bottom: 0;
}

.message-meta strong {
  color: #57534e;
}

.message-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.body-content {
  max-width: 900px;
  min-height: 260px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.62;
  white-space: pre-wrap;
  animation: slideUp 240ms ease-out both;
}

.attachment-list {
  max-width: 900px;
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.attachment-item {
  min-height: 54px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.attachment-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.attachment-item strong,
.attachment-item small {
  display: block;
}

.attachment-item small {
  margin-top: 2px;
  color: var(--muted);
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 22px;
}

.empty-state p {
  margin: 0;
}

.compose-drawer {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: none;
  flex-direction: column;
  z-index: 10;
}

.compose-drawer.open {
  display: flex;
  animation: drawerIn 220ms ease-out both;
}

.compose-header {
  min-height: 48px;
  padding: 0 12px 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--sidebar);
  color: white;
}

.compose-body {
  padding: 16px;
  overflow: auto;
}

.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.file-label {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-strong);
  font-weight: 800;
}

.file-label input {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  min-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--sidebar);
  color: white;
  box-shadow: var(--shadow);
  display: none;
  z-index: 20;
}

.toast.show {
  display: block;
  animation: toastIn 180ms ease-out both;
}

.admin-shell {
  grid-template-columns: 248px minmax(330px, 440px) minmax(0, 1fr);
}

.admin-users-pane,
.admin-detail-pane {
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 260ms ease-out both;
}

.admin-users-pane {
  border-right: 1px solid var(--line);
}

.admin-user-list {
  overflow: auto;
  padding: 8px;
}

.admin-user-row {
  width: 100%;
  min-height: 78px;
  padding: 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  text-align: left;
  transition: background-color 140ms ease, transform 140ms ease;
}

.admin-user-row:hover,
.admin-user-row.active {
  background: var(--primary-soft);
  transform: translateX(2px);
}

.pfp {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 900;
}

.admin-user-row strong,
.admin-user-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-row small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.admin-user-row em {
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.admin-detail-body {
  overflow: auto;
  padding: 18px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.admin-card {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  animation: slideUp 240ms ease-out both;
}

.admin-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.kv {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}

.kv:last-child {
  border-bottom: 0;
}

.kv strong {
  color: var(--muted);
}

.kv span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-mail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.admin-tabs {
  padding-top: 0;
  border-bottom: 1px solid var(--line);
}

.admin-mail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  min-height: 460px;
}

.admin-message-list {
  border-right: 1px solid var(--line);
  overflow: auto;
}

.admin-message-preview {
  min-width: 0;
  padding: 18px;
  overflow: auto;
  background: var(--bg);
}

.admin-preview-head {
  margin-bottom: 14px;
}

.admin-preview-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-preview-head h3 {
  margin: 4px 0 0;
  font-size: 20px;
}

.hidden {
  display: none !important;
}

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

  .auth-visual {
    min-height: 280px;
  }

  .app-shell {
    grid-template-columns: 76px minmax(300px, 380px) minmax(0, 1fr);
  }

  .sidebar {
    padding: 12px;
  }

  .app-logo strong,
  .app-logo span,
  .nav-item span,
  .compose-btn span,
  .account-card {
    display: none;
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
  }

  .compose-btn {
    width: auto;
    padding: 0 12px;
  }

  .nav-list {
    grid-template-columns: repeat(2, 42px);
    display: grid;
  }

  .mail-list-pane,
  .read-pane,
  .admin-detail-pane {
    min-height: 52vh;
  }

  .admin-grid,
  .admin-mail-grid {
    grid-template-columns: 1fr;
  }

  .read-header h2 {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
