/**
 * RUNEKT Base Styles
 * Reset, normalize, and foundational styles
 * WCAG 2.1 AA compliant
 */

/* ============================================================================
   Minimal Reset
   ============================================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

/* ============================================================================
   Document Root
   ============================================================================ */

html {
  font-size: 16px; /* Base size for rem calculations */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============================================================================
   Body Foundation
   ============================================================================ */

body {
  font-family: var(--rk-font-active);
  font-size: var(--rk-font-size-base);
  font-weight: var(--rk-font-weight-normal);
  line-height: var(--rk-line-height-normal);
  color: var(--rk-text);
  background-color: var(--rk-bg);
  overflow-x: hidden;
}

/* Locale-specific font selection is handled by i18n.js.
   Keep line-height stable across locale switches; components opt in as needed. */

/* ============================================================================
   Typography Base
   ============================================================================ */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--rk-font-weight-semibold);
  line-height: var(--rk-line-height-tight);
  color: var(--rk-text);
}

h1 { font-size: var(--rk-font-size-2xl); }
h2 { font-size: var(--rk-font-size-xl); }
h3 { font-size: var(--rk-font-size-lg); }
h4 { font-size: var(--rk-font-size-md); }
h5 { font-size: var(--rk-font-size-base); }
h6 { font-size: var(--rk-font-size-sm); }

p {
  margin-bottom: var(--rk-space-4);
}

a {
  color: var(--rk-primary);
  text-decoration: none;
  transition: color var(--rk-transition-fast);
}

a:hover {
  color: var(--rk-primary-hover);
  text-decoration: underline;
}

/* ============================================================================
   Focus Styles (WCAG 2.1 AA - 2.4.7 Focus Visible)
   ============================================================================ */

:focus-visible {
  outline: 2px solid var(--rk-primary);
  outline-offset: 2px;
  border-radius: var(--rk-radius-sm);
}

/* Remove default outline for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================================
   Reduced Motion (WCAG 2.1 AA - 2.3.3 Animation from Interactions)
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================================
   Dark Mode Auto-Detection
   ============================================================================ */

[data-theme="system"] {
  /* JavaScript will set data-theme to light/dark based on media query */
}

/* ============================================================================
   Safe Area Insets (mobile notches, iOS home indicator)
   ============================================================================ */

@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ============================================================================
   Scrollbar Styling (webkit browsers)
   ============================================================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--rk-bg-2);
  border-radius: var(--rk-radius);
}

::-webkit-scrollbar-thumb {
  background: var(--rk-border-strong);
  border-radius: var(--rk-radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--rk-text-3);
}

/* Firefox scrollbar (thinner, auto) */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--rk-border-strong) var(--rk-bg-2);
}

/* ============================================================================
   Selection Styles
   ============================================================================ */

::selection {
  background-color: var(--rk-primary);
  color: white;
}

::-moz-selection {
  background-color: var(--rk-primary);
  color: white;
}

/* ============================================================================
   Form Elements Base
   ============================================================================ */

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

/* ============================================================================
   Images and Media
   ============================================================================ */

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ============================================================================
   Lists
   ============================================================================ */

ul, ol {
  list-style: none;
  padding-left: 0;
}

/* ============================================================================
   Text-level semantics
   ============================================================================ */

strong, b {
  font-weight: var(--rk-font-weight-bold);
}

em, i {
  font-style: italic;
}

code {
  font-family: var(--rk-font-mono);
  font-size: 0.9em;
  background-color: var(--rk-bg-2);
  padding: 0.2em 0.4em;
  border-radius: var(--rk-radius-sm);
}

pre {
  font-family: var(--rk-font-mono);
  background-color: var(--rk-bg-2);
  padding: var(--rk-space-4);
  border-radius: var(--rk-radius);
  overflow-x: auto;
  line-height: var(--rk-line-height-normal);
}

/* ============================================================================
   Tables (reset only - component styles in components.css)
   ============================================================================ */

table {
  border-collapse: collapse;
  width: 100%;
}

/* ============================================================================
   Legal Documents
   ============================================================================ */

.rk-legal {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 64px 0 80px;
  color: var(--rk-text);
}

.rk-legal__header {
  padding-bottom: 28px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--rk-border);
}

.rk-legal__eyebrow {
  margin-bottom: 10px;
  color: var(--rk-primary);
  font-size: var(--rk-font-size-sm);
  font-weight: var(--rk-font-weight-semibold);
}

.rk-legal__header h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 5vw, 3rem);
}

.rk-legal__header p {
  color: var(--rk-text-2);
}

.rk-legal section {
  margin-top: 32px;
}

.rk-legal h2 {
  margin-bottom: 14px;
  font-size: var(--rk-font-size-lg);
}

.rk-legal p,
.rk-legal li {
  color: var(--rk-text-2);
  line-height: 1.75;
}

.rk-legal ol {
  display: grid;
  gap: 10px;
  list-style: decimal;
  padding-left: 1.25rem;
}

.rk-legal__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding-top: 32px;
  margin-top: 40px;
  border-top: 1px solid var(--rk-border);
}

/* ============================================================================
   Shared Conversation (read-only /s/<token>/)
   ============================================================================ */

.rk-share {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 72px;
  color: var(--rk-text);
}

.rk-share__header {
  padding-bottom: 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rk-border);
}

.rk-share__brand {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--rk-primary);
  font-size: var(--rk-font-size-sm);
  font-weight: var(--rk-font-weight-semibold);
  text-decoration: none;
}

.rk-share__title {
  margin-bottom: 8px;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  line-height: 1.3;
}

.rk-share__meta {
  color: var(--rk-text-2);
  font-size: var(--rk-font-size-sm);
}

.rk-share__messages {
  display: grid;
  gap: 16px;
  list-style: none;
  padding: 0;
}

.rk-share__message {
  padding: 20px 24px;
  border: 1px solid var(--rk-border);
  border-radius: var(--rk-radius-lg);
  background: var(--rk-bg);
}

.rk-share__message--user {
  background: var(--rk-bg-2);
}

.rk-share__message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--rk-text-3);
  font-size: var(--rk-font-size-sm);
}

.rk-share__message-meta strong {
  color: var(--rk-text);
}

.rk-share__content {
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.rk-share__content > * + * {
  margin-top: 12px;
}

.rk-share__content p {
  margin-bottom: 0;
}

.rk-share__content h1,
.rk-share__content h2,
.rk-share__content h3 {
  font-size: var(--rk-font-size-lg);
  line-height: 1.4;
}

.rk-share__content ul,
.rk-share__content ol {
  padding-left: 1.4rem;
}

.rk-share__content ul {
  list-style: disc;
}

.rk-share__content ol {
  list-style: decimal;
}

.rk-share__content blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--rk-border);
  color: var(--rk-text-2);
}

.rk-share__content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: var(--rk-font-size-sm);
  line-height: 1.5;
}

.rk-share__content th,
.rk-share__content td {
  padding: 6px 10px;
  border: 1px solid var(--rk-border);
  text-align: left;
  vertical-align: top;
}

.rk-share__content th {
  background: var(--rk-bg-2, #f1f5f9);
  font-weight: 600;
}


.rk-share__attachments {
  margin-top: 12px;
  padding-left: 1.2rem;
  list-style: disc;
  color: var(--rk-text-2);
  font-size: var(--rk-font-size-sm);
}

.rk-share__empty {
  color: var(--rk-text-2);
}

.rk-share__footer {
  padding-top: 24px;
  margin-top: 32px;
  border-top: 1px solid var(--rk-border);
}

/* ============================================================================
   Accessibility Utilities
   ============================================================================ */

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

/* Focusable for screen readers but visually hidden */
.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Skip to main content link (appears on focus) */
.skip-link {
  position: absolute;
  top: -9999px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--rk-z-modal);
  padding: var(--rk-space-3) var(--rk-space-6);
  background-color: var(--rk-primary);
  color: white;
  text-decoration: none;
  border-radius: 0 0 var(--rk-radius) var(--rk-radius);
  font-weight: var(--rk-font-weight-medium);
}

.skip-link:focus {
  top: 0;
}

/* ============================================================================
   Container Utilities
   ============================================================================ */

.container {
  width: 100%;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--rk-space-4);
  padding-right: var(--rk-space-4);
}

@media (min-width: 768px) {
  .container {
    padding-left: var(--rk-space-6);
    padding-right: var(--rk-space-6);
  }
}

@media (min-width: 1440px) {
  .container {
    padding-left: var(--rk-space-8);
    padding-right: var(--rk-space-8);
  }
}
