/* ============================================================
   Design System — Trợ lý ảo Phường/Xã
   Government-grade, mobile-first, accessible.
   Keeps existing class names so all templates keep working.
   ============================================================ */

:root {
    --primary: hsl(220, 82%, 46%);
    --primary-600: hsl(220, 82%, 42%);
    --primary-700: hsl(220, 82%, 36%);
    --primary-050: hsl(220, 82%, 96%);
    --primary-100: hsl(220, 82%, 92%);

    --success: hsl(155, 54%, 38%);
    --warning: hsl(32, 95%, 44%);
    --error: hsl(0, 72%, 51%);

    --ink: #0f172a;
    --ink-soft: #475569;
    --muted: #64748b;
    --line: #e5e7eb;
    --line-soft: #eef2f7;
    --bg: #f6f8fb;
    --surface: #ffffff;

    --radius-sm: 0.5rem;
    --radius: 0.75rem;
    --radius-lg: 1rem;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.14);

    --ring: 0 0 0 3px hsla(220, 82%, 46%, 0.18);
}

/* ---------- Global niceties ---------- */
* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Larger, friendlier base text for citizens (many older users) */
main { font-size: 1rem; line-height: 1.6; }

h1, h2, h3, h4 { letter-spacing: -0.01em; }

a { transition: color 0.15s; }

:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: 4px;
}

::selection { background: var(--primary-100); color: var(--primary-700); }

/* Nicer scrollbars on desktop */
@media (pointer: fine) {
    ::-webkit-scrollbar { width: 10px; height: 10px; }
    ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid var(--bg); }
    ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
}

/* ---------- Form controls ---------- */
.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 0.625rem 0.85rem;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background-color: var(--surface);
    color: var(--ink);
    transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.form-textarea { resize: vertical; min-height: 90px; line-height: 1.6; }

.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

input::placeholder, textarea::placeholder { color: #9aa5b1; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.925rem;
    font-weight: 600;
    line-height: 1.2;
    transition: transform 0.12s ease, box-shadow 0.15s ease, background-color 0.15s ease, border-color 0.15s;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background-image: linear-gradient(180deg, var(--primary), var(--primary-600));
    color: #fff;
    box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
    background-image: linear-gradient(180deg, var(--primary-600), var(--primary-700));
    box-shadow: var(--shadow-sm);
}

.btn-outline {
    background-color: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-xs);
}
.btn-outline:hover:not(:disabled) {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.btn-danger { background-color: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled) { background-color: hsl(0, 72%, 45%); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--line-soft); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1.05rem; border-radius: var(--radius); }
.btn-block { width: 100%; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.7rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid transparent;
}
.badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
}
.badge-pending  { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-answered, .badge-processed { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.badge-need-info, .badge-rejected { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ---------- Cards ---------- */
.card {
    background-color: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--line-soft); }
.card-content { padding: 1.5rem; }

/* ---------- Toggle switch (checkbox + slider markup) ---------- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    vertical-align: middle;
}
.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background-color: #cbd5e1;
    border-radius: 9999px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease;
}
.toggle-switch input:checked + .toggle-slider { background-color: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle-switch input:focus-visible + .toggle-slider { box-shadow: var(--ring); }

/* Legacy .active variant (kept for any JS-driven toggles) */
.toggle-switch.active { background-color: var(--primary); }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background-color: #f8fafc; }
.data-table th {
    padding: 0.75rem 1.5rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.data-table td { padding: 0.9rem 1.5rem; }
.data-table tbody tr { border-top: 1px solid var(--line-soft); }
.data-table tbody tr:hover { background-color: #f8fafc; }

/* ---------- Tabs (segmented) ---------- */
.tab-list { display: inline-flex; background-color: #eef2f7; border-radius: var(--radius-sm); padding: 0.25rem; }
.tab-trigger {
    padding: 0.5rem 1rem; border-radius: 0.4rem; font-size: 0.875rem; font-weight: 600;
    color: var(--muted); cursor: pointer; transition: all 0.15s; border: none; background: none;
}
.tab-trigger:hover { color: var(--ink); }
.tab-trigger.active { background-color: var(--surface); color: var(--ink); box-shadow: var(--shadow-xs); }

/* Underline tab links (dashboard / knowledge) */
.tab-link { transition: color 0.15s, border-color 0.15s; }
.tab-active { border-color: var(--primary) !important; color: var(--primary) !important; }
.tab-inactive { border-color: transparent; color: var(--muted); }
.tab-inactive:hover { color: var(--ink); border-color: #cbd5e1; }

/* ---------- Stat tile ---------- */
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 1rem;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.stat-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon {
    width: 46px; height: 46px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0;
}

/* ---------- Utility helpers ---------- */
.hover-lift { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.hover-lift:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.glass-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
}

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius-sm); border: 1px solid; padding: 0.85rem 1rem; font-size: 0.9rem; }

/* ---------- Animations ---------- */
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.animate-spin { animation: spin 1s linear infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.animate-pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.animate-in { animation: fadeInUp 0.4s ease both; }

@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.animate-float { animation: float 5s ease-in-out infinite; }

@keyframes haloPulse { 0%, 100% { transform: scale(1); opacity: 0.55; } 50% { transform: scale(1.08); opacity: 0.9; } }

/* Staggered entrance for a group of children */
.stagger > * { opacity: 0; animation: fadeInUp 0.55s ease forwards; }
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.14s; }
.stagger > *:nth-child(3) { animation-delay: 0.23s; }
.stagger > *:nth-child(4) { animation-delay: 0.32s; }
.stagger > *:nth-child(5) { animation-delay: 0.41s; }
.stagger > *:nth-child(6) { animation-delay: 0.50s; }

/* Emblem halo (behind centered logo) */
.emblem-halo { animation: haloPulse 4s ease-in-out infinite; }

/* Copy button feedback */
.copied { background-color: var(--success) !important; color: #fff !important; border-color: var(--success) !important; }

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

/* ---------- Accessibility: bigger touch targets on mobile ---------- */
@media (max-width: 640px) {
    .btn { padding: 0.7rem 1.1rem; }
    main { font-size: 1.02rem; }
}
