/* ============================================================
   Unity Hub 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); }

/* ---- 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; }
}
