/* ============================================================
   Blind Techno TeamTalk Panel - base stylesheet
   Accessibility-first: WCAG 2.1 AA target.
   - Minimum 4.5:1 text contrast
   - Visible focus indicator on every interactive element
   - No information conveyed by color alone (icons/text labels pair with color)
   - Responsive from 320px up, touch targets >= 44x44px
   ============================================================ */

:root {
  --color-bg: #101418;
  --color-surface: #1a2029;
  --color-surface-raised: #232b37;
  --color-border: #3a4451;
  --color-text: #f2f4f7;
  --color-text-muted: #b7c0cc;
  --color-accent: #4fb0ff;      /* 4.5:1+ on --color-bg */
  --color-accent-text: #06202f; /* text-on-accent, for buttons */
  --color-success: #57c785;
  --color-error: #ff8a80;
  --color-error-bg: #3a1f1f;
  --focus-ring: 3px solid #ffd166;
  --radius: 6px;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.5;
}

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

/* ---- Skip link: first focusable element, hidden until focused ---- */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--color-accent);
  color: var(--color-accent-text);
  padding: var(--space-1) var(--space-2);
  z-index: 100;
  font-weight: 700;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus {
  left: 0;
}

/* ---- Universal visible focus indicator (never remove outline) ---- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* ---- Layout ---- */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.site-header .brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
}
.site-header .brand:hover { text-decoration: underline; }

.main-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
}

.main-nav a {
  color: var(--color-text);
  text-decoration: none;
  padding: var(--space-1);
  border-radius: var(--radius);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.main-nav a:hover, .main-nav a:focus-visible { text-decoration: underline; }
.main-nav a[aria-current="page"] {
  text-decoration: underline;
  font-weight: 700;
  color: var(--color-accent);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--space-3);
}

h1 { font-size: 1.75rem; margin-top: 0; }
h2 { font-size: 1.35rem; margin-top: var(--space-3); }
h3 { font-size: 1.1rem; margin-bottom: 0.4rem; color: var(--color-accent); }

footer {
  margin-top: var(--space-4);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

/* ---- Flash messages: role=status/alert set in template, icon+text (not color alone) ---- */
.flash-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-3) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.flash {
  padding: var(--space-2);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-1);
}
.flash-success { background: #10281c; border-color: var(--color-success); }
.flash-error { background: var(--color-error-bg); border-color: var(--color-error); }
.flash-info { background: var(--color-surface-raised); }

/* ---- Forms ---- */
fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  margin: 0 0 var(--space-3) 0;
}
legend { padding: 0 var(--space-1); font-weight: 700; }

.form-field { margin-bottom: var(--space-2); }

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.required-marker {
  color: var(--color-error);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.6rem;
  font-size: 1rem;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  min-height: 44px;
}

.field-hint {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.field-error {
  font-size: 0.875rem;
  color: var(--color-error);
  margin-top: 0.25rem;
  font-weight: 600;
}

/* ---- Checkbox rows: "Show password", "Stay signed in", etc ----
   The whole row (not just the tiny native box) is the click/tap target,
   and state is shown by the checkbox itself, never by color alone. */
.form-field-checkbox { margin-bottom: var(--space-2); }

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  font-weight: 400;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"],
.checkbox-label input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  accent-color: var(--color-accent);
}

input[aria-invalid="true"] {
  border-color: var(--color-error);
}

/* ---- Buttons ---- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-text);
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border-color: var(--color-error);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* ---- Tables (used for user lists, server lists) ----
   Wrapped in .table-scroll so on narrow phone screens only the table
   itself scrolls horizontally - the rest of the page (nav, buttons,
   text) still reflows normally with no sideways scrolling needed. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-3);
}
.table-scroll:focus-visible {
  outline: var(--focus-ring);
  outline-offset: -2px;
}
table {
  width: 100%;
  border-collapse: collapse;
}
caption {
  text-align: left;
  font-weight: 700;
  margin-bottom: var(--space-1);
}
th, td {
  text-align: left;
  padding: 0.6rem;
  border-bottom: 1px solid var(--color-border);
}
th { color: var(--color-text-muted); font-weight: 700; }

/* ---- Cards (server list items) ---- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--color-border);
}
.badge-banned { color: var(--color-error); border-color: var(--color-error); }
.badge-admin { color: var(--color-accent); border-color: var(--color-accent); }

/* ---- Announcements / notifications ---- */
.main-nav .badge-count {
  margin-left: 0.4rem;
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: var(--color-accent);
}

.badge-new {
  margin-left: 0.4rem;
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: var(--color-accent);
}

.notification-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.notification-list .notification-card {
  margin-bottom: var(--space-2);
}
.notification-list li:last-child .notification-card {
  margin-bottom: 0;
}

.notification-card h2 {
  margin-top: 0;
}

.notification-card h2 a {
  color: var(--color-accent);
}

.notification-card-unread {
  border-left: 4px solid var(--color-accent);
}

.notification-card-unread h2 a {
  font-weight: 700;
}

.notification-preview {
  margin-bottom: var(--space-1);
}

.notification-meta {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.notification-meta a {
  color: var(--color-accent);
  font-weight: 600;
}

.notification-body {
  white-space: pre-wrap;  /* keep line breaks the poster typed */
}

.notification-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.inline-form {
  display: inline;
}

.announcement-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.announcement-item {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-1);
  margin-top: var(--space-1);
}
.announcement-item:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}
.announcement-item h3 {
  margin-top: 0;
}
.announcement-item h3 a {
  color: var(--color-accent);
}

/* ---- Pagination ---- */
.pagination ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin: var(--space-2) 0;
  padding: 0;
}

.pagination a,
.pagination .page-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.6rem;
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
}

.pagination a {
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.pagination a:hover { border-color: var(--color-accent); color: var(--color-accent); }

.pagination .page-current {
  background: var(--color-accent);
  color: var(--color-accent-text);
}

.pagination .page-ellipsis {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 0.3rem;
  color: var(--color-text-muted);
}

/* ---- Browser notification settings (bell menu) ---- */
.notify-bell {
  position: relative;
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text);
  padding: 0.4rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius);
}
.notify-bell:hover, .notify-bell:focus-visible {
  border-color: var(--color-border);
}

.notify-bell-icon {
  width: 24px;
  height: 24px;
  display: block;
}

/* Small dot on the bell when there are unread announcements. Sits next
   to the word "Announcements" in the nav, so it's never color-only. */
.notify-bell-dot {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-surface);
}
.notify-bell.has-unread .notify-bell-dot {
  display: block;
}

/* ---- Dialog (notification settings) ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  z-index: 50;
}
.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h2 {
  margin-top: 0;
  padding-right: 2rem;
}

.modal-close {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text);
  font-size: 1.4rem;
  line-height: 1;
  border-radius: var(--radius);
}
.modal-close:hover, .modal-close:focus-visible {
  border-color: var(--color-border);
}

.notify-ok {
  color: var(--color-success);
  font-weight: 600;
}

/* ---- In-app toast (new announcement while the panel is open) ---- */
#notify-toast[hidden] {
  display: none;
}

.notify-toast-card {
  position: fixed;
  right: var(--space-2);
  bottom: var(--space-2);
  z-index: 60;
  max-width: 360px;
  width: calc(100% - 2 * var(--space-2));
  background: var(--color-surface-raised);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: var(--space-2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.notify-toast-title {
  margin: 0 0 0.25rem 0;
  font-weight: 700;
  color: var(--color-accent);
}

.notify-toast-body {
  margin: 0 0 var(--space-1) 0;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.notify-toast-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: var(--space-1) 0 0 0;
}

@media (prefers-reduced-motion: reduce) {
  #notify-toast .notify-toast-card {
    transition: none;
  }
}

/* ---- Utility ---- */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  main { padding: var(--space-2); }
  .site-header { flex-direction: column; align-items: flex-start; }
}
