/* ============================================================
   DESIGN SYSTEM — VietnamCOS Courses Platform
   Centralized tokens, typography, components.
   All pages should import this file. No purple. No gradients.
   ============================================================ */

/* === DESIGN TOKENS === */
:root {
    /* --- Primary (Blue) --- */
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-active: #1E40AF;
    --primary-light: #DBEAFE;
    --primary-lighter: #EFF6FF;

    /* --- Accent (Dark Orange) --- */
    --accent: #D97706;
    --accent-hover: #B45309;
    --accent-light: #FEF3C7;
    --accent-lighter: #FFFBEB;

    /* --- Neutrals --- */
    --black: #111827;
    --gray-900: #1F2937;
    --gray-800: #374151;
    --gray-700: #4B5563;
    --gray-600: #6B7280;
    --gray-500: #9CA3AF;
    --gray-400: #D1D5DB;
    --gray-300: #E5E7EB;
    --gray-200: #F3F4F6;
    --gray-100: #F9FAFB;
    --white: #FFFFFF;

    /* --- Semantic --- */
    --success: #059669;
    --success-light: #D1FAE5;
    --error: #DC2626;
    --error-light: #FEE2E2;
    --warning: #D97706;
    --warning-light: #FEF3C7;
    --info: #2563EB;
    --info-light: #DBEAFE;

    /* --- Surfaces --- */
    --surface-page: #F3F4F6;
    --surface-card: #FFFFFF;
    --surface-raised: #FFFFFF;
    --surface-inset: #F9FAFB;
    --surface-dark: #1F2937;
    --surface-dark-hover: #374151;

    /* --- Borders --- */
    --border: #E5E7EB;
    --border-strong: #D1D5DB;
    --border-focus: #2563EB;

    /* --- Typography --- */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1rem;     /* 16px */
    --text-lg: 1.125rem;   /* 18px */
    --text-xl: 1.25rem;    /* 20px */
    --text-2xl: 1.5rem;    /* 24px */
    --text-3xl: 1.875rem;  /* 30px */
    --text-4xl: 2.25rem;   /* 36px */

    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* --- Spacing (8px base) --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* --- Radius --- */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* --- Shadows (subtle, no heavy drops) --- */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

    /* --- Transitions --- */
    --transition-fast: 150ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;

    /* --- Layout --- */
    --max-width: 1200px;
    --header-height: 56px;
    --sidebar-width: 240px;
}


/* === RESET === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    color: var(--gray-700);
    background-color: var(--surface-page);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

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

a:hover {
    color: var(--primary-hover);
}


/* === TYPOGRAPHY === */
h1, h2, h3, h4, h5, h6 {
    color: var(--black);
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
}

h1 { font-size: var(--text-2xl); font-weight: var(--font-bold); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-base); }
h4 { font-size: var(--text-sm); font-weight: var(--font-medium); }

p {
    color: var(--gray-700);
    line-height: var(--leading-relaxed);
}

.text-muted { color: var(--gray-600); }
.text-small { font-size: var(--text-xs); }

.label {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}


/* === LAYOUT === */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-6);
}

.section {
    padding: var(--space-12) 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
    gap: var(--space-4);
}

.section-header h2 {
    margin: 0;
}

.grid {
    display: grid;
    gap: var(--space-6);
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.grid-auto {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}


/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    height: 36px;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--white);
}

.btn-accent {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}
.btn-accent:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--white);
}

.btn-secondary {
    background: var(--white);
    color: var(--gray-800);
    border-color: var(--border-strong);
}
.btn-secondary:hover {
    background: var(--gray-100);
    border-color: var(--gray-500);
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--primary-lighter);
}

.btn-danger {
    background: var(--error);
    color: var(--white);
    border-color: var(--error);
}
.btn-danger:hover {
    background: #B91C1C;
}

.btn-lg {
    height: 44px;
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
}

.btn-sm {
    height: 28px;
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

.btn-icon {
    width: 36px;
    padding: 0;
    justify-content: center;
}


/* === CARD === */
.card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    transition: border-color var(--transition-fast);
}

.card-hover:hover {
    border-color: var(--primary);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.card-body {
    flex: 1;
}

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


/* === BADGES === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-sm);
    line-height: 1.5;
}

.badge-default {
    background: var(--gray-200);
    color: var(--gray-700);
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-accent {
    background: var(--accent-light);
    color: var(--accent);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-error {
    background: var(--error-light);
    color: var(--error);
}


/* === FORM CONTROLS === */
.input,
.select,
.textarea {
    width: 100%;
    height: 40px;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--gray-900);
    background: var(--white);
    border: 1px solid var(--gray-400);
    border-radius: var(--radius);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input::placeholder {
    color: var(--gray-500);
}

.textarea {
    height: auto;
    min-height: 80px;
    resize: vertical;
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--gray-800);
}


/* === HEADER / NAV === */
.ds-header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
}

.ds-nav {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    gap: var(--space-4);
}

.ds-nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: var(--black);
    font-weight: var(--font-bold);
    font-size: var(--text-lg);
    flex-shrink: 0;
}

.ds-nav-brand img {
    height: 28px;
    width: auto;
}

.ds-nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.ds-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--gray-700);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
    text-decoration: none;
}

.ds-nav-link:hover {
    color: var(--black);
    background: var(--gray-200);
}

.ds-nav-link.active {
    color: var(--primary);
    background: var(--primary-lighter);
}


/* === STAT CARDS === */
.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.stat-card .stat-value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--black);
}

.stat-card .stat-label {
    font-size: var(--text-xs);
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-card.stat-primary { border-left: 3px solid var(--primary); }
.stat-card.stat-accent { border-left: 3px solid var(--accent); }
.stat-card.stat-success { border-left: 3px solid var(--success); }


/* === PROGRESS BAR === */
.progress-track {
    width: 100%;
    height: 6px;
    background: var(--gray-300);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius-sm);
    transition: width var(--transition-slow);
}


/* === TABLE === */
.ds-table {
    width: 100%;
    border-collapse: collapse;
}

.ds-table thead th {
    background: var(--gray-200);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.ds-table tbody td {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--gray-800);
    border-bottom: 1px solid var(--border);
}

.ds-table tbody tr:hover {
    background: var(--gray-100);
}


/* === PAGINATION === */
.pagination {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    justify-content: center;
    margin-top: var(--space-8);
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 var(--space-2);
    font-size: var(--text-sm);
    color: var(--gray-700);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.page-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.page-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}


/* === MODAL === */
.ds-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ds-modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 100%;
    margin: var(--space-4);
}

.ds-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5);
    border-bottom: 1px solid var(--border);
}

.ds-modal-body {
    padding: var(--space-5);
}

.ds-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border);
}


/* === TOAST === */
.ds-toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    box-shadow: var(--shadow-md);
}

.ds-toast-success { background: var(--success-light); color: var(--success); border-left: 3px solid var(--success); }
.ds-toast-error { background: var(--error-light); color: var(--error); border-left: 3px solid var(--error); }
.ds-toast-warning { background: var(--warning-light); color: var(--warning); border-left: 3px solid var(--warning); }
.ds-toast-info { background: var(--info-light); color: var(--info); border-left: 3px solid var(--info); }


/* === FOOTER === */
.ds-footer {
    background: var(--gray-900);
    color: var(--gray-400);
    padding: var(--space-12) 0 var(--space-8);
}

.ds-footer a {
    color: var(--gray-400);
}

.ds-footer a:hover {
    color: var(--white);
}

.ds-footer h4 {
    color: var(--white);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}


/* === UTILITY === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }


/* === RESPONSIVE === */
@media (max-width: 1024px) {
    .container {
        padding: 0 var(--space-4);
    }
}

@media (max-width: 768px) {
    h1 { font-size: var(--text-xl); }
    h2 { font-size: var(--text-lg); }

    .section {
        padding: var(--space-8) 0;
    }

    .ds-nav-links {
        display: none;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 var(--space-3);
    }
}

/* ═══ Geo-blocking: hide download info for non-Vietnam users ═══ */
body.geo-blocked .geo-dl {
    display: none !important;
}


/* ════════════════════════════════════════════════════════════
   DESIGN SYSTEM v2 — contrast-safe tokens + layout primitives
   Additive only (new tokens + new class names). See docs/design-guidelines.md.
   ════════════════════════════════════════════════════════════ */
:root {
    /* Text-on-color — ALWAYS use these for text placed on a colored/dark surface.
       Never put a gray/inherited color on --primary, --accent, or --surface-dark
       (that is the dark-on-dark / unreadable bug). */
    --text-on-primary: #FFFFFF;
    --text-on-accent:  #FFFFFF;
    --text-on-dark:    #F9FAFB;      /* primary text on --surface-dark */
    --text-on-dark-muted: #D1D5DB;   /* secondary text on --surface-dark */

    /* Interaction */
    --tap-min: 44px;                 /* minimum touch-target on mobile */
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.35);

    /* Breakpoints (reference values; mirror these exact numbers in @media) */
    --bp-sm: 480px;
    --bp-md: 768px;
    --bp-lg: 1024px;
}

/* Vertical rhythm: children get one consistent gap — no ad-hoc margins that
   collide or overlap. Override the gap per context with --stack-gap. */
.stack { display: flex; flex-direction: column; }
.stack > * { margin-block: 0; }
.stack > * + * { margin-top: var(--stack-gap, var(--space-4)); }

/* Horizontal group that wraps cleanly with even gaps (prevents overlap). */
.cluster { display: flex; flex-wrap: wrap; gap: var(--cluster-gap, var(--space-3)); align-items: center; }

/* Responsive auto grid — set --col-min per use (e.g. style="--col-min:260px"). */
.auto-fit { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(var(--col-min, 240px), 1fr)); }

/* Keyboard focus everywhere (only shows for keyboard users — safe + accessible). */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* Responsive visibility helpers (mobile-first: design the small screen on purpose). */
@media (max-width: 480px)  { .u-hide-sm { display: none !important; } }
@media (min-width: 769px)  { .u-hide-lg { display: none !important; } }

/* On touch widths, primary interactive controls meet the minimum tap target. */
@media (max-width: 768px) {
    .btn { min-height: var(--tap-min); }
}
