/* ============================================================
   TecWindow Social Platform - Accessibility-First Stylesheet
   ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
    /* Colors - WCAG AAA contrast ratios */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f7f9fa;
    --color-bg-tertiary: #eff3f4;
    --color-bg-hover: #e7e7e8;
    --color-bg-overlay: rgba(0, 0, 0, 0.4);
    --color-text-primary: #0f1419;
    --color-text-secondary: #536471;
    --color-text-inverse: #ffffff;
    --color-border: #cfd9de;
    --color-border-focus: #1d9bf0;
    --color-accent: #1d9bf0;
    --color-accent-hover: #1a8cd8;
    --color-accent-active: #1a73b8;
    --color-danger: #f4212e;
    --color-danger-hover: #dc1d29;
    --color-success: #00ba7c;
    --color-repost: #00ba7c;
    --color-like: #f91880;
    --color-verified: #1d9bf0;
    --color-org-badge: #e8a317;

    /* Focus ring */
    --focus-ring: 0 0 0 3px rgba(29, 155, 240, 0.5);
    --focus-ring-offset: 0 0 0 1px var(--color-bg-primary), 0 0 0 4px rgba(29, 155, 240, 0.5);

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-size-xs: 0.8125rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 0.9375rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --line-height-normal: 1.5;
    --line-height-tight: 1.25;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 0.75rem;
    --space-lg: 1rem;
    --space-xl: 1.5rem;
    --space-2xl: 2rem;

    /* Layout */
    --sidebar-width: 275px;
    --main-width: 600px;
    --aside-width: 350px;
    --header-height: 53px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
}

/* ── Dark Theme ────────────────────────────────────────── */
[data-theme="dark"] {
    --color-bg-primary: #15202b;
    --color-bg-secondary: #1e2732;
    --color-bg-tertiary: #263340;
    --color-bg-hover: #2c3640;
    --color-text-primary: #e7e9ea;
    --color-text-secondary: #8b98a5;
    --color-text-inverse: #15202b;
    --color-border: #38444d;
}

/* ── Reset & Base ──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Focus Management ──────────────────────────────────── */
/* Remove default outline, add custom focus ring */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--color-border-focus);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Skip to main content link */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-lg);
    z-index: 10000;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-accent);
    color: var(--color-text-inverse);
    font-weight: 700;
    text-decoration: none;
    border-radius: 0 0 8px 8px;
    transition: top var(--transition-fast);
}

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

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

/* ── Layout ────────────────────────────────────────────── */
.app-layout {
    display: flex;
    max-width: calc(var(--sidebar-width) + var(--main-width) + var(--aside-width));
    margin: 0 auto;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
    padding: var(--space-lg);
}

.app-main {
    width: var(--main-width);
    min-height: 100vh;
    border-right: 1px solid var(--color-border);
}

.app-aside {
    width: var(--aside-width);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: var(--space-xl);
}

/* ── Timeline Header ──────────────────────────────────── */
.timeline-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
}

[data-theme="dark"] .timeline-header {
    background: rgba(21, 32, 43, 0.85);
}

.timeline-tabs {
    display: flex;
    list-style: none;
}

.timeline-tabs [role="tab"] {
    flex: 1;
    padding: var(--space-lg);
    text-align: center;
    font-weight: 700;
    color: var(--color-text-secondary);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    font-size: var(--font-size-base);
    font-family: inherit;
}

.timeline-tabs [role="tab"]:hover {
    background: var(--color-bg-hover);
}

.timeline-tabs [role="tab"][aria-selected="true"] {
    color: var(--color-text-primary);
    border-bottom-color: var(--color-accent);
}

.timeline-tabs [role="tab"]:focus-visible {
    box-shadow: var(--focus-ring);
    border-radius: 0;
}

/* ── Post Card ─────────────────────────────────────────── */
.post-card {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    transition: background var(--transition-fast);
    text-decoration: none;
    color: inherit;
}

.post-card:hover {
    background: var(--color-bg-secondary);
}

.post-card:focus-visible {
    box-shadow: inset var(--focus-ring);
}

.post-avatar {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--color-bg-tertiary);
}

.post-body {
    flex: 1;
    min-width: 0;
}

.post-author-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-xs);
    line-height: var(--line-height-tight);
}

.post-display-name {
    font-weight: 700;
    color: var(--color-text-primary);
}

.post-username {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.post-timestamp {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.post-timestamp::before {
    content: "·";
    margin: 0 var(--space-xs);
}

.post-content {
    margin-top: var(--space-xs);
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.post-content a {
    color: var(--color-accent);
    text-decoration: none;
}

.post-content a:hover {
    text-decoration: underline;
}

/* ── Verification Badge ────────────────────────────────── */
.verified-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    vertical-align: middle;
}

.verified-badge__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.verified-badge__icon--blue {
    color: var(--color-verified);
}

.verified-badge__icon--gold {
    color: var(--color-org-badge);
}

/* Affiliate org avatar beside the badge */
.verified-badge__org-avatar {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--color-bg-primary);
    margin-left: -4px;
}

/* ── Post Actions Toolbar ──────────────────────────────── */
.post-actions {
    display: flex;
    justify-content: space-between;
    max-width: 425px;
    margin-top: var(--space-md);
}

.post-action-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: none;
    border: none;
    border-radius: 9999px;
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
    font-family: inherit;
}

.post-action-btn:focus-visible {
    box-shadow: var(--focus-ring);
}

.post-action-btn--reply:hover {
    color: var(--color-accent);
    background: rgba(29, 155, 240, 0.1);
}

.post-action-btn--repost:hover,
.post-action-btn--repost[aria-pressed="true"] {
    color: var(--color-repost);
    background: rgba(0, 186, 124, 0.1);
}

.post-action-btn--like:hover,
.post-action-btn--like[aria-pressed="true"] {
    color: var(--color-like);
    background: rgba(249, 24, 128, 0.1);
}

.post-action-btn--bookmark:hover,
.post-action-btn--bookmark[aria-pressed="true"] {
    color: var(--color-accent);
    background: rgba(29, 155, 240, 0.1);
}

.post-action-btn__icon {
    width: 18px;
    height: 18px;
}

/* ── Post Media ────────────────────────────────────────── */
.post-media-grid {
    display: grid;
    gap: 2px;
    margin-top: var(--space-md);
    border-radius: 16px;
    overflow: hidden;
}

.post-media-grid--1 { grid-template-columns: 1fr; }
.post-media-grid--2 { grid-template-columns: 1fr 1fr; }
.post-media-grid--3,
.post-media-grid--4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.post-media-item {
    background: var(--color-bg-tertiary);
    overflow: hidden;
}

.post-media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── User Profile Header ──────────────────────────────── */
.profile-header {
    position: relative;
}

.profile-banner {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: var(--color-bg-tertiary);
    display: block;
}

.profile-info {
    padding: 0 var(--space-lg) var(--space-lg);
}

.profile-avatar-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: -42px;
}

.profile-avatar {
    width: 134px;
    height: 134px;
    border-radius: 50%;
    border: 4px solid var(--color-bg-primary);
    object-fit: cover;
    background: var(--color-bg-tertiary);
}

.profile-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: 50px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-xl);
    border-radius: 9999px;
    font-weight: 700;
    font-size: var(--font-size-base);
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition-fast), opacity var(--transition-fast);
    border: none;
    text-decoration: none;
    min-height: 36px;
}

.btn:focus-visible {
    box-shadow: var(--focus-ring-offset);
}

.btn--primary {
    background: var(--color-text-primary);
    color: var(--color-text-inverse);
}

.btn--primary:hover {
    opacity: 0.85;
}

.btn--outline {
    background: transparent;
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.btn--outline:hover {
    background: var(--color-bg-hover);
}

.btn--danger {
    background: var(--color-danger);
    color: white;
}

.btn--danger:hover {
    background: var(--color-danger-hover);
}

.profile-names {
    margin-top: var(--space-md);
}

.profile-display-name {
    font-size: var(--font-size-xl);
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.profile-username {
    color: var(--color-text-secondary);
    font-size: var(--font-size-base);
}

.profile-bio {
    margin-top: var(--space-md);
    white-space: pre-wrap;
}

.profile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-lg);
    margin-top: var(--space-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.profile-meta-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

.profile-stats {
    display: flex;
    gap: var(--space-xl);
    margin-top: var(--space-lg);
    font-size: var(--font-size-sm);
}

.profile-stat {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.profile-stat:hover {
    text-decoration: underline;
}

.profile-stat strong {
    color: var(--color-text-primary);
    font-weight: 700;
}

/* ── Compose Box ───────────────────────────────────────── */
.compose-box {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.compose-input {
    flex: 1;
    min-height: 52px;
    padding: var(--space-md);
    font-size: var(--font-size-xl);
    font-family: inherit;
    border: none;
    resize: none;
    background: none;
    color: var(--color-text-primary);
    line-height: var(--line-height-normal);
}

.compose-input::placeholder {
    color: var(--color-text-secondary);
}

.compose-input:focus {
    outline: none;
}

.compose-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-md);
}

.compose-char-count {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.compose-char-count--warn {
    color: var(--color-org-badge);
}

.compose-char-count--danger {
    color: var(--color-danger);
}

/* ── Loading States ────────────────────────────────────── */
.loading-spinner {
    display: flex;
    justify-content: center;
    padding: var(--space-2xl);
}

.loading-spinner::after {
    content: "";
    width: 28px;
    height: 28px;
    border: 3px solid var(--color-bg-tertiary);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.skeleton {
    background: linear-gradient(90deg, var(--color-bg-tertiary) 25%, var(--color-bg-secondary) 50%, var(--color-bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Navigation ────────────────────────────────────────── */
.nav-list {
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-md) var(--space-lg);
    border-radius: 9999px;
    font-size: var(--font-size-xl);
    color: var(--color-text-primary);
    text-decoration: none;
    transition: background var(--transition-fast);
    font-weight: 400;
}

.nav-link:hover {
    background: var(--color-bg-hover);
}

.nav-link:focus-visible {
    box-shadow: var(--focus-ring);
}

.nav-link[aria-current="page"] {
    font-weight: 700;
}

.nav-link__icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

.nav-link__badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9999px;
    background: var(--color-accent);
    color: white;
    font-size: 0.6875rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1024px) {
    .app-aside { display: none; }
    .app-main { flex: 1; }
}

@media (max-width: 768px) {
    .app-sidebar {
        width: auto;
        padding: var(--space-sm);
    }
    .nav-link span:not(.sr-only) { display: none; }
    .nav-link { justify-content: center; padding: var(--space-md); }
    .profile-avatar { width: 84px; height: 84px; }
    .profile-banner { height: 130px; }
    .profile-avatar-row { margin-top: -30px; }
}

/* ── Reduced Motion ────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── High Contrast Mode ────────────────────────────────── */
@media (forced-colors: active) {
    .verified-badge__icon {
        forced-color-adjust: none;
    }
    .post-action-btn[aria-pressed="true"] {
        border: 2px solid ButtonText;
    }
}
