/* ============================================
   Reset & Base Styles
   ============================================ */

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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Navigation
   ============================================ */

header {
    background-color: var(--bg-primary);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar {
    padding: 1rem 0;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-logo a {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

.nav-logo a:hover {
    color: var(--primary-hover);
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 0;
    position: relative;
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--primary-color);
}

.nav-link.active {
    color: var(--primary-color);
    font-weight: 600;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--primary-color);
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
    flex: 1;
    padding: 3rem 0;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.page-section {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.page-section.active {
    display: block;
}

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

/* ============================================
   Typography
   ============================================ */

.main-title {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 1rem;
}

.subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 3rem;
}

.page-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2rem;
    text-align: center;
}

h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    margin-top: 1.5rem;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    margin-top: 1.25rem;
}

p {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* ============================================
   Cards & Content
   ============================================ */

.content-card {
    background-color: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.constitution-structure {
    margin-top: 1.5rem;
}

.constitution-structure h3 {
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.constitution-structure p {
    margin-bottom: 1rem;
    padding-left: 1rem;
    border-left: 3px solid var(--border-color);
}

.note-box {
    background-color: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 1rem 1.5rem;
    margin-top: 2rem;
    border-radius: var(--border-radius);
}

.note-box p {
    margin-bottom: 0;
}

.inline-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

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

/* ============================================
   Buttons
   ============================================ */

.action-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 2rem;
}

.btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    border-radius: var(--border-radius);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
    cursor: pointer;
    border: none;
    font-size: 1rem;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover {
    background-color: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ============================================
   Links List
   ============================================ */

.links-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.link-card {
    background-color: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.link-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.link-card h3 {
    margin-top: 0;
    color: var(--primary-color);
}

.link-card p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.external-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.external-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.link-icon {
    font-size: 0.875rem;
    opacity: 0.7;
}

/* ============================================
   Footer
   ============================================ */

footer {
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    margin-top: 3rem;
}

footer .container {
    text-align: center;
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
}

/* ============================================
   Chat UI
   ============================================ */

.chat-page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0;
}

.chat-layout {
    display: flex;
    gap: 0;
    height: calc(100vh - 200px);
    min-height: 600px;
    background-color: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.chat-sidebar {
    width: 280px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.new-chat-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.new-chat-btn span {
    font-size: 1.2rem;
    font-weight: bold;
}

.chat-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-sidebar-loading,
.chat-sidebar-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.chat-sidebar-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    background-color: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: relative;
}

.chat-sidebar-item:hover {
    background-color: rgba(37, 99, 235, 0.1);
}

.chat-sidebar-item:hover .chat-sidebar-item-delete {
    opacity: 1;
}

.chat-sidebar-item.active {
    background-color: rgba(37, 99, 235, 0.15);
    border-left: 3px solid var(--primary-color);
}

.chat-sidebar-item-content {
    flex: 1;
    min-width: 0;
}

.chat-sidebar-item-title-wrapper {
    position: relative;
    margin-bottom: 0.25rem;
}

.chat-sidebar-item-title {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.chat-sidebar-item.active .chat-sidebar-item-title {
    color: var(--primary-color);
    font-weight: 600;
}

.chat-sidebar-item-title-edit {
    width: 100%;
    padding: 0.25rem 0.5rem;
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-family: inherit;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
}

.chat-sidebar-item-title-edit:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-sidebar-item-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-sidebar-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    font-size: 1.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.chat-sidebar-item-delete:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.chat-sidebar-item-delete span {
    display: block;
    font-weight: bold;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: var(--bg-secondary);
}

.chat-welcome {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
    font-style: italic;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: fadeIn 0.3s ease-in;
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-bubble {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-content {
    margin-bottom: 0.5rem;
}

.message-references {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.message-references-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.message-references-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message-reference-item {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.message-reference-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    gap: 0.5rem;
}

.message-reference-number {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.75rem;
}

.message-reference-score {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background-color: var(--bg-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.message-reference-text {
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.6;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    padding: 0 0.5rem;
}

.message.user .message-time {
    text-align: right;
}

.chat-input-container {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-primary);
}

.chat-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    transition: var(--transition);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-send-btn {
    padding: 0.75rem 2rem;
    white-space: nowrap;
    align-self: flex-end;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Login Form
   ============================================ */

.login-form {
    max-width: 400px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    box-sizing: border-box;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.error-message {
    background-color: #fee2e2;
    color: #dc2626;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border-left: 4px solid #dc2626;
}

.success-message {
    background-color: #d1fae5;
    color: #059669;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border-left: 4px solid #059669;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-menu {
        gap: 1.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .main-title {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1.1rem;
    }

    .page-title {
        font-size: 2rem;
    }

    .content-card {
        padding: 1.5rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        text-align: center;
    }

    .link-card {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }

    .main-content {
        padding: 2rem 0;
    }

    .main-title {
        font-size: 1.75rem;
    }

    .page-title {
        font-size: 1.75rem;
    }

    .content-card {
        padding: 1.25rem;
    }

    .chat-layout {
        flex-direction: column;
        height: auto;
        min-height: 600px;
    }
    
    .chat-sidebar {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .chat-sidebar-content {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    .chat-sidebar-item {
        min-width: 200px;
        flex-shrink: 0;
    }
    
    .chat-container {
        height: 500px;
    }

    .message {
        max-width: 85%;
    }

    .chat-input-container {
        flex-direction: column;
    }

    .chat-send-btn {
        width: 100%;
    }
}

