/* ---- Tokens ---- */
:root {
  --jet: #0A0A0B;
  --jet-raised: #16171a;
  --green: #77B82A;
  --green-dim: #5c921f;
  --paper: #F7F8F5;
  --panel: #FFFFFF;
  --line: #E4E6E1;
  --text: #121310;
  --text-muted: #6b6f68;
  --text-on-dark: #F2F3F0;
  --text-on-dark-muted: #9a9d96;
  --danger: #c0392b;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

a { color: var(--green-dim); }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ---- Wordmark (Platzhalter bis Logo-Auswahl) ---- */
.wordmark {
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wordmark .mark { color: var(--green); display: inline-flex; align-items: center; }
.wordmark .mark svg { display: block; }
.wordmark .rest { color: inherit; }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--jet);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
}
.login-card .wordmark {
  font-size: 30px;
  color: var(--text-on-dark);
  margin-bottom: 2px;
}
.login-card .tagline {
  color: var(--text-on-dark-muted);
  font-size: 14px;
  margin-bottom: 36px;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card label {
  color: var(--text-on-dark-muted);
  font-size: 13px;
  margin-bottom: 6px;
  display: block;
}
.login-card input {
  width: 100%;
  background: #1c1d20;
  border: 1px solid #2c2d30;
  color: var(--text-on-dark);
  border-radius: var(--radius);
  padding: 11px 12px;
}
.login-card input:focus { border-color: var(--green); }
.login-error {
  color: #ff8a7a;
  font-size: 13px;
  min-height: 18px;
}

/* ---- Buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #0d1304;
  font-weight: 600;
}
.btn-primary:hover { background: var(--green-dim); border-color: var(--green-dim); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: default; }

/* ---- App shell ---- */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--jet);
  color: var(--text-on-dark);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}
.sidebar .wordmark { font-size: 18px; margin-bottom: 32px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-on-dark-muted);
  text-decoration: none;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--text-on-dark); }
.nav-item.active {
  color: var(--text-on-dark);
  background: var(--jet-raised);
  border-left-color: var(--green);
}
.sidebar-foot { border-top: 1px solid #222327; padding-top: 14px; margin-top: 14px; }
.sidebar-foot .email { font-size: 12px; color: var(--text-on-dark-muted); display: block; margin-bottom: 10px; word-break: break-all; }

.main { padding: 36px 44px; max-width: 920px; }
.page-title { font-size: 26px; font-weight: 600; margin: 0 0 6px; }
.page-sub { color: var(--text-muted); margin: 0 0 32px; }

/* ---- Stat row ---- */
.stats { display: flex; gap: 28px; margin-bottom: 28px; flex-wrap: wrap; }
.stat { }
.stat .n { font-size: 26px; font-weight: 700; color: var(--jet); }
.stat .label { font-size: 13px; color: var(--text-muted); }

/* ---- List rows (dashboard & recipients) ---- */
.list { border-top: 1px solid var(--line); }
.list-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 18px 4px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
}
.list-row.sent { border-left-color: var(--green); }
.list-row.pending { border-left-color: #d8dad2; }
.list-row .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--jet); color: var(--text-on-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.list-row .body { flex: 1; min-width: 0; }
.list-row .row-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.list-row .name { font-weight: 600; }
.list-row .time { color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.list-row .message {
  margin-top: 4px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-row .muted { color: var(--text-muted); }
.list-row .summary {
  margin-top: 6px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}
.list-row .meta-line { margin-top: 6px; font-size: 13px; color: var(--text-muted); }
.pill {
  display: inline-block;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 100px;
  background: #ECF4E3;
  color: var(--green-dim);
  margin-right: 6px;
}
.pill.event { background: #FFF3DC; color: #9a6b00; }
.pill.noreply { background: #FBEAE7; color: var(--danger); }

/* ---- Recipients table ---- */
.recipients-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;
}
.rec-row { display: flex; gap: 16px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.rec-row .name { font-weight: 600; flex: 1; }
.rec-row .number { color: var(--text-muted); font-size: 13px; width: 160px; }
.rec-row .relationship { color: var(--text-muted); font-size: 13px; width: 160px; }
.toggle {
  width: 38px; height: 22px; border-radius: 100px; background: #d8dad2;
  border: none; cursor: pointer; position: relative; flex-shrink: 0;
}
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: white; border-radius: 50%; transition: left .15s ease;
}
.toggle.on { background: var(--green); }
.toggle.on::after { left: 18px; }
.row-actions { display: flex; gap: 6px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,10,11,0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--panel); border-radius: 12px; padding: 32px;
  width: 100%; max-width: 560px;
}
.modal h2 { margin: 0 0 22px; font-size: 20px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px; background: var(--panel); color: var(--text);
}
.field textarea { resize: vertical; min-height: 64px; }
.modal-actions { display: flex; justify-content: space-between; margin-top: 26px; }
.modal-actions .right { display: flex; gap: 8px; }

/* ---- Settings ---- */
.settings-form { max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.settings-form .field label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; display: block; }
.settings-form input {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--jet); color: var(--text-on-dark);
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; z-index: 100;
  border-left: 3px solid var(--green);
}
.toast.error { border-left-color: var(--danger); }

.empty {
  padding: 40px 4px; color: var(--text-muted); border-top: 1px solid var(--line);
}

/* ---- Responsive ---- */
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  .shell { grid-template-columns: 1fr; min-height: 100vh; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
    gap: 8px;
  }
  .sidebar .wordmark { font-size: 16px; }
  .nav {
    flex-direction: row;
    flex: 1 1 auto;
    gap: 2px;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 8px 10px;
    white-space: nowrap;
  }
  .nav-item.active { background: transparent; border-bottom-color: var(--green); }
  .sidebar-foot {
    border-top: none;
    margin: 0;
    padding: 0;
    flex: 0 0 auto;
  }
  .sidebar-foot .email { display: none; }
  .sidebar-foot .btn { width: auto; padding: 8px 12px; font-size: 13px; }

  .main { padding: 20px 16px 40px; max-width: 100%; }
  .page-title { font-size: 21px; }
  .page-sub { margin-bottom: 22px; }

  .stats { gap: 20px; margin-bottom: 22px; }

  .recipients-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .recipients-head .btn { width: 100%; }

  .list-row { gap: 12px; }
  .list-row .avatar { width: 32px; height: 32px; font-size: 12px; }
  .list-row .row-top { flex-direction: column; align-items: flex-start; gap: 2px; }
  .list-row .message { white-space: normal; overflow: visible; }

  .rec-row { flex-wrap: wrap; padding: 14px 0; }
  .rec-row .name { flex: 1 1 100%; order: 1; }
  .rec-row .number, .rec-row .relationship { width: auto; order: 2; font-size: 12px; }
  .toggle { order: 0; }
  .row-actions { order: 3; flex: 1 1 100%; justify-content: flex-end; margin-top: 6px; }

  .field-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 22px 18px 28px;
    max-height: 92vh;
    overflow-y: auto;
  }
  .modal-actions { flex-direction: column-reverse; gap: 10px; }
  .modal-actions .right { width: 100%; }
  .modal-actions .right .btn { width: 100%; }
  .modal-actions .btn-ghost { width: 100%; }

  .settings-form { max-width: 100%; }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    text-align: center;
  }

  .login-screen { padding: 16px; }
  .login-card .wordmark { font-size: 24px; }
}

@media (max-width: 420px) {
  .stats { gap: 14px; }
  .stat .n { font-size: 22px; }
  .list-row .message { white-space: normal; }
}

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