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

:root {
    --bg-primary: #111115;
    --bg-secondary: #18181c;
    --bg-surface: #1e1e24;
    --bg-hover: #26262e;
    --border: #2a2a34;
    --text-primary: #e4e4e8;
    --text-secondary: #8e8e9a;
    --text-muted: #5c5c6a;
    --accent: #44d7a8;
    --accent-dim: rgba(68, 215, 168, 0.15);
    --green: #34d399;
    --yellow: #fbbf24;
    --red: #f87171;
    --sidebar-width: 240px;
    --topbar-height: 48px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* === App Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transition: width 0.2s ease, transform 0.2s ease;
    z-index: 100;
    overflow-y: auto;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo {
    height: 32px;
    width: auto;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

/* === Navigation === */
.sidebar-nav {
    padding: 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* === Collapsible Nav Groups === */
.nav-group {
    border: none;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    list-style: none;
}

.nav-group-toggle::-webkit-details-marker {
    display: none;
}

.nav-group-toggle:hover {
    background: var(--bg-hover);
    color: #fff;
}

.nav-chevron {
    margin-left: auto;
    font-size: 14px;
    transition: transform 0.2s ease;
    user-select: none;
}

.nav-group[open] .nav-chevron {
    transform: rotate(90deg);
}

.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-left: 28px;
}

.nav-group-items .nav-item {
    font-size: 13px;
    padding: 6px 12px;
    color: rgba(255, 255, 255, 0.6);
}

.nav-group-items .nav-item:hover {
    color: #fff;
}

/* === Nav Separator === */
.nav-separator {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

/* === Main Content === */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 0;
}

/* === Top Bar === */
.topbar {
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    line-height: 1;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-dim);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

/* === Page Content === */
.page-content {
    padding: 24px;
    flex: 1;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 4px;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-change {
    font-size: 12px;
    margin-top: 4px;
    font-weight: 500;
}

.stat-change.positive { color: var(--green); }
.stat-change.negative { color: var(--red); }

/* === Dashboard Grid === */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* === Cards === */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.card-body {
    padding: 14px 18px;
}

/* === Activity List === */
.activity-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.activity-dot.green { background: var(--green); }
.activity-dot.yellow { background: var(--yellow); }
.activity-dot.red { background: var(--red); }

.activity-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.activity-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-time {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 12px;
}

/* === Data Table === */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 10px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge.green {
    background: rgba(52, 211, 153, 0.15);
    color: var(--green);
}

.badge.yellow {
    background: rgba(251, 191, 36, 0.15);
    color: var(--yellow);
}

.badge.red {
    background: rgba(248, 113, 113, 0.15);
    color: var(--red);
}

/* === Table Extras === */
.table-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.table-link:hover {
    text-decoration: underline;
}

.data-table code {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 0 !important;
}

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

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.pagination-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: background 0.15s;
}

.pagination-btn:hover:not(.disabled) {
    background: var(--bg-hover);
}

.pagination-btn.disabled {
    color: var(--text-muted);
    cursor: default;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-page {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.pagination-page:hover:not(.active) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.pagination-page.active {
    background: var(--accent);
    color: var(--bg-primary);
    font-weight: 600;
}

.pagination-ellipsis {
    width: 32px;
    text-align: center;
    color: var(--text-muted);
}

/* === Forms === */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-input-error {
    border-color: var(--red);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
}

.form-error {
    display: block;
    font-size: 12px;
    color: var(--red);
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    border: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
}

.btn-primary:hover {
    background: #38c99a;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--red);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.25);
}

/* === Conversation New === */
.conversation-new {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--topbar-height) - 48px);
}

.conversation-new-inner {
    width: 100%;
    max-width: 640px;
}

.conversation-new-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 20px;
    text-align: center;
}

.conversation-textarea {
    min-height: 140px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
}

.conversation-form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

/* === Conversation Detail === */
.conversation-detail {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 48px);
}

.conversation-messages {
    flex: 1;
    overflow-y: auto;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.conversation-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-message-role {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.conversation-message--assistant .conversation-message-role {
    color: var(--accent);
}

.conversation-message-content {
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
}

.thinking-logo {
    height: 24px;
    width: auto;
    animation: pulse 1.5s ease-in-out infinite;
}

.thinking-text {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.conversation-input-bar {
    position: sticky;
    bottom: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    padding: 16px 0;
}

.conversation-input-form {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.conversation-input-textarea {
    flex: 1;
    min-height: 40px;
    max-height: 160px;
    resize: none;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
}

.conversation-send-btn {
    flex-shrink: 0;
    height: 40px;
}

/* === Poll Indicator === */
.poll-indicator {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.2s;
    z-index: 200;
}

.poll-indicator--green { background: var(--green); }
.poll-indicator--orange { background: var(--yellow); }
.poll-indicator--red { background: var(--red); }

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo {
    height: 48px;
    width: auto;
    margin-bottom: 12px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.login-error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--red);
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.login-btn {
    width: 100%;
    margin-top: 8px;
    padding: 10px 16px;
}

/* === Responsive === */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .sidebar.collapsed {
        transform: translateX(-100%);
    }
    .main-content {
        margin-left: 0;
    }
}