:root {
    --primary: #72b344;
    --primary-dark: #72b344;
    --secondary: #1e295d;
    --success: #1e295d;
    --danger: #dc2626;
    --warning: #d97706;
    --light: #f8fafc;
    --dark: #1e293b;
    --border: #1e295d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--dark);
    background: var(--light);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.container-narrow {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 15px 0;
    margin-bottom: 30px;
}

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

.logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

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

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 5px;
}

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

.form-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

.btn-secondary:hover {
    background: #475569;
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 14px;
}

.btn-block {
    width: 100%;
}

/* Alerts */
.alert {
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-label {
    font-size: 13px;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--dark);
}

.stat-value.success {
    color: var(--success);
}

/* Matter List */
.matter-list {
    list-style: none;
}

.matter-item {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    transition: box-shadow 0.2s;
}

.matter-item:hover {
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.matter-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 10px;
}

.matter-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 5px;
}

.matter-meta {
    font-size: 14px;
    color: var(--secondary);
    margin-bottom: 10px;
}

.matter-description {
    color: var(--dark);
    margin-bottom: 15px;
}

.matter-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.matter-stats {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: var(--secondary);
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-pending {
    background: #fef3c7;
    color: #92400e;
}

.badge-processing {
    background: #dbeafe;
    color: #1e40af;
}

.badge-completed,
.badge-answered {
    background: #d1fae5;
    color: #065f46;
}

.badge-error {
    background: #fee2e2;
    color: #991b1b;
}

/* Messages/Conversation */
.messages {
    max-width: 800px;
    margin: 0 auto;
}

.message {
    margin-bottom: 20px;
    padding: 15px;
    border-radius: 8px;
}

.message-user {
    background: #dbeafe;
    margin-left: 40px;
}

.message-assistant {
    background: #f1f5f9;
    margin-right: 40px;
}

.message-system {
    background: #fef3c7;
    font-size: 14px;
    font-style: italic;
}

.message-role {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    margin-bottom: 8px;
    color: var(--secondary);
}

.message-content {
    line-height: 1.6;
}

/* Markdown styling in messages */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin-top: 20px;
    margin-bottom: 10px;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 { font-size: 24px; }
.message-content h2 { font-size: 20px; }
.message-content h3 { font-size: 18px; }
.message-content h4 { font-size: 16px; }

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child,
.message-content h4:first-child {
    margin-top: 0;
}

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul,
.message-content ol {
    margin: 12px 0;
    padding-left: 30px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 15px;
    margin: 12px 0;
    color: var(--secondary);
    font-style: italic;
}

.message-content a {
    color: var(--primary);
    text-decoration: underline;
}

.message-content a:hover {
    color: var(--primary-dark);
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.message-content table th,
.message-content table td {
    border: 1px solid var(--border);
    padding: 8px;
    text-align: left;
}

.message-content table th {
    background: var(--light);
    font-weight: 600;
}

/* Sources */
.sources {
    margin-top: 30px;
}

.source-item {
    background: #f8fafc;
    border-left: 3px solid var(--primary);
    padding: 15px;
    margin-bottom: 10px;
}

.source-title {
    font-weight: 600;
    margin-bottom: 5px;
}

.source-meta {
    font-size: 13px;
    color: var(--secondary);
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--secondary);
}

.spinner {
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spinner-small {
    display: inline-block;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    animation: spin 0.8s linear infinite;
}

/* Utility classes */
.text-center {
    text-align: center;
}

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

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

.text-small {
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .matter-header {
        flex-direction: column;
    }
    
    .matter-footer {
        flex-direction: column;
        align-items: start;
        gap: 10px;
    }
    
    .message-user,
    .message-assistant {
        margin-left: 0;
        margin-right: 0;
    }
}
