:root {
  color-scheme: light;
  --paper: #f4f7f5;
  --surface: #fff;
  --ink: #17201c;
  --muted: #68736e;
  --line: #dce3df;
  --accent: #146c49;
  --accent-hover: #0d593b;
  --accent-soft: #e8f4ee;
  --danger: #b42318;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
}
button,
input {
  font: inherit;
  letter-spacing: 0;
}
button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}
button:disabled {
  cursor: wait;
  opacity: 0.65;
}
input {
  width: 100%;
  height: 44px;
  border: 1px solid #c8d2cd;
  border-radius: 6px;
  padding: 0 12px;
}
input:focus {
  border-color: var(--accent);
  outline: 3px solid rgb(20 108 73 / 15%);
}
label {
  display: grid;
  gap: 7px;
  color: #46524c;
  font-size: 12px;
  font-weight: 700;
}
h1,
h2,
h3,
p {
  margin: 0;
}
.hidden {
  display: none !important;
}
.primary {
  background: var(--accent);
  color: #fff;
}
.primary:hover {
  background: var(--accent-hover);
}
.quiet {
  border-color: var(--line);
  background: #fff;
  color: #43504a;
}
.quiet:hover {
  background: #eef3f0;
}
.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}
.login-panel {
  display: grid;
  width: min(100%, 380px);
  gap: 19px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 48px rgb(23 32 28 / 10%);
  padding: 32px;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
}
.brand-lockup h1 {
  font-size: 22px;
}
.brand-lockup p,
.brand-lockup span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 21px;
  font-weight: 800;
}
.form-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
}
.app-header {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  padding: 9px max(18px, calc((100vw - 1080px) / 2));
}
.brand-lockup.compact .brand-mark {
  width: 38px;
  height: 38px;
  flex-basis: 38px;
  font-size: 17px;
}
.brand-lockup.compact > div:last-child {
  display: grid;
}
.brand-lockup.compact span {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  overflow-wrap: anywhere;
}
.header-actions {
  display: flex;
  gap: 7px;
}
.mail-main {
  width: min(1080px, calc(100% - 36px));
  margin: 0 auto;
  padding: 34px 0 70px;
}
.mail-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
}
.mail-heading h1 {
  font-size: 21px;
}
.mail-heading > div {
  display: grid;
  gap: 4px;
}
.mail-heading span {
  color: var(--muted);
  font-size: 12px;
}
.live {
  display: flex;
  align-items: center;
  gap: 7px;
}
.live i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #218c5c;
}
.empty-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  align-content: center;
  gap: 7px;
  border: 1px dashed #c8d3cd;
  border-radius: 7px;
  color: var(--muted);
}
.empty-state strong {
  color: var(--ink);
  font-size: 16px;
}
.mail-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.mail-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.mail-table th,
.mail-table td {
  border-bottom: 1px solid var(--line);
  padding: 13px 15px;
  text-align: left;
  vertical-align: middle;
}
.mail-table th {
  background: #fafcfb;
  color: var(--muted);
  font-size: 11px;
}
.mail-table th:first-child {
  width: 38%;
}
.mail-table th:nth-child(2) {
  width: 30%;
}
.mail-table th:nth-child(3) {
  width: 22%;
}
.mail-table th:last-child {
  width: 10%;
}
.mail-table tbody tr {
  cursor: pointer;
}
.mail-table tbody tr:hover {
  background: var(--accent-soft);
}
.mail-table tbody tr:last-child td {
  border-bottom: 0;
}
.cell-main,
.cell-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
dialog {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 80px rgb(23 32 28 / 24%);
  padding: 0;
}
dialog::backdrop {
  background: rgb(15 25 21 / 46%);
}
.dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 18px 22px;
}
.dialog-header span {
  color: var(--muted);
  font-size: 11px;
}
.dialog-header h2 {
  max-width: 720px;
  margin-top: 4px;
  font-size: 18px;
  overflow-wrap: anywhere;
}
.icon-button {
  display: grid;
  width: 36px;
  min-height: 36px;
  place-items: center;
  border-color: var(--line);
  background: #fff;
  padding: 0;
  font-size: 22px;
}
.message-meta {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 15px 22px;
  color: var(--muted);
  font-size: 12px;
}
.message-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}
.message-meta-row strong {
  color: var(--ink);
  overflow-wrap: anywhere;
  text-align: right;
}
.extract-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 22px 0;
}
.extract-chip,
.attachment-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid #b7d4c7;
  border-radius: 5px;
  background: var(--accent-soft);
  color: #124c36;
  padding: 6px 10px;
  text-decoration: none;
}
.message-tabs {
  display: flex;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  margin-top: 14px;
  padding: 0 22px;
}
.tab {
  min-height: 40px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
}
.tab.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}
.message-text {
  min-height: 280px;
  max-height: 52vh;
  margin: 0;
  overflow: auto;
  padding: 22px;
  font:
    13px/1.65 ui-monospace,
    "Cascadia Mono",
    Consolas,
    monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-html {
  width: 100%;
  height: 52vh;
  border: 0;
  background: #fff;
}
.attachment-section {
  border-top: 1px solid var(--line);
  padding: 18px 22px 24px;
}
.attachment-section h3 {
  margin-bottom: 10px;
}
#attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.toast {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: 20px;
  max-width: min(380px, calc(100vw - 40px));
  transform: translateY(20px);
  border-radius: 6px;
  background: #19231f;
  color: #fff;
  padding: 12px 16px;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.error {
  background: var(--danger);
}
@media (max-width: 680px) {
  .app-header {
    padding: 9px 12px;
  }
  .brand-lockup.compact span {
    max-width: 48vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mail-main {
    width: calc(100% - 24px);
    padding-top: 24px;
  }
  .mail-table th:nth-child(2),
  .mail-table td:nth-child(2),
  .mail-table th:last-child,
  .mail-table td:last-child {
    display: none;
  }
  .mail-table th:first-child {
    width: 62%;
  }
  .mail-table th:nth-child(3) {
    width: 38%;
  }
  .empty-state {
    min-height: 260px;
  }
}
@media (max-width: 430px) {
  .login-panel {
    padding: 24px 20px;
  }
  .brand-lockup.compact .brand-mark {
    display: none;
  }
  .header-actions button {
    padding: 0 9px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}

/* Keep the customer mail view calm: hierarchy comes from size and colour first,
   with weight reserved for labels, headings, and the message subject. */
body {
  font-weight: 400;
  line-height: 1.5;
}
button {
  font-size: 13px;
  font-weight: 600;
}
label {
  font-weight: 500;
}
input {
  font-size: 14px;
  font-weight: 400;
}
h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.35;
}
.brand-lockup p,
.brand-lockup span,
.mail-heading span,
.cell-sub {
  font-weight: 400;
}
.mail-table th {
  font-weight: 500;
}
.mail-table td:first-child .cell-main {
  font-weight: 600;
}
.mail-table td:nth-child(2) .cell-main {
  font-weight: 500;
}
.message-meta-row strong {
  font-weight: 500;
}
.extract-chip,
.attachment-link {
  font-weight: 500;
}
.tab {
  font-weight: 500;
}
.tab.active {
  font-weight: 600;
}
