:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #fff;
  --text: #17211b;
  --muted: #66736b;
  --line: #dce5df;
  --green: #176b45;
  --green-dark: #0f5133;
  --green-soft: #e8f5ee;
  --red: #ad2e24;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: inherit; }
button, input, select { font: inherit; }
button, .button {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .7rem 1rem;
  text-decoration: none;
}
button:hover, .button:hover { border-color: #aebdb4; }
button:disabled { cursor: wait; opacity: .6; }
.primary { background: var(--green); border-color: var(--green); color: white; }
.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }

.topbar {
  align-items: center;
  background: #12271c;
  color: white;
  display: flex;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
}
.brand { font-size: 1.15rem; font-weight: 800; text-decoration: none; }
.topbar nav { align-items: center; display: flex; gap: 1.25rem; }
.topbar nav a, .link-button { color: #dcebe2; font-size: .92rem; text-decoration: none; }
.topbar nav form { margin: 0; }
.link-button { background: none; border: 0; padding: 0; }

.container { margin: 0 auto; max-width: 1180px; min-height: calc(100vh - 130px); padding: 36px 24px 60px; }
footer { color: var(--muted); font-size: .82rem; padding: 0 24px 28px; text-align: center; }
h1 { font-size: 1.8rem; margin: .3rem 0; }
h2 { font-size: 1.05rem; margin: 0 0 1rem; }
.muted { color: var(--muted); margin: .25rem 0; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 2px 8px rgba(20, 50, 32, .04); padding: 24px; }
.page-heading { align-items: center; display: flex; justify-content: space-between; margin-bottom: 24px; gap: 20px; }
.heading-actions { display: flex; gap: 10px; }
.back { color: var(--green); display: inline-block; font-size: .9rem; margin-bottom: 8px; text-decoration: none; }
.notice { align-items: center; border-radius: 10px; display: flex; gap: 10px; margin-bottom: 20px; padding: 14px 18px; }
.notice.success { background: var(--green-soft); color: var(--green-dark); }
.notice.info { background: #eaf2fb; color: #24527a; }
.notice.error { background: #fdecea; color: #8a211a; }
.toast-container {
  display: grid;
  gap: 10px;
  max-width: min(420px, calc(100vw - 28px));
  position: fixed;
  right: 20px;
  top: 82px;
  width: max-content;
  z-index: 1000;
}
.toast {
  box-shadow: 0 10px 30px rgba(20, 45, 30, .18);
  margin: 0;
  transition: opacity .2s ease, transform .2s ease;
}
.toast-leaving { opacity: 0; transform: translateX(20px); }
.secret { margin-top: 8px; }
.secret code { background: white; border: 1px solid #bdd8c7; border-radius: 5px; padding: 3px 7px; }

label { color: #34423a; display: grid; font-size: .88rem; font-weight: 650; gap: 7px; }
input, select {
  background: white;
  border: 1px solid #cbd7cf;
  border-radius: 8px;
  color: var(--text);
  min-height: 43px;
  padding: 9px 11px;
}
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px #dcefe5; outline: none; }
.stack { display: grid; gap: 18px; }
.inline-form { align-items: end; display: grid; gap: 14px; grid-template-columns: 2fr 1.3fr auto; }
.field-row { align-items: end; display: flex; gap: 10px; }
.at { padding-bottom: 12px; }
small { color: var(--muted); font-weight: 400; }

.auth-card { margin: 8vh auto 0; max-width: 420px; }
.auth-card h1, .auth-card > p { text-align: center; }
.cow { font-size: 3rem; text-align: center; }
.mailbox-search { margin-top: 24px; max-width: 430px; }
.mailbox-search input { width: 100%; }
.mailbox-grid { display: grid; gap: 14px; margin-top: 20px; }
.mailbox-card {
  align-items: center;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(150px, .8fr) minmax(220px, 1.4fr) auto;
}
.mailbox-name-cell { align-items: center; display: flex; gap: 9px; min-width: 0; }
.mailbox-name-cell strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-address { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-name-button { background: none; border: 0; color: var(--green); font-size: .78rem; padding: 3px; white-space: nowrap; }
.inline-name-form { align-items: center; display: flex; gap: 6px; }
.inline-name-form input { min-width: 100px; width: 100%; }
.inline-name-form button { padding: .55rem .7rem; }
.actions { align-items: center; display: flex; gap: 9px; }
.actions form { margin: 0; }
.unread-badge {
  align-items: center;
  background: white;
  border-radius: 999px;
  color: var(--green-dark);
  display: inline-flex;
  font-size: .75rem;
  font-weight: 800;
  justify-content: center;
  margin-left: 8px;
  min-width: 22px;
  padding: 2px 6px;
}
.danger-link { background: none; border: 0; color: var(--red); padding: .5rem; }
.empty { color: var(--muted); padding: 50px 20px; text-align: center; }
.empty h2 { color: var(--text); }

.tabs { background: #e5ebe7; border-radius: 9px; display: flex; padding: 4px; }
.tabs a { border-radius: 6px; color: var(--muted); padding: 8px 16px; text-decoration: none; }
.tabs a.active { background: white; box-shadow: 0 1px 4px rgba(0,0,0,.08); color: var(--text); font-weight: 700; }
.message-list { padding: 0; overflow: hidden; }
.message-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: 10px minmax(150px, 1fr) minmax(240px, 2.2fr) 180px;
  padding: 15px 18px;
  text-decoration: none;
}
.message-row:last-child { border-bottom: 0; }
.message-row:hover { background: #f7faf8; }
.message-row.unread { background: #f0faf5; font-weight: 700; }
.status-dot { background: transparent; border-radius: 50%; height: 7px; width: 7px; }
.unread .status-dot { background: var(--green); }
.sender, .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-row time { color: var(--muted); font-size: .82rem; text-align: right; }
.pagination { align-items: center; display: flex; gap: 12px; justify-content: center; padding: 22px; }

.email-detail { padding: 0; overflow: hidden; }
.email-header { align-items: flex-start; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: 24px; gap: 20px; }
.email-header h1 { font-size: 1.4rem; margin: 0 0 16px; }
dl { display: grid; gap: 6px; margin: 0; }
dl div { display: grid; font-size: .9rem; gap: 10px; grid-template-columns: 55px 1fr; }
dt { color: var(--muted); }
dd { margin: 0; word-break: break-word; }
.attachments { background: #f8faf9; border-bottom: 1px solid var(--line); padding: 18px 24px; }
.attachments h2 { margin-bottom: 10px; }
.attachment { align-items: center; border: 1px solid var(--line); border-radius: 8px; display: inline-flex; gap: 16px; margin: 0 8px 8px 0; padding: 9px 12px; text-decoration: none; }
.email-body { line-height: 1.6; min-height: 260px; overflow-wrap: anywhere; padding: 28px; }
.email-body pre { font-family: inherit; white-space: pre-wrap; }
.email-body table { border-collapse: collapse; max-width: 100%; }
.email-body img { display: none; }
.form-card { max-width: 650px; }

body.modal-open { overflow: hidden; }
.modal { align-items: center; display: flex; inset: 0; justify-content: center; padding: 24px; position: fixed; z-index: 900; }
.modal[hidden] { display: none; }
.modal-backdrop { background: rgba(10, 25, 16, .58); inset: 0; position: absolute; }
.modal-dialog {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  max-width: 1120px;
  overflow: hidden;
  position: relative;
  width: 94vw;
}
.modal-header { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: 18px 22px; }
.modal-header h2 { margin: 0; }
.modal-close { background: none; border: 0; font-size: 1.8rem; line-height: 1; padding: 5px 9px; }
.modal-toolbar { align-items: center; background: #f8faf9; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 20px; }
.tabs button { background: transparent; border: 0; border-radius: 6px; color: var(--muted); padding: 8px 16px; }
.tabs button.active { background: white; box-shadow: 0 1px 4px rgba(0,0,0,.08); color: var(--text); font-weight: 700; }
.select-all { align-items: center; display: flex; font-weight: 500; gap: 7px; margin-left: auto; }
.select-all input { min-height: 0; }
.danger-button { border-color: #e6b8b4; color: var(--red); }
.modal-content { min-height: 300px; overflow: auto; }
.modal-loading, .modal-empty { color: var(--muted); padding: 70px 24px; text-align: center; }
.error-text { color: var(--red); }
.modal-message-row { align-items: center; border-bottom: 1px solid var(--line); display: grid; gap: 12px; grid-template-columns: 22px 1fr; padding: 0 18px; }
.modal-message-row.unread { background: #f0faf5; font-weight: 700; }
.modal-message-row > input { min-height: 0; }
.modal-message-open {
  background: transparent;
  border: 0;
  border-radius: 0;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(150px, .8fr) minmax(240px, 1.8fr) 150px;
  min-width: 0;
  padding: 15px 0;
  text-align: left;
}
.modal-message-open:hover { border-color: transparent; }
.modal-sender, .modal-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-message-open time { color: var(--muted); font-size: .82rem; text-align: right; }
.modal-pagination { align-items: center; display: flex; gap: 12px; justify-content: center; padding: 18px; }
.modal-back-button { color: var(--green); margin: 18px 22px 0; }
.modal-email-meta { border-bottom: 1px solid var(--line); padding: 18px 22px; }
.modal-attachments { background: #f8faf9; border-bottom: 1px solid var(--line); padding: 14px 22px; }
.modal-email-body { line-height: 1.6; min-height: 260px; overflow-wrap: anywhere; padding: 24px; }
.modal-email-body pre { font-family: inherit; white-space: pre-wrap; }
.modal-email-body table { border-collapse: collapse; max-width: 100%; }
.modal-email-body img { display: none; }
.confirm-dialog { align-items: center; display: flex; inset: 0; justify-content: center; padding: 20px; position: fixed; z-index: 1100; }
.confirm-dialog[hidden] { display: none; }
.confirm-backdrop { background: rgba(10, 20, 14, .66); inset: 0; position: absolute; }
.confirm-card {
  background: white;
  border-radius: 14px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .3);
  max-width: 440px;
  padding: 24px;
  position: relative;
  width: 100%;
}
.confirm-card h2 { margin-bottom: 10px; }
.confirm-card p { color: var(--muted); line-height: 1.55; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.danger-primary { background: var(--red); border-color: var(--red); color: white; }
.danger-primary:hover { background: #8e251d; border-color: #8e251d; }

@media (max-width: 760px) {
  .container { padding: 24px 14px 48px; }
  .toast-container { left: 14px; right: 14px; top: 74px; width: auto; }
  .topbar { padding: 0 16px; }
  .topbar nav a { display: none; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { flex-wrap: wrap; }
  .mailbox-card { align-items: stretch; grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .actions { flex-wrap: wrap; }
  .message-row { grid-template-columns: 8px 1fr auto; }
  .message-row .subject { grid-column: 2 / 4; }
  .email-header { flex-direction: column; }
  .modal { padding: 0; }
  .modal-dialog { border-radius: 0; height: 100vh; max-height: 100vh; width: 100vw; }
  .select-all { margin-left: 0; }
  .modal-message-open { grid-template-columns: 1fr auto; }
  .modal-subject { grid-column: 1 / 3; }
}
