:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #5b6270;
  --border: #d9dce1;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d64545;
  --danger-text: #ffffff;
  --row-hover: #eef1f6;
}

:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1e2127;
  --text: #e6e8eb;
  --text-muted: #9aa1ad;
  --border: #33373f;
  --accent: #4d8dff;
  --accent-text: #0b1220;
  --danger: #e05c5c;
  --danger-text: #1a0000;
  --row-hover: #262a32;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1.5rem;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

h1 { font-size: 1.3rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inline-form { display: inline; }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}
button:hover { background: var(--row-hover); }
button[type="submit"], button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
button.danger { background: var(--danger); color: var(--danger-text); border-color: var(--danger); }
/* .secondary needs its own `color` even though .secondary buttons are never
   type="submit" elsewhere - the "Log out" button is, and without this it
   also matches `button[type="submit"]` above (same specificity, so only
   whichever property isn't already set here would leak through): that rule's
   color: var(--accent-text) is meant to sit on the accent-blue background it
   also sets, not on the page background .secondary's transparent reveals -
   giving near-white-on-light / near-black-on-dark text instead of var(--text). */
button.secondary { background: transparent; color: var(--text); }
button.icon-button {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 50%;
}

table.messages-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.messages-table th, .messages-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.messages-table th { color: var(--text-muted); font-weight: 600; font-size: 0.85rem; }
.messages-table tbody tr:hover { background: var(--row-hover); }
.messages-table tbody tr:last-child td { border-bottom: none; }
.cell-clickable { cursor: pointer; }
.empty-state { text-align: center; color: var(--text-muted); padding: 1.5rem; }

.auth-page {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.75rem;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 100%;
  max-width: 320px;
}
.auth-form h1 { text-align: center; margin-bottom: 0.25rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
}
input[type="color"] { padding: 0.2rem; height: 2.4rem; width: 5rem; }
/* The date input's calendar icon color follows the inherited `color-scheme`
   set on :root above (both Chromium and Firefox pick a light-vs-dark icon
   based on it directly) - no extra rule needed here, and adding one (e.g. a
   filter) would fight that native adaptation rather than help it. */

.error {
  color: var(--danger-text);
  background: var(--danger);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  margin: 0;
}

dialog.modal {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  background: var(--surface);
  color: var(--text);
  width: min(480px, 92vw);
}
dialog.modal.modal-wide { width: min(700px, 92vw); }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.5); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

form { display: flex; flex-direction: column; gap: 0.9rem; }
.row { display: flex; gap: 0.9rem; }
.row .grow { flex: 1; }
.row-preview { align-items: stretch; }

.markdown-preview {
  flex: 1;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  overflow-y: auto;
  max-height: 220px;
  background: var(--bg);
}

.content-preview {
  padding-left: 0.75rem;
  margin: 0.75rem 0;
}
.attachments-label { font-weight: 600; margin: 0.75rem 0 0.25rem; }
.attachments-edit { display: flex; flex-direction: column; gap: 0.3rem; }
.attachment-row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  color: var(--text);
}
.countdown { color: var(--text-muted); font-size: 0.9rem; }
