/* ============================================================
   HR Policy Assistant — Design System & Responsive Styles
   ============================================================ */

/* --- CSS Custom Properties (Dark theme default) --- */
:root {
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

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

    /* Sidebar */
    --sidebar-w: 300px;

    /* Transitions */
    --ease: cubic-bezier(.4, 0, .2, 1);
    --dur: .25s;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-tertiary: #1a1a3e;
    --bg-surface: rgba(255, 255, 255, .04);
    --bg-surface-hover: rgba(255, 255, 255, .08);
    --bg-glass: rgba(18, 18, 42, .75);
    --border: rgba(255, 255, 255, .08);
    --border-focus: rgba(99, 102, 241, .5);
    --text-primary: #f0f0ff;
    --text-secondary: #a0a0c0;
    --text-muted: #606080;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, .25);
    --accent2: #a855f7;
    --msg-user-bg: linear-gradient(135deg, #6366f1, #7c3aed);
    --msg-bot-bg: rgba(255, 255, 255, .05);
    --scrollbar-thumb: rgba(255, 255, 255, .12);
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg-primary: #f5f5ff;
    --bg-secondary: #ebebfa;
    --bg-tertiary: #ddddf5;
    --bg-surface: rgba(0, 0, 0, .03);
    --bg-surface-hover: rgba(0, 0, 0, .06);
    --bg-glass: rgba(245, 245, 255, .8);
    --border: rgba(0, 0, 0, .08);
    --border-focus: rgba(99, 102, 241, .4);
    --text-primary: #1a1a2e;
    --text-secondary: #555570;
    --text-muted: #999;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, .15);
    --accent2: #a855f7;
    --msg-user-bg: linear-gradient(135deg, #6366f1, #7c3aed);
    --msg-bot-bg: rgba(0, 0, 0, .03);
    --scrollbar-thumb: rgba(0, 0, 0, .12);
}

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

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    height: 100%;
    font-family: var(--font-main);
    font-size: 15px;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    overflow-x: hidden;
    line-height: 1.6;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    color: inherit;
}

textarea {
    font-family: inherit;
    color: inherit;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* --- Animated Background --- */
.bg-animation {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: .15;
    animation: orbFloat 20s ease-in-out infinite;
}

.bg-orb--1 {
    width: 500px;
    height: 500px;
    background: #6366f1;
    top: -10%;
    left: -5%;
}

.bg-orb--2 {
    width: 400px;
    height: 400px;
    background: #a855f7;
    bottom: -10%;
    right: -5%;
    animation-delay: -7s;
}

.bg-orb--3 {
    width: 300px;
    height: 300px;
    background: #3b82f6;
    top: 50%;
    left: 50%;
    animation-delay: -14s;
}

@keyframes orbFloat {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -40px) scale(1.05);
    }

    66% {
        transform: translate(-20px, 30px) scale(.95);
    }
}

/* ============================================================
   APP LAYOUT — Desktop: sidebar + main  |  Mobile: drawer + main
   ============================================================ */
.app {
    position: relative;
    z-index: 1;
    display: flex;
    height: 100vh;
    height: 100dvh;
    /* dynamic vh for mobile */
    max-width: 100vw;
    overflow-x: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-glass);
    backdrop-filter: blur(24px) saturate(1.4);
    border-right: 1px solid var(--border);
    transition: transform var(--dur) var(--ease);
}

.sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    box-sizing: border-box;
    height: 60px;
    border-bottom: 1px solid var(--border);
}

.sidebar__close {
    display: none;
}

/* visible only on mobile */
.brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.brand__icon svg {
    width: 36px;
    height: 36px;
}

.brand__text {
    display: flex;
    flex-direction: column;
}

.brand__name {
    font-weight: 700;
    font-size: 15px;
}

.brand__sub {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar__body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

.sidebar__section {
    margin-bottom: var(--space-xl);
}

.sidebar__label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}

.sidebar__hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}



/* Topic buttons */
.topic-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.topic-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-align: left;
    background: var(--bg-surface);
    border: 1px solid transparent;
    transition: all var(--dur) var(--ease);
}

.topic-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border);
    transform: translateX(4px);
}

.topic-btn__icon {
    font-size: 16px;
    flex-shrink: 0;
}

/* Sidebar footer */
.sidebar__footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border);
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 12px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    transition: all var(--dur) var(--ease);
}

.new-chat-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.device-badge {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    font-size: 11px;
    color: var(--text-muted);
    justify-content: center;
}

.device-badge__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .4;
    }
}

/* --- Sidebar overlay (mobile) --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, .5);
    backdrop-filter: blur(4px);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    position: relative;
    overflow-x: hidden;
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0 var(--space-lg);
    box-sizing: border-box;
    height: 60px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.topbar__menu {
    display: none;
}

/* visible on mobile */
.topbar__new-chat {
    display: none;
}

.new-chat-text {
    display: none;
}

/* visible on mobile */
.topbar__title {
    flex: 1;
}

.topbar__title h1 {
    font-size: 18px;
    font-weight: 700;
}

.topbar__status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot--online {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, .5);
}

.topbar__btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    transition: background var(--dur) var(--ease);
}

.topbar__btn:hover {
    background: var(--bg-surface-hover);
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Theme toggle — more visible in light mode */
[data-theme="light"] .topbar__theme {
    background: rgba(0, 0, 0, .08);
    border: 1px solid rgba(0, 0, 0, .12);
    color: #1a1a2e;
}

[data-theme="light"] .topbar__theme:hover {
    background: rgba(0, 0, 0, .14);
    border-color: rgba(0, 0, 0, .2);
}

/* Chat area */
.chat {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
}

/* Welcome screen */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-xl);
    animation: fadeUp .6s var(--ease);
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome__glow {
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow), transparent 70%);
    pointer-events: none;
    z-index: -1;
}

.welcome__icon svg {
    width: 72px;
    height: 72px;
    margin-bottom: var(--space-lg);
}

.welcome__title {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: var(--space-sm);
}

.welcome__sub {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 460px;
    margin-bottom: var(--space-xl);
}

.welcome__chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: center;
    max-width: 600px;
}

.chip {
    padding: 10px 18px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    transition: all var(--dur) var(--ease);
    white-space: nowrap;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* Messages */
.messages {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding-bottom: var(--space-md);
}

.messages:empty {
    display: none;
}

.msg {
    display: flex;
    gap: var(--space-sm);
    max-width: 780px;
    animation: msgIn .35s var(--ease);
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg--bot {
    align-self: flex-start;
}

.msg__avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.msg--user .msg__avatar {
    background: var(--msg-user-bg);
    color: #fff;
}

.msg--bot .msg__avatar {
    background: var(--bg-surface);
    border: 1px solid var(--border);
}

.msg__bubble {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.7;
    position: relative;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
    overflow-x: hidden;
}

.msg--user .msg__bubble {
    background: var(--msg-user-bg);
    color: #fff;
    border-bottom-right-radius: var(--space-xs);
}

.msg--bot .msg__bubble {
    background: var(--msg-bot-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: var(--space-xs);
}

/* Markdown inside bot bubbles */
.msg--bot .msg__bubble h1,
.msg--bot .msg__bubble h2,
.msg--bot .msg__bubble h3 {
    margin: var(--space-md) 0 var(--space-sm);
    font-weight: 700;
}

.msg--bot .msg__bubble h1 {
    font-size: 18px;
}

.msg--bot .msg__bubble h2 {
    font-size: 16px;
}

.msg--bot .msg__bubble h3 {
    font-size: 15px;
}

.msg--bot .msg__bubble p {
    margin-bottom: var(--space-sm);
}

.msg--bot .msg__bubble ul,
.msg--bot .msg__bubble ol {
    padding-left: var(--space-lg);
    margin-bottom: var(--space-sm);
}

.msg--bot .msg__bubble li {
    margin-bottom: var(--space-xs);
}

.msg--bot .msg__bubble code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-surface);
    padding: 2px 6px;
    border-radius: 4px;
}

.msg--bot .msg__bubble strong {
    font-weight: 600;
    color: var(--accent-hover);
}

.msg--bot .msg__bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: var(--space-md);
    color: var(--text-secondary);
    margin: var(--space-sm) 0;
}

/* Tables inside bot messages */
.msg--bot .msg__bubble .table-wrap {
    overflow-x: auto;
    margin: var(--space-md) 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}

.msg--bot .msg__bubble table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    line-height: 1.5;
}

.msg--bot .msg__bubble thead th {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    padding: 10px 16px;
    text-align: left;
    white-space: nowrap;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .6px;
    border-bottom: 2px solid rgba(255, 255, 255, .15);
}

.msg--bot .msg__bubble thead th:first-child {
    border-top-left-radius: var(--radius-md);
}

.msg--bot .msg__bubble thead th:last-child {
    border-top-right-radius: var(--radius-md);
}

.msg--bot .msg__bubble tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.msg--bot .msg__bubble tbody tr:last-child td {
    border-bottom: none;
}

.msg--bot .msg__bubble tbody tr:nth-child(even) td {
    background: var(--bg-surface);
}

.msg--bot .msg__bubble tbody tr:hover td {
    background: var(--accent-glow);
    transition: background .15s var(--ease);
}

/* References */
.msg__refs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border);
}

.msg__ref {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* Typing indicator */
.typing {
    display: flex;
    gap: 5px;
    padding: var(--space-md);
    align-items: center;
}

.typing__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing__dot:nth-child(2) {
    animation-delay: .2s;
}

.typing__dot:nth-child(3) {
    animation-delay: .4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: .4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Input area */
.input-area {
    padding: var(--space-sm) var(--space-lg) var(--space-lg);
    background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
}

.input-area__inner {
    max-width: 780px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-sm);
    transition: border-color var(--dur) var(--ease);
}

.input-wrapper:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.message-input {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    padding: var(--space-sm) var(--space-md);
    font-size: 15px;
    max-height: 150px;
    line-height: 1.5;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #ffffff;
    flex-shrink: 0;
    transition: all var(--dur) var(--ease);
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: .35;
    cursor: default;
}

.input-area__note {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: var(--space-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}


/* ============================================================
   RESPONSIVE — MOBILE (< 768px)
   ============================================================ */
@media (max-width: 767px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        width: 85vw;
        max-width: 340px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar__close {
        display: flex;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .topbar__menu {
        display: flex;
    }

    .topbar__new-chat {
        display: flex;
        width: auto;
        padding: 0 12px;
        gap: 6px;
        font-size: 13px;
        font-weight: bold;
    }

    .new-chat-text {
        display: inline;
    }

    .chat {
        padding: var(--space-sm);
        overflow-x: hidden;
    }

    .welcome {
        padding: var(--space-sm);
    }

    .welcome__title {
        font-size: 22px;
    }

    .welcome__sub {
        font-size: 14px;
    }

    .welcome__icon svg {
        width: 56px;
        height: 56px;
    }

    .welcome__chips {
        gap: var(--space-xs);
    }

    .chip {
        padding: 8px 14px;
        font-size: 12px;
        white-space: normal;
    }

    .msg {
        max-width: 100%;
    }

    .msg__bubble {
        padding: var(--space-sm) var(--space-md);
        font-size: 13px;
    }

    .msg__avatar {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }

    /* Tables: compact and wrapping on mobile */
    .msg--bot .msg__bubble .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .msg--bot .msg__bubble thead th {
        padding: 8px 10px;
        font-size: 11px;
        white-space: normal;
    }

    .msg--bot .msg__bubble tbody td {
        padding: 8px 10px;
        font-size: 12px;
        white-space: normal;
    }

    .msg--bot .msg__bubble table {
        font-size: 12px;
    }

    .input-area {
        padding: var(--space-sm) var(--space-sm) var(--space-md);
    }

    .topbar {
        padding: var(--space-sm) var(--space-md);
    }

    .topbar__title h1 {
        font-size: 16px;
    }

    .bg-orb {
        display: none;
    }
}

/* --- Tablet (768-1024) --- */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        --sidebar-w: 260px;
    }

    .welcome__title {
        font-size: 26px;
    }
}

/* --- Large desktop (>1400) --- */
@media (min-width: 1400px) {
    .msg {
        max-width: 860px;
    }

    .input-area__inner {
        max-width: 860px;
    }
}

/* Theme toggle icon switch */
[data-theme="dark"] .icon-sun {
    display: block;
}

[data-theme="dark"] .icon-moon {
    display: none !important;
}

[data-theme="light"] .icon-sun {
    display: none !important;
}

[data-theme="light"] .icon-moon {
    display: block !important;
}