/* ============================================
   AI Parliamentary Drafting System
   Kementerian Pengangkutan Malaysia
   ============================================ */

:root {
    /* MOT (Kementerian Pengangkutan) navy ramp — centred on the live MOT brand navy #193B6A */
    --navy-900: #07182f;
    --navy-800: #0d2748;
    --navy-700: #11305a;
    --navy-600: #193B6A;   /* MOT navy — primary header/surface */
    --navy-500: #24487f;   /* MOT navy (lighter) — hovers, gradients */
    --navy-400: #3a6fb5;
    --navy-300: #6a9fd8;
    --navy-200: #a3c4e9;
    --navy-100: #d4e3f5;
    --navy-50:  #edf3fa;

    /* Primary interactive accent — MOT bright blue (replaces the former gold accent,
       matching the /copilot reskin). Var names kept as --gold-* so all existing
       references flip centrally without touching every rule. */
    --gold-500: #2680EB;   /* MOT bright blue — "look here" accent */
    --gold-400: #4a95ef;   /* MOT blue, lighter/hover */
    --gold-300: #7db3f4;   /* MOT blue, soft */

    /* Parliament gold — reserved for emblem / parliamentary cues only (as on /copilot) */
    --gold: #C9A84C;

    --white: #ffffff;
    --gray-50: #f8f9fb;
    --gray-100: #f1f3f7;
    --gray-200: #e2e6ee;
    --gray-300: #ccd2de;
    --gray-400: #9aa3b5;
    --gray-500: #6b7589;
    --gray-600: #4a5568;
    --gray-700: #2d3748;

    --success: #0d7a3f;
    --error: #c53030;

    --font-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
    --font-sans: 'Raleway', 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --shadow-sm: 0 1px 2px rgba(10, 22, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(10, 22, 40, 0.08);
    --shadow-lg: 0 8px 30px rgba(10, 22, 40, 0.12);
    --shadow-xl: 0 12px 40px rgba(10, 22, 40, 0.16);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

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

body {
    font-family: var(--font-sans);
    background-color: var(--gray-50);
    color: var(--gray-700);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Header
   ============================================ */
.header {
    background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 50%, var(--navy-700) 100%);
    border-bottom: 3px solid var(--gold-500);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.emblem {
    flex-shrink: 0;
    opacity: 0.9;
}

.header-title {
    font-family: var(--font-serif);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--white);
    letter-spacing: 0.02em;
    line-height: 1.3;
}

.header-subtitle {
    font-size: 0.8rem;
    color: var(--navy-300);
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 0.15rem;
}

.classification-badge {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gold-500);
    border: 1px solid var(--gold-500);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-sm);
}

/* "Next step" call-to-action — links each pipeline page directly to the next
   stage so users no longer have to bounce back to the dashboard between steps.
   Uses the MOT bright-blue accent as the primary "go here next" affordance. */
.next-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--white);
    background: var(--gold-500);
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    transition: background 0.2s, transform 0.15s;
}

.next-link:hover {
    background: var(--gold-400);
    transform: translateX(2px);
}

.next-link svg {
    flex-shrink: 0;
}

/* ============================================
   Data Sources Bar
   ============================================ */
.sources-bar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
}

.sources-bar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0.6rem 2rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.sources-bar-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--navy-600);
    flex-shrink: 0;
}

.sources-bar-items {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.sources-bar-item {
    font-size: 0.75rem;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.sources-check {
    color: var(--success);
    font-weight: 700;
    font-size: 0.85rem;
}

.sources-label {
    font-weight: 600;
    color: var(--navy-700);
}

.sources-value {
    font-weight: 700;
    color: var(--navy-800);
}

.sources-bar-total {
    border-left: 1px solid var(--gray-300);
    padding-left: 1.5rem;
}

.sources-bar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
    padding: 0.35rem 0.85rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--navy-900);
    background: var(--gold-500);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.sources-bar-btn:hover {
    background: var(--gold-400);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

/* ============================================
   Source Type Badges on References
   ============================================ */
.source-type-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.source-type-badge.badge-hansard {
    background: var(--navy-800);
    color: var(--white);
}

.source-type-badge.badge-mim {
    background: var(--gold-500);
    color: var(--navy-900);
}

/* ============================================
   Main Content
   ============================================ */
.main {
    flex: 1;
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* ============================================
   Section Headers
   ============================================ */
.section-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.section-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: var(--navy-800);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gold-500);
    margin-top: 0.1rem;
}

.section-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--navy-800);
    line-height: 1.3;
}

.section-desc {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: 0.2rem;
}

/* ============================================
   Query Section
   ============================================ */
.query-section {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
    margin-bottom: 2rem;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--navy-600);
    margin-bottom: 0.5rem;
}

.form-textarea {
    width: 100%;
    padding: 1rem 1.25rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--gray-700);
    background: var(--gray-50);
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.form-textarea:focus {
    outline: none;
    border-color: var(--navy-400);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(35, 77, 138, 0.12);
}

.form-textarea::placeholder {
    color: var(--gray-400);
    font-style: italic;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 2rem;
    background: linear-gradient(135deg, var(--navy-700), var(--navy-800));
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--navy-600), var(--navy-700));
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 0.75rem 1.5rem;
    background: var(--white);
    color: var(--gray-500);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: var(--gray-400);
    color: var(--gray-700);
    background: var(--gray-50);
}

/* ============================================
   Loading State
   ============================================ */
.loading-section {
    margin-bottom: 2rem;
}

.loading-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--navy-100);
    border-top-color: var(--navy-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1.5rem;
}

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

.loading-text {
    font-family: var(--font-serif);
    font-size: 1rem;
    color: var(--navy-700);
    font-weight: 600;
}

.loading-subtext {
    font-size: 0.85rem;
    color: var(--gray-400);
    margin-top: 0.35rem;
    font-style: italic;
}

/* ============================================
   Error State
   ============================================ */
.error-card {
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-left: 4px solid var(--error);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    color: var(--error);
    font-weight: 500;
}

/* ============================================
   Results Section
   ============================================ */
.results-section {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* ============================================
   Panels
   ============================================ */
.panel {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--navy-800), var(--navy-900));
    color: var(--white);
    border-bottom: 2px solid var(--gold-500);
}

.panel-header h3 {
    font-family: var(--font-serif);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

/* References Panel */
.references-panel {
    position: sticky;
    top: 100px;
}

.references-list {
    padding: 0.75rem;
    max-height: 70vh;
    overflow-y: auto;
}

.reference-card {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
    margin-bottom: 0.5rem;
    transition: all 0.2s;
    cursor: default;
}

.reference-card:hover {
    border-color: var(--navy-300);
    background: var(--navy-50);
}

.reference-card:last-child {
    margin-bottom: 0;
}

.reference-source {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--navy-500);
    margin-bottom: 0.35rem;
}

.reference-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--navy-800);
    line-height: 1.4;
    margin-bottom: 0.3rem;
}

.reference-excerpt {
    font-size: 0.75rem;
    color: var(--gray-500);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.reference-score {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--success);
    background: #edf7ed;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

/* Draft Panel */
.draft-panel {
    min-height: 400px;
}

.draft-meta {
    padding: 0.6rem 1.5rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.75rem;
    color: var(--gray-500);
    display: flex;
    gap: 1.5rem;
}

.draft-meta span {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.draft-content {
    padding: 2rem 2.5rem;
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--gray-700);
}

.draft-content h1,
.draft-content h2,
.draft-content h3 {
    font-family: var(--font-serif);
    color: var(--navy-800);
    margin-top: 1.8rem;
    margin-bottom: 0.6rem;
}

.draft-content h1 { font-size: 1.25rem; }
.draft-content h2 { font-size: 1.1rem; }
.draft-content h3 { font-size: 1rem; }

.draft-content h2:first-child,
.draft-content h3:first-child {
    margin-top: 0;
}

.draft-content p {
    margin-bottom: 0.8rem;
}

.draft-content ul, .draft-content ol {
    margin: 0.5rem 0 1rem 1.5rem;
}

.draft-content li {
    margin-bottom: 0.3rem;
}

.draft-content strong {
    color: var(--navy-700);
}

.draft-section {
    border-left: 3px solid var(--navy-200);
    padding-left: 1.25rem;
    margin-bottom: 1.5rem;
}

.draft-section-header {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--navy-700);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.draft-section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--navy-800);
    color: var(--gold-500);
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-sans);
    flex-shrink: 0;
}

/* ============================================
   Sentiment Panel (Pillar 1)
   ============================================ */
.sentiment-panel {
    margin-bottom: 1.5rem;
}

.pillar-badge {
    margin-left: auto;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--gold-500);
    border: 1px solid var(--gold-500);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
}

.sentiment-body {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    padding: 1.5rem;
}

.sentiment-col-title {
    font-family: var(--font-serif);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--navy-600);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.75rem;
}

/* Overall gauge */
.sentiment-overall {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.sentiment-gauge {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 4px solid var(--gray-300);
    transition: border-color 0.5s;
}

.sentiment-gauge.sentiment-negative { border-color: #c53030; }
.sentiment-gauge.sentiment-positive { border-color: var(--success); }
.sentiment-gauge.sentiment-mixed    { border-color: var(--gold-500); }
.sentiment-gauge.sentiment-neutral  { border-color: var(--navy-400); }

.gauge-emoji {
    font-size: 1.6rem;
    line-height: 1;
}

.gauge-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-600);
    margin-top: 0.25rem;
    text-align: center;
}

.sentiment-mentions {
    text-align: center;
}

.mentions-count {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--navy-800);
    line-height: 1.2;
}

.mentions-label {
    font-size: 0.65rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sentiment-trend {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
}

.trend-arrow {
    font-size: 1rem;
}

/* Breakdown bars */
.bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.bar-label {
    font-size: 0.7rem;
    color: var(--gray-600);
    min-width: 140px;
    flex-shrink: 0;
}

.bar-track {
    flex: 1;
    height: 10px;
    background: var(--gray-100);
    border-radius: 5px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 5px;
    width: 0%;
    transition: width 0.8s ease-out;
}

.bar-frustration { background: #c53030; }
.bar-approval    { background: var(--success); }
.bar-confusion   { background: #d69e2e; }

.bar-value {
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 36px;
    text-align: right;
    color: var(--navy-700);
}

/* Top concerns */
.concerns-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.concerns-list li {
    position: relative;
    padding-left: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--gray-600);
}

.concerns-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.45em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gold-500);
}

.concern-en {
    display: block;
    font-style: italic;
    color: var(--gray-400);
    font-size: 0.7rem;
}

/* Source chips */
.source-chips {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.source-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--navy-700);
}

.source-chip-pct {
    font-weight: 700;
    color: var(--navy-600);
}

/* ============================================
   Language Toggle
   ============================================ */
.lang-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 0.2rem 0.15rem;
    margin-right: 0.75rem;
}

.lang-opt {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--navy-400);
    padding: 0.2rem 0.6rem;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.lang-opt.active {
    background: var(--gold-500);
    color: var(--navy-900);
}

.lang-opt:hover:not(.active) {
    color: var(--white);
}

.lang-sep {
    font-size: 0.45rem;
    color: var(--navy-600);
    line-height: 1;
}

/* ============================================
   Footer
   ============================================ */
.footer {
    background: var(--navy-900);
    border-top: 2px solid var(--navy-700);
    padding: 1.25rem 2rem;
    margin-top: auto;
}

.footer-inner {
    max-width: 1280px;
    margin: 0 auto;
    text-align: center;
}

.footer p {
    font-size: 0.75rem;
    color: var(--navy-400);
}

.footer-note {
    margin-top: 0.25rem;
    font-style: italic;
    color: var(--navy-500) !important;
    font-size: 0.7rem !important;
}

.footer-version {
    margin-top: 0.2rem;
    font-size: 0.65rem !important;
    color: var(--navy-600) !important;
    letter-spacing: 0.04em;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 960px) {
    .results-grid {
        grid-template-columns: 1fr;
    }

    .references-panel {
        position: static;
    }

    .header-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-meta {
        align-self: flex-start;
    }

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

@media (max-width: 640px) {
    .main {
        padding: 1rem;
    }

    .query-section {
        padding: 1.25rem;
    }

    .draft-content {
        padding: 1.25rem;
    }

    .header-title {
        font-size: 1.1rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .sentiment-body {
        grid-template-columns: 1fr;
    }

    .bar-label {
        min-width: 100px;
    }
}

/* ============================================
   Scrollbar
   ============================================ */
.references-list::-webkit-scrollbar {
    width: 6px;
}

.references-list::-webkit-scrollbar-track {
    background: var(--gray-100);
}

.references-list::-webkit-scrollbar-thumb {
    background: var(--navy-200);
    border-radius: 3px;
}

.references-list::-webkit-scrollbar-thumb:hover {
    background: var(--navy-300);
}
