:root {
  --bg: #0d1117;
  --bg-elevated: #151b23;
  --bg-card: #171d27;
  --border: #2a3140;
  --text: #e6edf3;
  --text-muted: #8b95a5;
  --accent: #3ba7ff;
  --accent-dim: #1d4e75;
  --crit: #f0645a;
  --crit-soft: rgba(240,100,90,0.12);
  --warn: #d29922;
  --warn-soft: rgba(210,153,34,0.12);
  --ok: #3fb950;
  --ok-soft: rgba(63,185,80,0.12);
  --radius: 10px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top left, #131a24, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---- login ---- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-box h1 { font-size: 18px; margin: 0 0 6px; text-align: center; }
.login-box input {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.login-error { color: var(--crit); font-size: 13px; min-height: 16px; margin: 0; }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 22px; }
.brand-text h1 { margin: 0; font-size: 17px; font-weight: 600; }
.brand-text p { margin: 0; font-size: 12px; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.search-input {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; width: 220px; outline: none;
}
.search-input:focus { border-color: var(--accent); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-dim); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

main#app { padding: 22px 26px 60px; max-width: 1100px; margin: 0 auto; }

.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; border: 1px solid var(--crit); color: #ffb4ae; background: rgba(240,100,90,0.08); }

.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; padding: 14px 16px; margin-bottom: 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elevated); }
.filter-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.filter-bar select { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: inherit; font-size: 13px; min-width: 140px; }
.filter-bar .btn { align-self: flex-end; }

/* ---- groups ---- */
.group { margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-card); }
.group-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--bg-elevated); border: none; cursor: pointer;
  color: var(--text); font-size: 14px; font-weight: 600; text-align: left;
}
.group-toggle { color: var(--accent); transition: transform .15s; font-size: 12px; }
.group.collapsed .group-toggle { transform: rotate(-90deg); }
.group.collapsed .group-body { display: none; }
.group-count { color: var(--text-muted); font-weight: 400; font-size: 12px; font-family: Consolas, monospace; }

.item { border-top: 1px solid var(--border); padding: 12px 16px; }
.group-body .item:first-child { border-top: none; }
.item-main { display: flex; align-items: flex-start; gap: 12px; }
.item-check { margin-top: 4px; }
.item-content { flex: 1; min-width: 0; }
.item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-subject { font-weight: 600; font-size: 14px; }
.item-thread-badge {
  font-size: 10.5px; font-family: Consolas, monospace; color: var(--accent);
  border: 1px solid var(--accent-dim); border-radius: 10px; padding: 1px 7px;
}
.item-date { margin-left: auto; font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.item-from { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.item-summary { font-size: 13px; margin-top: 6px; }
.item-task { font-size: 13px; margin-top: 6px; padding: 8px 10px; background: var(--bg-elevated); border-radius: 6px; border-left: 2px solid var(--accent); }
.item-task-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; }
.item-task-text { outline: none; }
.item-task-text:focus { background: var(--accent-dim); border-radius: 3px; }

.item-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.item-actions .btn { padding: 6px 12px; font-size: 12px; }
.item-notion-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.item-expand { background: none; border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 6px 12px; }

.item-messages { margin: 10px 0 0 34px; display: flex; flex-direction: column; gap: 8px; }
.sub-message { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }
.sub-message-head { display: flex; justify-content: space-between; color: var(--text-muted); margin-bottom: 4px; }
.sub-message-body { white-space: pre-wrap; max-height: 160px; overflow-y: auto; }

.pill {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  font-family: Consolas, monospace;
}
.priority-pill.hoch { background: var(--crit-soft); color: var(--crit); }
.priority-pill.normal { background: var(--warn-soft); color: var(--warn); }
.priority-pill.niedrig { background: var(--ok-soft); color: var(--ok); }
.category-pill { background: var(--accent-dim); color: #9fd8ff; }
.pill[contenteditable], .pill.editable { cursor: pointer; }

.item-notion-status { margin-top: 8px; font-size: 12px; min-height: 15px; }
.item-notion-status.ok { color: var(--ok); }
.item-notion-status.err { color: var(--crit); }
.item-notion-status.busy { color: var(--warn); }

.empty-state { text-align: center; color: var(--text-muted); padding: 60px 20px; }

/* ---- buttons ---- */
.btn { border: none; border-radius: 8px; padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #2a86d6); color: #05121f; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { background: transparent; border: 1px solid var(--crit); color: var(--crit); }
.btn-danger:hover { background: var(--crit-soft); }

/* ---- modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,7,12,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { width: min(680px, 92vw); max-height: 86vh; overflow-y: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-card); }
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: 12px; position: sticky; bottom: 0; background: var(--bg-card); }

.form-section h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.form-section .hint { font-size: 12px; color: var(--text-muted); margin: 4px 0 12px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
input, select, textarea {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; outline: none; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.input-with-toggle { display: flex; gap: 8px; }
.input-with-toggle input { flex: 1; }
.toggle-visibility { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-muted); border-radius: 8px; padding: 0 10px; font-size: 11px; cursor: pointer; }

.mailbox-list { display: flex; flex-direction: column; gap: 14px; }
.mailbox-row { border: 1px solid var(--border); border-radius: 10px; padding: 14px; background: var(--bg-elevated); }
.mailbox-row-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 14px; }
.mailbox-row-grid label { margin-bottom: 0; }
.mailbox-row-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.mailbox-test-result, .dest-setup-result { font-size: 12px; color: var(--text-muted); }
.mailbox-smtp { margin-top: 10px; }
.mailbox-smtp summary { cursor: pointer; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.settings-msg { font-size: 12px; color: var(--text-muted); margin-right: auto; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { padding: 12px 16px; border-radius: 10px; font-size: 13px; background: var(--bg-elevated); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,0.4); max-width: 320px; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--crit); }

@media (max-width: 700px) {
  .search-input { width: 130px; }
  .item-date { display: none; }
}
