:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button,
.btn {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover,
.btn:hover { border-color: #c5c9d0; background: #f3f4f6; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { color: var(--danger); border-color: var(--border); background: var(--surface); }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.app-shell {
  display: flex;
  min-height: calc(100vh - 54px);
  align-items: stretch;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 12px 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-of-type {
  border-bottom: none;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0 8px;
}

.sidebar-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.35;
}
.sidebar-item:hover {
  background: #f3f4f6;
  text-decoration: none;
}
.sidebar-item.active {
  background: #eff6ff;
  color: var(--accent);
  font-weight: 500;
}
.sidebar-item-title { font-weight: 500; }
.sidebar-item-sub { font-size: 12px; word-break: break-all; }

.sidebar-muted {
  font-size: 13px;
  color: var(--muted);
  padding: 4px 8px;
  margin: 0;
}

.sidebar-foot {
  display: block;
  font-size: 13px;
  color: var(--muted);
  padding: 8px;
  margin-top: 6px;
}
.sidebar-foot:hover { color: var(--accent); }

.main-area {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

/* 主内容区占满侧栏右侧可用宽度（不再限制 900px） */
.main-inner {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 20px 28px 48px;
  box-sizing: border-box;
}

.page-toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }
  .sidebar-section {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    padding-bottom: 12px;
  }
  .sidebar-label { width: 100%; margin-bottom: 0; }
  .sidebar-item { flex: 1 1 auto; min-width: 44%; margin-bottom: 0; }
  .sidebar-foot { width: 100%; }
}

.topbar {
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none; font-weight: 600;
}
.topbar .logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}
.topbar nav { margin-left: auto; display: flex; gap: 14px; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active { color: var(--text); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--muted); }

.muted { color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; background: #fafbfc; }
tr:hover td { background: #f9fafb; }

.form-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px 16px; align-items: center; margin-bottom: 10px; }
@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; gap: 4px; }
  .topbar nav { gap: 10px; }
  .container { padding: 16px 12px 48px; }
  th:nth-child(3), td:nth-child(3),
  th:nth-child(4), td:nth-child(4) { display: none; }
}

.grid-2 { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.mail-list { list-style: none; margin: 0; padding: 0; }
.mail-list li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.mail-list li.unseen { background: #f8fafc; }
.mail-list li:hover { background: #f3f4f6; }
.mail-list .subject { font-weight: 500; }
.mail-list .from { color: var(--muted); font-size: 13px; }

/* token 弹框 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 8px;
  width: min(360px, 92vw);
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.modal h3 { margin: 0 0 10px; color: var(--text); font-size: 14px; }
.modal .actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 8px; }

.modal.modal-wide {
  width: min(640px, 94vw);
  max-height: min(92vh, 880px);
  overflow-y: auto;
  padding: 20px 22px;
}
.modal.modal-wide h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 600;
}

/* 阅读邮件：宽弹窗，正文区域独立滚动 */
.modal.modal-mail {
  width: min(1320px, 98vw);
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.modal-mail-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-mail-toolbar h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
}
.modal-mail-meta {
  padding: 0 20px 12px;
  font-size: 14px;
}
.modal-mail-meta p {
  margin: 4px 0;
}
.modal-mail-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 20px 20px;
}
.modal-mail-body iframe {
  display: block;
  width: 100%;
  min-height: min(720px, 72vh);
  border: 0;
}
.modal-mail-body pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.tag {
  display: inline-block; font-size: 12px; color: var(--muted);
  padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px;
}

pre { background: #f6f8fa; padding: 12px; border-radius: 6px; overflow: auto; font-family: var(--mono); }

.access-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}
