:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-hover: #f2f6fb;
  --text: #151a23;
  --muted: #77808f;
  --line: #e8edf3;
  --primary: #2f80ed;
  --primary-hover: #1f6fd8;
  --primary-soft: #eef6ff;
  --danger: #d92d20;
  --shadow: 0 10px 34px rgba(18, 38, 63, .08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101722;
  --surface: #151e2b;
  --surface-soft: #1b2635;
  --surface-hover: #222f41;
  --text: #f4f7fb;
  --muted: #96a2b2;
  --line: #273446;
  --primary: #4a92ff;
  --primary-hover: #6ba7ff;
  --primary-soft: #1a3151;
  --danger: #ff7066;
  --shadow: 0 18px 48px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100vh; background: var(--bg); }
.topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand-mark { width: 27px; height: 27px; display: grid; place-items: center; color: var(--text); }
.brand-mark svg { width: 22px; height: 22px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.current-account {
  max-width: min(34vw, 340px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 13px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
}
.small-button, .icon-button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
}
.small-button { min-width: 45px; padding: 0 12px; font-weight: 650; }
.icon-button { width: 36px; display: grid; place-items: center; }
.icon-button svg { width: 18px; height: 18px; }
.moon-icon { display: none; }
:root[data-theme="dark"] .sun-icon { display: none; }
:root[data-theme="dark"] .moon-icon { display: block; }

.workspace {
  width: min(1380px, calc(100% - 28px));
  height: calc(100vh - 78px);
  margin: 14px auto 0;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
}
.sidebar-title { padding: 17px 16px 10px; font-size: 12px; font-weight: 750; }
.platform-list { display: grid; gap: 4px; padding: 0 8px; }
.platform-item {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 12px 10px;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.platform-item::before { content: ""; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: transparent; }
.platform-item:hover { background: var(--surface-hover); }
.platform-item.active { color: var(--primary); background: var(--primary-soft); }
.platform-item.active::before { background: var(--primary); }
.platform-dot { width: 7px; height: 7px; margin-top: 5px; border-radius: 2px; }
.platform-dot.all { background: #5ebcf0; }
.platform-dot.outlook { background: #20252c; }
.platform-dot.hotmail { background: #686d75; }
.platform-dot.icloud { background: #7d8cff; }
:root[data-theme="dark"] .platform-dot.outlook { background: #d6e3f4; }
.platform-copy { min-width: 0; display: grid; gap: 4px; }
.platform-copy b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.platform-copy small { color: var(--muted); font-size: 11px; }
.sidebar-spacer { flex: 1; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 8px 4px;
  padding: 10px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-size: 12px;
}
.sidebar-link:hover { color: var(--text); background: var(--surface-hover); }
.sidebar-link:last-child { margin-bottom: 10px; }

.main-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.panel-head { height: 62px; flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); }
.provider-title { display: flex; align-items: center; gap: 9px; }
.provider-title h1 { margin: 0; font-size: 18px; }
.provider-icon { width: 24px; height: 24px; display: grid; place-items: center; color: var(--primary); font-size: 18px; }
.fetch-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--line));
  border-radius: 10px;
  color: var(--primary);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
}
.fetch-button:hover:not(:disabled) { background: var(--primary-soft); }
.fetch-button:disabled { opacity: .45; cursor: not-allowed; }

.import-card { margin: 12px 16px 9px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.import-card label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.import-card textarea {
  width: 100%;
  min-height: 112px;
  max-height: 180px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  color: var(--text);
  background: var(--surface-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
}
.import-card textarea:focus, .search-box:focus-within, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 13%, transparent); }
.import-actions { display: flex; gap: 10px; margin-top: 10px; }
.primary-button, .secondary-button {
  min-height: 38px;
  padding: 0 24px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
}
.primary-button { border: 0; color: #fff; background: linear-gradient(135deg, #368cff, #2f72e8); box-shadow: 0 7px 18px rgba(47, 128, 237, .22); }
.primary-button:hover { background: var(--primary-hover); }
.secondary-button { border: 1px solid var(--line); color: var(--text); background: var(--surface); }
.one-shot-tip { margin: 8px 0 0; color: var(--muted); font-size: 10px; }

.search-row { padding: 0 16px 9px; }
.search-box {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--surface);
}
.search-box svg { width: 15px; height: 15px; flex: none; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 12px; }
.folder-tabs { display: flex; gap: 18px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.folder-tab { position: relative; padding: 9px 0 11px; border: 0; color: var(--muted); background: transparent; font-size: 12px; font-weight: 650; }
.folder-tab.active { color: var(--primary); }
.folder-tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: var(--primary); }
.filter-row { display: grid; grid-template-columns: 120px 100px minmax(180px, 260px); gap: 9px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filter-row select { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; outline: 0; color: var(--text); background: var(--surface); font-size: 11px; }
.search-box.compact { height: 38px; }

.mail-area { position: relative; flex: 1; min-height: 0; overflow: hidden; display: grid; grid-template-columns: minmax(280px, 38%) minmax(0, 1fr); }
.mail-list { min-width: 0; min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); }
.mail-list:has(.empty-state) { grid-column: 1 / -1; border-right: 0; }
.empty-state { min-height: 100%; display: grid; place-content: center; justify-items: center; padding: 36px; color: var(--muted); text-align: center; }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; background: var(--surface-soft); color: var(--muted); }
.empty-icon svg { width: 26px; height: 26px; }
.empty-state h2 { margin: 12px 0 5px; color: var(--text); font-size: 17px; }
.empty-state p { margin: 0; font-size: 11px; }
.mail-item {
  width: 100%;
  display: block;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  text-align: left;
}
.mail-item:hover { background: var(--surface-soft); }
.mail-item.active { background: var(--primary-soft); box-shadow: inset 3px 0 var(--primary); }
.mail-item-top { display: flex; justify-content: space-between; gap: 10px; }
.mail-sender { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 750; }
.mail-time { flex: none; color: var(--muted); font-size: 10px; }
.mail-subject { margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.mail-preview { margin-top: 5px; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: var(--muted); font-size: 10px; line-height: 1.45; }
.otp-chip { display: inline-flex; margin-top: 8px; padding: 3px 8px; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.mail-detail { min-width: 0; overflow: auto; padding: 22px; }
.mail-detail.hidden { display: none; }
.detail-back { display: none; margin-bottom: 12px; border: 0; border-radius: 9px; padding: 7px 10px; color: var(--primary); background: var(--primary-soft); }
.detail-subject { margin: 0; font-size: 19px; line-height: 1.4; }
.detail-meta { margin-top: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.65; }
.otp-banner { margin: 16px 0; padding: 16px; border-radius: 12px; color: var(--primary); background: var(--primary-soft); text-align: center; }
.otp-banner small { display: block; margin-bottom: 6px; color: var(--muted); }
.otp-banner strong { font-size: 34px; letter-spacing: .16em; }
.detail-body { margin-top: 16px; color: var(--text); font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; }
.detail-body img { max-width: 100%; height: auto; }
.loading { pointer-events: none; opacity: .6; }

.toast-region { position: fixed; top: 74px; right: 18px; z-index: 20; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); font-size: 12px; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.info-dialog { width: min(500px, calc(100vw - 28px)); padding: 22px; border: 1px solid var(--line); border-radius: 16px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.info-dialog::backdrop { background: rgba(5, 12, 22, .5); backdrop-filter: blur(5px); }
.dialog-close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border: 0; border-radius: 9px; color: var(--text); background: var(--surface-soft); font-size: 20px; }
.info-dialog h3 { margin-top: 0; }
.info-dialog p, .info-dialog li { color: var(--muted); font-size: 12px; line-height: 1.7; }

@media (max-width: 900px) {
  body { overflow: auto; }
  .workspace { width: 100%; height: auto; min-height: calc(100vh - 62px); margin: 0; border: 0; border-radius: 0; box-shadow: none; grid-template-columns: 132px minmax(0, 1fr); }
  .current-account { display: none; }
  .mail-area { min-height: 420px; grid-template-columns: 1fr; }
  .mail-list { border-right: 0; }
  .mail-detail { display: none; }
  .mail-detail.mobile-open { display: block; position: absolute; inset: 0; z-index: 4; background: var(--surface); }
  .detail-back { display: inline-flex; }
}

@media (max-width: 640px) {
  .topbar { height: 56px; padding: 0 12px; }
  .brand { font-size: 15px; }
  .workspace { display: block; min-height: calc(100vh - 56px); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-title, .sidebar-spacer, .sidebar-link { display: none; }
  .platform-list { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 8px; }
  .platform-item { grid-template-columns: 7px 1fr; padding: 8px 6px; }
  .platform-item::before { display: none; }
  .platform-copy b { font-size: 11px; }
  .platform-copy small { display: none; }
  .panel-head { height: 56px; padding: 0 14px; }
  .provider-title h1 { font-size: 16px; }
  .import-card { margin: 10px 12px 8px; }
  .import-card textarea { min-height: 96px; }
  .search-row { padding: 0 12px 8px; }
  .folder-tabs { padding: 0 14px; gap: 16px; overflow-x: auto; }
  .filter-row { grid-template-columns: 1fr 1fr; padding: 10px 12px; }
  .filter-row .compact { grid-column: 1 / -1; }
  .mail-area { min-height: 430px; }
}
