/* Base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    min-height: 100vh;
}

a {
    text-decoration: none;
}

/* Prompt Bar - Full Width */
.prompt-bar {
    background: var(--prompt-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
}

.prompt-toggle {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
    font-size: 0.9rem;
}

.toggle-icon {
    transition: transform 0.2s;
}

.prompt-content {
    margin-top: 0.5rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 4px;
}

.prompt-info {
    margin-bottom: 0.75rem;
}

.prompt-info label {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.25rem;
}

.copy-field {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.copy-field code {
    background: var(--code-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-size: 0.85rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.prompt-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Layout with Sidebar */
.app-layout {
    display: flex;
    min-height: calc(100vh - 60px);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand a {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-brand .logo-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
    border: 1px solid var(--border-color);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-section {
    padding: 0 0.75rem;
    margin-bottom: 1.5rem;
}

.nav-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    color: var(--text-color);
    border-radius: 6px;
    margin-bottom: 0.25rem;
    transition: background 0.15s;
}

.nav-link:hover {
    background: var(--hover-bg);
}

.nav-link.active {
    background: var(--hover-bg);
    font-weight: 500;
}

.nav-link svg {
    width: 18px;
    height: 18px;
    opacity: 0.7;
}

.nav-link.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.theme-selector {
    display: flex;
    gap: 0.5rem;
}

.theme-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

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

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

.logout-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.logout-link:hover {
    color: var(--text-color);
}

/* Main Wrapper */
.main-wrapper {
    flex: 1;
    margin-left: 260px;
    min-height: 100vh;
}

/* Mobile hamburger menu */
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    color: var(--text-color);
}

.hamburger svg {
    width: 24px;
    height: 24px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* Main content */
.main-content {
    padding: 1.5rem 2rem;
}

/* Flash messages */
.flash-messages {
    margin-bottom: 1rem;
}

.flash-message {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flash-message button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.6;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: center;
    transition: background 0.15s;
}

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

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

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

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

.btn-danger {
    background: #1f2937;
    color: white;
}

.btn-danger:hover {
    background: #111827;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 3px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    cursor: pointer;
}

.btn-copy {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.btn-full {
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check input {
    width: auto;
}

.form-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.inline-form {
    display: inline;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 4px;
    overflow: hidden;
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: var(--header-bg);
    font-weight: 600;
}

.data-table tr:hover {
    background: var(--hover-bg);
}

.data-table tr.disabled {
    opacity: 0.5;
}

.data-table .actions {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

/* Login page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.login-hint {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.login-hint code {
    background: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
}

/* Dashboard */
.dashboard h1 {
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.dashboard-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.dashboard-section h2 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Status breakdown */
.status-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.status-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online { background: #4b5563; }
.status-dot.active { background: #374151; }
.status-dot.offline { background: #9ca3af; }
.status-dot.disabled { background: #6b7280; }
.status-dot.open { background: #4b5563; }
.status-dot.closed { background: #1f2937; }
.status-dot.archived { background: #9ca3af; }
.status-dot.pending { background: #6b7280; }
.status-dot.in_progress { background: #374151; }
.status-dot.completed { background: #4b5563; }

.status-count {
    font-weight: 600;
    color: var(--text-color);
}

/* Activity feed */
.activity-feed {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.activity-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--code-bg);
    border-radius: 6px;
}

.activity-icon {
    width: 32px;
    height: 32px;
    background: var(--sidebar-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-title {
    font-size: 0.9rem;
    color: var(--text-color);
    margin-bottom: 0.25rem;
}

.activity-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Quick actions */
.quick-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Thread list in dashboard */
.thread-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.thread-item {
    display: block;
    padding: 0.75rem;
    background: var(--code-bg);
    border-radius: 6px;
    transition: background 0.15s;
}

.thread-item:hover {
    background: var(--hover-bg);
}

.thread-title {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.thread-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

/* Agents list */
.agents-list {
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.agent-name {
    font-weight: 500;
}

.agent-id {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* Thread list */
.threads-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.thread-card {
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border-left: 3px solid var(--primary-color);
}

.thread-card:hover {
    box-shadow: var(--shadow-lg);
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.thread-header h3 {
    font-size: 1.1rem;
}

.thread-header h3 a {
    color: var(--text-color);
}

.thread-header h3 a:hover {
    color: var(--primary-color);
}

.thread-status {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    background: var(--secondary-bg);
}

.thread-content-preview {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.thread-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.thread-meta {
    display: flex;
    gap: 1rem;
    color: var(--text-muted);
}

.thread-mentions {
    display: flex;
    gap: 0.25rem;
}

.mention-badge {
    background: var(--code-bg);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
}

/* Thread view */
.thread-view {
    max-width: 900px;
    margin: 0 auto;
}

.thread-nav {
    margin-bottom: 1rem;
}

.thread-main {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.thread-main .thread-header {
    margin-bottom: 1rem;
}

.thread-main .thread-header h1 {
    font-size: 1.5rem;
}

.thread-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.thread-actions select {
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-color);
}

.assigned-badge {
    background: var(--code-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.post-meta {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.author-type {
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}

.author-name {
    font-weight: 500;
}

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

.post-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.7;
}

.post-mentions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.9rem;
}

/* Replies */
.reply-section {
    margin-bottom: 2rem;
}

.reply-section h2 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.replies-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.reply {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 6px;
    border-left: 3px solid var(--border-color);
}

.reply.depth-0 {
    border-left-color: var(--primary-color);
}

.reply.depth-1 {
    margin-left: 1.5rem;
    border-left-color: #6b7280;
}

.reply.depth-2 {
    margin-left: 3rem;
    border-left-color: #9ca3af;
}

.reply.depth-3 {
    margin-left: 4.5rem;
    border-left-color: #d1d5db;
}

.nested-replies {
    margin-top: 0.75rem;
}

.reply-link {
    color: var(--primary-color);
    font-size: 0.85rem;
}

/* Reply form */
.reply-form-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.reply-form-section h2 {
    margin-bottom: 1rem;
}

/* Thread danger zone */
.thread-danger {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    text-align: right;
}

/* Thread form */
.thread-form-page {
    max-width: 800px;
    margin: 0 auto;
}

.thread-form {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
}

/* Logs page */
.logs-page {
    max-width: 1000px;
    margin: 0 auto;
}

.logs-table .log-time {
    white-space: nowrap;
    font-size: 0.85rem;
}

.logs-table .log-agent {
    font-weight: 500;
}

.logs-table .log-action {
    font-size: 0.9rem;
}

.logs-table .log-details code {
    font-size: 0.8rem;
    background: var(--code-bg);
    padding: 0.15rem 0.3rem;
    border-radius: 3px;
}

/* Filters */
.filters {
    margin-bottom: 1.5rem;
}

.filter-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.filter-form select {
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: auto;
}

.modal-large {
    max-width: 700px;
}

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

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-content form {
    padding: 1.5rem;
}

.prompt-container {
    padding: 1.5rem;
}

.prompt-container pre {
    background: var(--code-bg);
    padding: 1rem;
    border-radius: 4px;
    overflow: auto;
    font-size: 0.85rem;
    white-space: pre-wrap;
    margin-bottom: 1rem;
    max-height: 400px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-task {
    background: #6b7280;
    color: #ffffff;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .hamburger {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
    }

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

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

    .main-wrapper {
        margin-left: 0;
    }

    .main-content {
        padding: 1rem;
        padding-top: 4rem;
    }

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

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .data-table {
        font-size: 0.85rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem;
    }

    .reply.depth-1,
    .reply.depth-2,
    .reply.depth-3 {
        margin-left: 0.5rem;
    }

    .filter-form {
        flex-wrap: wrap;
    }

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

    .quick-actions .btn-primary,
    .quick-actions .btn-secondary {
        width: 100%;
    }
}
