:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --fg: #1c1c1e;
  --muted: #75757d;
  --border: #e4e4e9;
  --hover: #f0f0f3;
  --accent: #fe2c55;
  --accent-fg: #ffffff;
  --ok: #16813d;
  --warn: #b45309;
  --info: #2563eb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101012;
    --card: #191a1d;
    --fg: #ececf1;
    --muted: #93939c;
    --border: #2a2b30;
    --hover: #232429;
    --ok: #4ade80;
    --warn: #fbbf24;
    --info: #7aa2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC",
    "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.6;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
svg { display: block; }

.app {
  max-width: 940px;
  margin: 0 auto;
  padding: 20px 16px 80px;
  padding-top: max(20px, env(safe-area-inset-top));
}

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.brand { display: flex; align-items: center; gap: 8px; }

.brand h1 {
  font-size: 17px;
  font-weight: 500;
  margin: 0;
  letter-spacing: .2px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.count {
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 8px;
}

.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: var(--hover); color: var(--fg); }

/* ---------------- composer ---------------- */

.composer {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.composer textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.7;
  padding: 4px 4px 8px;
  min-height: 52px;
}

.composer textarea::placeholder { color: var(--muted); opacity: .8; }

.composer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.composer-row .primary-btn { margin-left: auto; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
}

.ghost-btn:hover { background: var(--hover); color: var(--fg); }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
}

.switch input { accent-color: var(--accent); width: 15px; height: 15px; }

.primary-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 9px;
  padding: 7px 18px;
  font-size: 14px;
  font-weight: 500;
  transition: filter .15s, opacity .15s;
}

.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:disabled { opacity: .5; cursor: default; }

.sub-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 9px;
  padding: 7px 14px;
  font-size: 13px;
}

.sub-btn:hover { background: var(--hover); }
.sub-btn.danger { color: var(--accent); }

/* ---------------- toolbar ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.tabs button {
  font-size: 13px;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 7px;
  white-space: nowrap;
}

.tabs button.active {
  background: var(--fg);
  color: var(--bg);
}

.search {
  flex: 1;
  min-width: 120px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
}

.search:focus { border-color: var(--muted); }

/* ---------------- list ---------------- */

.list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 720px) {
  .list { grid-template-columns: 1fr 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
}

.card:hover { border-color: var(--muted); }

.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.card-top time { margin-left: auto; font-variant-numeric: tabular-nums; }

.badge {
  font-size: 11px;
  line-height: 1.7;
  padding: 0 7px;
  border-radius: 5px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge.inbox { color: var(--muted); background: var(--hover); }
.badge.processing { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.ready { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.archived { color: var(--info); background: color-mix(in srgb, var(--info) 14%, transparent); }

.card h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .summary {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
}

.card-foot .author { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }

.tagline {
  display: flex;
  gap: 5px;
  overflow: hidden;
  white-space: nowrap;
}

.tagline span { color: var(--muted); opacity: .85; }

/* ---------------- empty ---------------- */

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty p { margin: 12px 0 4px; color: var(--fg); font-size: 15px; }
.empty span { font-size: 13px; }

.empty-mark {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
}

/* ---------------- sheet ---------------- */

.sheet-wrap, .modal-wrap { position: fixed; inset: 0; z-index: 40; }

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .32);
  animation: fade .18s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(560px, 100%);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  overflow-x: hidden;
  animation: slide .22s cubic-bezier(.2, .8, .2, 1);
}

@keyframes slide { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }

@media (max-width: 640px) {
  .sheet {
    top: auto;
    left: 0;
    width: 100%;
    height: 92%;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    animation: rise .24s cubic-bezier(.2, .8, .2, 1);
  }
  @keyframes rise { from { transform: translateY(40px); } to { transform: none; } }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  min-width: 0;
}

.sheet-head-main { display: flex; align-items: center; gap: 8px; flex: 1; overflow: hidden; }
.sheet-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 24px;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

.sheet-foot {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-wrap: wrap;
  min-width: 0;
}

.sheet-foot .primary-btn { margin-left: auto; }

@media (max-width: 430px) {
  .sheet-foot { gap: 6px; padding: 10px 12px; }
  .sheet-foot .sub-btn, .sheet-foot .primary-btn { padding: 7px 10px; font-size: 12.5px; }
  .sheet-body { padding: 16px 12px 20px; }
}

.field { margin-bottom: 18px; }

.field > label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .3px;
}

.field input, .field textarea, .field select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  line-height: 1.7;
  outline: none;
  resize: vertical;
  color: var(--fg);
}

.field select { resize: none; padding-right: 8px; }

.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--muted); }

.hint a { text-decoration: none; }

.field .readonly {
  background: var(--hover);
  color: var(--muted);
  font-size: 13px;
  border-radius: 10px;
  padding: 9px 11px;
  border: 1px solid transparent;
  word-break: break-all;
}

.field .readonly a { color: var(--info); text-decoration: none; }

.hint {
  font-size: 12px;
  color: var(--muted);
}

.notice {
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12.5px;
  line-height: 1.6;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--warn);
  margin-bottom: 16px;
}

.transcript {
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.85;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px;
}

/* ---------------- modal ---------------- */

.modal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 24px));
  max-height: min(86vh, 760px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: pop .18s ease;
}

@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } to { opacity: 1; } }

.modal-head, .modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  gap: 10px;
}

.modal-head { border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15px; font-weight: 500; margin: 0; }
.modal-foot { border-top: 1px solid var(--border); }
.modal-body { padding: 16px; overflow-y: auto; min-width: 0; }

.section-title {
  font-size: 12px;
  color: var(--muted);
  margin: 20px 0 10px;
  letter-spacing: .4px;
}

.section-title:first-child { margin-top: 0; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 20px;
  z-index: 60;
  animation: pop2 .2s ease;
}

@keyframes pop2 { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; } }

.spin { animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
