:root {
  --ink: #1e2424;
  --muted: #687170;
  --paper: #f4f1ea;
  --panel: #fffdf8;
  --line: #ded9cf;
  --green: #1f6557;
  --green-dark: #174d43;
  --orange: #d9673f;
  --shadow: 0 20px 60px rgba(44, 50, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 7% 0%, rgba(211, 227, 217, 0.9), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: "Aptos", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 42px;
  line-height: 1.05;
}

.login-intro,
.security-note {
  color: var(--muted);
  line-height: 1.6;
}

.login-intro {
  margin: 16px 0 25px;
  font-size: 14px;
}

.login-card form,
.login-card label {
  display: grid;
}

.login-card form {
  gap: 17px;
}

.login-card label {
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  background: white;
  color: var(--ink);
  outline: none;
}

.login-card input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 101, 87, 0.1);
}

.security-note {
  margin: -4px 0 0;
  font-size: 12px;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.primary-button {
  padding: 14px 20px;
  background: var(--green);
  color: white;
  font-weight: 700;
}

.primary-button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.secondary-button {
  padding: 11px 14px;
  background: transparent;
  color: var(--muted);
}

.ai-status {
  border: 1px solid #d9d4ca;
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 253, 248, 0.7);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.ai-status.ready {
  border-color: #b9d6ca;
  background: #e7f2ed;
  color: var(--green);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: #a83e2e;
  font-size: 12px;
  line-height: 1.5;
}

.shell {
  width: min(1500px, calc(100% - 48px));
  margin: 0 auto;
  padding: 44px 0 28px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 34px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 10px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.19em;
}

h1 {
  max-width: 720px;
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(42px, 5vw, 74px);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.subtitle {
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.connection {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4b9c6d;
  box-shadow: 0 0 0 5px rgba(75, 156, 109, 0.12);
}

#refreshButton {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  background: var(--green);
  color: white;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(31, 101, 87, 0.18);
}

#refreshButton:hover {
  background: var(--green-dark);
}

#refreshButton:disabled {
  opacity: 0.65;
  cursor: wait;
}

.spinning .refresh-icon {
  display: inline-block;
  animation: spin 0.9s linear infinite;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card {
  min-height: 164px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 253, 248, 0.82);
  backdrop-filter: blur(14px);
}

.stat-primary {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat-primary .stat-label,
.stat-primary small {
  color: rgba(255, 255, 255, 0.72);
}

.stat-card strong {
  display: block;
  margin: 15px 0 7px;
  font-family: Georgia, serif;
  font-size: 48px;
  font-weight: 500;
  line-height: 1;
}

.stat-card small {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(310px, 0.75fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.main-panel {
  min-height: 590px;
  padding: 28px;
}

.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.panel-heading.compact {
  margin-bottom: 22px;
}

.panel-heading h2 {
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 28px;
  font-weight: 500;
}

.filters {
  display: flex;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f4f1e9;
}

.filter {
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.filter.active {
  background: var(--ink);
  color: white;
}

.mail-list {
  display: grid;
  gap: 10px;
}

.mail-item {
  position: relative;
  display: grid;
  grid-template-columns: 4px 1fr;
  gap: 17px;
  overflow: hidden;
  padding: 18px 20px 18px 0;
  border: 1px solid #e6e1d7;
  border-radius: 16px;
  background: #fffefa;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.mail-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 30px rgba(35, 44, 40, 0.08);
}

.priority-line {
  border-radius: 0 6px 6px 0;
  background: #aaa;
}

.priority-line.urgent {
  background: #c94831;
}

.priority-line.high {
  background: #d8842f;
}

.priority-line.medium {
  background: #4f8374;
}

.mail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.mail-meta time {
  margin-left: auto;
}

.priority-badge,
.category-badge {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eeebe4;
}

.priority-badge.urgent {
  background: #fde4dd;
  color: #a93422;
}

.priority-badge.high {
  background: #f9ead8;
  color: #9b5b1e;
}

.mail-item h3 {
  margin: 10px 0 4px;
  font-size: 16px;
  font-weight: 700;
}

.sender,
.snippet {
  margin: 0;
}

.sender {
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.snippet {
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.side-column {
  display: grid;
  align-content: start;
  gap: 16px;
}

.category-panel,
.completed-panel {
  padding: 25px;
}

.category-list {
  display: grid;
  gap: 18px;
}

.category-row {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.category-row:hover .category-top {
  color: var(--green);
}

.category-row.active {
  margin: -8px;
  padding: 8px;
  border-radius: 12px;
  background: #f0eee7;
}

.summary {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f3f0e8;
  color: #4f5856;
  font-size: 13px;
  line-height: 1.6;
}

.summary-source {
  border-radius: 999px;
  padding: 4px 8px;
  background: #f0ede6;
  color: var(--muted);
}

.summary-source.ready {
  background: #e0efe8;
  color: var(--green);
}

.summary-source.warning {
  background: #f9ead8;
  color: #9b5b1e;
}

.classification-state {
  border-radius: 999px;
  padding: 4px 8px;
  background: #ece9e2;
  color: var(--muted);
}

.original-mail,
.reply-box {
  margin-top: 10px;
  border: 1px solid #e3ded4;
  border-radius: 10px;
  background: #fffefa;
}

.original-mail summary,
.reply-box summary {
  padding: 10px 12px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.original-mail pre {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  border-top: 1px solid #ebe6dd;
  padding: 14px;
  color: #4f5856;
  font-family: "Aptos", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.mail-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-top: 10px;
}

.mail-actions label,
.reply-box label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.mail-actions select,
.reply-box textarea {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  background: white;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.confirm-category-button,
.send-reply-button {
  border: 0;
  border-radius: 9px;
  padding: 10px 13px;
  background: var(--green);
  color: white;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.confirm-category-button:disabled,
.send-reply-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.reply-box[open] {
  padding-bottom: 13px;
}

.reply-box label,
.reply-box .send-reply-button,
.reply-note {
  margin-right: 12px;
  margin-left: 12px;
}

.reply-box textarea {
  min-height: 120px;
  resize: vertical;
}

.reply-box .send-reply-button {
  margin-top: 10px;
}

.reply-note {
  margin-top: 8px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 11px;
}

.category-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.category-top span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-top i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.category-track {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: #ebe7de;
}

.category-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.completed-list {
  display: grid;
  gap: 10px;
}

.completed-item {
  display: grid;
  grid-template-columns: 25px 1fr;
  gap: 10px;
  align-items: start;
  padding-bottom: 11px;
  border-bottom: 1px solid #ebe6dd;
}

.completed-item:last-child {
  padding-bottom: 0;
  border: 0;
}

.check {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #dcebe4;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

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

.completed-item strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.completed-item small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.loading-card,
.empty-state {
  display: grid;
  justify-items: center;
  min-height: 360px;
  align-content: center;
  color: var(--muted);
  text-align: center;
}

.loading-card span {
  width: 70%;
  height: 12px;
  margin-bottom: 10px;
  border-radius: 99px;
  background: linear-gradient(90deg, #ede9e1, #f9f7f1, #ede9e1);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.loading-card span:nth-child(2) {
  width: 58%;
}

.loading-card span:nth-child(3) {
  width: 44%;
}

.loading-card p {
  margin-top: 20px;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #dfece7;
  color: var(--green);
  font-size: 24px;
}

.error-state .empty-mark {
  background: #f9e3dd;
  color: #af3f2d;
}

.empty-state h3 {
  margin: 16px 0 5px;
  color: var(--ink);
}

.empty-state p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 4px 0;
  color: var(--muted);
  font-size: 11px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  transform: translateY(20px);
  border-radius: 12px;
  padding: 13px 18px;
  background: var(--ink);
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  background: #a83e2e;
}

.settings-button,
.icon-button,
.add-category-button,
.secondary-action,
.remove-category-button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.settings-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: #f4f1e9;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 28, 26, 0.54);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(820px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  background: var(--panel);
  box-shadow: 0 30px 90px rgba(20, 28, 26, 0.24);
}

.modal-heading {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.modal-heading h2 {
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 30px;
  font-weight: 500;
}

.modal-heading p:not(.section-kicker) {
  max-width: 620px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.icon-button {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #eeebe4;
  color: var(--ink);
  font-size: 22px;
}

.category-editor {
  display: grid;
  gap: 12px;
}

.category-edit-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(130px, 0.55fr) minmax(240px, 1.25fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid #e6e1d7;
  border-radius: 15px;
  background: #fffefa;
}

.category-edit-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.category-edit-row input,
.category-edit-row textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  outline: none;
  resize: vertical;
}

.category-edit-row input:focus,
.category-edit-row textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 101, 87, 0.09);
}

.remove-category-button {
  margin-bottom: 2px;
  border-radius: 9px;
  padding: 10px;
  background: #f8e8e3;
  color: #a83e2e;
  font-size: 12px;
}

.add-category-button {
  margin-top: 14px;
  border-radius: 10px;
  padding: 11px 14px;
  background: #e5eee9;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.settings-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: #a83e2e;
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.modal-actions .primary-button {
  padding: 12px 18px;
}

.secondary-action {
  border-radius: 999px;
  padding: 12px 18px;
  background: #eeebe4;
  color: var(--ink);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .side-column {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .login-card {
    padding: 30px 24px;
  }

  .login-card h1 {
    font-size: 36px;
  }

  .shell {
    width: min(100% - 24px, 1500px);
    padding-top: 26px;
  }

  h1 {
    font-size: 44px;
  }

  .top-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .ai-status {
    width: max-content;
  }

  #refreshButton {
    justify-content: center;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card {
    min-height: 135px;
    padding: 18px;
  }

  .stat-card strong {
    font-size: 38px;
  }

  .main-panel {
    padding: 20px;
  }

  .mail-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .confirm-category-button {
    align-self: start;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .filters {
    width: 100%;
    justify-content: space-between;
  }

  .side-column {
    grid-template-columns: 1fr;
  }

  footer {
    flex-direction: column;
    gap: 3px;
  }

  .modal {
    align-items: end;
    padding: 0;
  }

  .modal-card {
    max-height: 94vh;
    border-radius: 24px 24px 0 0;
    padding: 23px 18px;
  }

  .category-edit-row {
    grid-template-columns: 1fr;
  }

  .remove-category-button {
    justify-self: start;
  }
}
