:root {
  color-scheme: light;
  --ink: #24334a;
  --muted: #8c9db6;
  --blue: #2f74ef;
  --blue-dark: #1763e6;
  --cyan: #0ba6d9;
  --line: rgba(255, 255, 255, 0.82);
  --panel: rgba(248, 252, 255, 0.66);
  --field: rgba(255, 255, 255, 0.76);
  --shadow: 0 14px 40px rgba(56, 104, 173, 0.11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 18% 5%, rgba(193, 218, 255, 0.86), transparent 37%),
    radial-gradient(circle at 76% 35%, rgba(210, 245, 255, 0.54), transparent 32%),
    linear-gradient(135deg, #e5efff 0%, #eaf8ff 48%, #e9edff 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.page-shell { padding: 12px; min-height: 100vh; }

.glass-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.topbar {
  min-height: 77px;
  padding: 14px 22px;
  border-radius: 20px;
  display: flex;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  margin-right: 13px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #277ff0, #03aed8);
  box-shadow: 0 7px 16px rgba(21, 138, 216, .28);
}

.brand-mark svg { width: 27px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.brand-copy h1 { margin: 0 0 3px; font-size: 18px; line-height: 1.2; }
.brand-copy p { margin: 0; color: var(--muted); font-size: 12px; }

.ready-pill {
  margin-left: auto;
  padding: 8px 15px;
  border: 1px solid rgba(29, 200, 155, .23);
  border-radius: 999px;
  color: #20ad86;
  background: rgba(224, 251, 245, .74);
  font-size: 12px;
  font-weight: 600;
}
.ready-pill span { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #21c594; }

.workspace { display: grid; grid-template-columns: 362px minmax(0, 1fr); gap: 14px; margin-top: 14px; }
.mailbox-panel { min-height: calc(100vh - 115px); padding: 17px; border-radius: 20px; }
.panel-heading, .heading-label { display: flex; align-items: center; }
.panel-heading { justify-content: space-between; margin-bottom: 13px; }
.heading-label svg { width: 18px; margin-right: 10px; fill: none; stroke: #8498b5; stroke-width: 1.7; }
.heading-label h2 { margin: 0; font-size: 14px; }
.panel-actions { display: flex; align-items: center; gap: 10px; }
.select-all { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; cursor: pointer; user-select: none; }
.select-all input { accent-color: var(--blue); }
.count-badge { min-width: 27px; padding: 5px 8px; border-radius: 11px; color: var(--blue); background: #dfeaff; text-align: center; font-size: 11px; font-weight: 700; }

.input-wrap, .select-wrap {
  height: 36px;
  display: flex;
  align-items: center;
  border: 1px solid rgba(145, 169, 202, .22);
  border-radius: 10px;
  color: #8ca0bc;
  background: var(--field);
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.input-wrap:focus-within, .select-wrap:focus-within { border-color: rgba(47, 116, 239, .48); box-shadow: 0 0 0 3px rgba(47, 116, 239, .1); background: #fff; }
.input-wrap svg { flex: 0 0 auto; width: 17px; margin: 0 12px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.input-wrap input, .select-wrap select { width: 100%; height: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 12px; }
.input-wrap input::placeholder { color: #99aac1; }
.compact-input { width: 100%; margin-bottom: 13px; }

.button {
  height: 36px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 650;
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); filter: saturate(1.08); }
.button:active:not(:disabled) { transform: translateY(0); }
.button svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.button.wide { width: 100%; }
.button.primary { color: #fff; background: linear-gradient(135deg, #3c80f3, #2469e9); box-shadow: 0 7px 15px rgba(38, 105, 233, .24); }
.button.secondary { margin-top: 9px; color: #5b6a7d; border-color: rgba(133, 155, 184, .2); background: rgba(255, 255, 255, .65); }
.button.cyan { color: #fff; background: linear-gradient(135deg, #1598ec, #03a7ce); box-shadow: 0 7px 15px rgba(2, 153, 203, .22); }

.sidebar-empty { min-height: 235px; display: flex; align-items: center; justify-content: center; flex-direction: column; color: #a4b3c8; }
.sidebar-empty svg { width: 50px; margin-bottom: 14px; fill: none; stroke: #cedbef; stroke-width: 1.7; }
.sidebar-empty strong { margin-bottom: 7px; font-size: 12px; font-weight: 500; }
.sidebar-empty span { font-size: 12px; }
.mailbox-list { margin-top: 12px; display: grid; gap: 8px; }
.mailbox-item { padding: 10px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; border: 1px solid rgba(131, 160, 199, .2); border-radius: 11px; background: rgba(255,255,255,.5); }
.mailbox-item input { accent-color: var(--blue); }
.mailbox-info { min-width: 0; display: grid; gap: 2px; }
.mailbox-address { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
.mailbox-protocol { color: #4d80d8; font-size: 10px; }
.mailbox-remove {
  width: 22px; height: 22px; padding: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  color: #9aa9bd; background: rgba(225, 235, 248, .6);
  font-size: 14px; line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.mailbox-remove:hover { color: #fff; background: rgba(190, 57, 72, .85); }

.content-column { min-width: 0; }
.toolbar { padding: 17px 20px; border-radius: 20px; }
.filters { display: grid; grid-template-columns: minmax(260px, 1fr) 205px 111px; gap: 10px; }
.select-wrap { position: relative; }
.select-wrap select { padding: 0 36px 0 14px; appearance: none; }
.select-wrap svg { position: absolute; right: 12px; width: 14px; pointer-events: none; fill: none; stroke: #8ca0bc; stroke-width: 1.7; }
.toolbar-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 13px; }
.protocol-tabs { display: flex; gap: 8px; }
.protocol-tab { padding: 7px 14px; border: 1px solid #8db6f8; border-radius: 999px; color: #2e72e9; background: rgba(221, 235, 255, .7); font-size: 11px; font-weight: 650; }
.protocol-tab.active { color: #fff; border-color: transparent; background: #3478ee; box-shadow: 0 4px 10px rgba(52, 120, 238, .2); }
.fetch-actions { display: flex; gap: 10px; }

.result-panel { min-height: calc(100vh - 235px); position: relative; }
.main-empty { min-height: 370px; display: flex; align-items: center; justify-content: center; flex-direction: column; color: #91a5bf; text-align: center; }
.main-empty svg { width: 66px; margin-bottom: 16px; fill: none; stroke: #d1deef; stroke-width: 1.6; }
.main-empty strong { margin-bottom: 8px; font-size: 13px; font-weight: 500; }
.main-empty span { font-size: 12px; }
.result-summary { margin: 16px 4px 10px; display: flex; align-items: center; justify-content: space-between; color: #7f91a9; font-size: 12px; }
.result-summary strong { color: var(--ink); font-size: 16px; }
.message-list { display: grid; gap: 10px; padding-bottom: 24px; }
.message-card { padding: 15px 17px; border: 1px solid rgba(255,255,255,.84); border-radius: 15px; background: rgba(255,255,255,.62); box-shadow: 0 8px 22px rgba(72, 113, 170, .08); }
.message-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.message-title { margin: 0; font-size: 14px; }
.message-date { flex: 0 0 auto; color: #96a6bc; font-size: 11px; }
.message-sender { margin: 6px 0; color: #4d79b8; font-size: 11px; }
.message-preview { margin: 0; max-height: 3.8em; overflow: hidden; color: #6f8098; font-size: 12px; line-height: 1.8; white-space: pre-wrap; }
.message-source { display: inline-block; margin-top: 10px; padding: 4px 8px; border-radius: 7px; color: #617793; background: rgba(220, 232, 249, .65); font-size: 10px; }

.import-dialog { width: min(620px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); background: transparent; box-shadow: 0 28px 80px rgba(30, 57, 95, .3); }
.import-dialog::backdrop { background: rgba(38, 60, 91, .28); backdrop-filter: blur(5px); }
.dialog-card { padding: 22px; border: 1px solid rgba(255,255,255,.9); border-radius: 18px; background: rgba(244, 250, 255, .96); }
.dialog-header { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.dialog-header h2 { margin: 0 0 5px; font-size: 18px; }
.dialog-header p { margin: 0; color: var(--muted); font-size: 12px; }
.icon-button { width: 32px; height: 32px; border: 0; border-radius: 9px; color: #71839c; background: rgba(225,235,248,.75); font-size: 21px; }
.dialog-card > label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 650; }
.dialog-card textarea { width: 100%; resize: vertical; padding: 13px; border: 1px solid rgba(130,158,195,.28); border-radius: 11px; outline: none; color: var(--ink); background: rgba(255,255,255,.82); font: 12px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace; }
.dialog-card textarea:focus { border-color: rgba(47,116,239,.5); box-shadow: 0 0 0 3px rgba(47,116,239,.1); }
.format-note { margin-top: 10px; display: flex; gap: 8px; align-items: flex-start; color: #778ba7; font-size: 11px; line-height: 1.5; }
.format-note svg { flex: 0 0 15px; width: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.dialog-actions .button.secondary { margin-top: 0; }

.toast { position: fixed; left: 50%; bottom: 25px; z-index: 20; max-width: min(520px, calc(100% - 30px)); padding: 11px 16px; border-radius: 11px; color: #fff; background: rgba(39, 53, 75, .94); box-shadow: 0 10px 30px rgba(23,43,73,.22); opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: .22s ease; font-size: 12px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: rgba(190, 57, 72, .96); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.is-loading { pointer-events: none; opacity: .7; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 290px minmax(0, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .select-wrap { grid-column: 2; }
}

@media (max-width: 700px) {
  .page-shell { padding: 8px; }
  .workspace { grid-template-columns: 1fr; }
  .mailbox-panel { min-height: auto; }
  .sidebar-empty { min-height: 130px; }
  .filters { grid-template-columns: 1fr; }
  .select-wrap { grid-column: auto; }
  .toolbar-actions { align-items: stretch; flex-direction: column; gap: 12px; }
  .fetch-actions .button { flex: 1; }
  .main-empty { min-height: 250px; }
}

@media (max-width: 430px) {
  .brand-copy h1 { font-size: 16px; }
  .ready-pill { padding: 7px 10px; }
  .toolbar { padding: 14px; }
  .fetch-actions { flex-direction: column; }
  .message-topline { flex-direction: column; gap: 5px; }
}
