/* Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Variables */
:root {
    --primary-color: #3b82f6;
    /* Modern Blue */
    --primary-hover: #2563eb;
    --secondary-color: #64748b;
    /* Slate 500 */
    --secondary-hover: #475569;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #22c55e;
    --background-color: #f8fafc;
    /* Slate 50 */
    --card-bg: #ffffff;
    --text-main: #1e293b;
    /* Slate 800 */
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    /* Slate 200 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background-color);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    transition: all 0.2s ease;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
header {
    background: var(--card-bg);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    text-decoration: none;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

nav {
    display: flex;
    gap: 2rem;
}

nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.5rem 0;
    position: relative;
}

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

nav a.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary-color);
    border-radius: 2px;
}

/* Cards & Sections */
.section,
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

/* Typography */
h1,
h2,
h3 {
    color: var(--text-main);
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
    margin-top: 2.5rem;
}

.card-icon {
    font-size: 2.5rem;
    margin-bottom: 1.25rem;
    background: #eff6ff;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--primary-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-main);
}

.card-description {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Buttons */
button,
.btn {
    font-family: inherit;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.3);
}

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

.btn-secondary:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.btn-danger {
    background: #fee2e2;
    color: var(--danger-color);
    border: 1px solid #fecaca;
}

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

.credentials-section.active {
    display: block !important;
}

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

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.95rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s;
    border: 1px solid var(--border-color);
}

.modal.active .modal-content {
    transform: scale(1);
}

/* Session Page specific */
.layout-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    align-items: start;
    height: calc(100vh - 120px);
    min-width: 0;
}

.sidebar {
    height: 100%;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.main-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.5rem;
}

.session-item {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    background: white;
    display: flex;
    align-items: center;
}

.session-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.session-item.active {
    background: #eff6ff;
    border-color: var(--primary-color);
}

.session-item-content {
    flex: 1;
    min-width: 0;
    /* Important for truncation */
}

.session-preview {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.15rem;
}

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

.delete-btn {
    padding: 0.5rem;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
}

.delete-btn-header {
    padding: 0.5rem;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn-header:hover {
    background: #fee2e2;
    color: var(--danger-color);
    border-color: #fca5a5;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    margin-bottom: 0.75rem;
    background: white;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    /* Ensure content starts at top and pushes down */
    justify-content: flex-start;
}

.session-summary {
    background: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
}

.summary-item label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
}

.summary-item span {
    display: block;
    color: var(--text-main);
    font-weight: 500;
}

.input-area.readonly {
    display: none;
}

.message {
    max-width: 85%;
    padding: 0.85rem 1.15rem;
    border-radius: 1rem;
    line-height: 1.5;
    position: relative;
    font-size: 0.95rem;
    animation: fadeIn 0.3s ease;
    overflow-wrap: break-word;
    /* Ensures long words wrap */
    word-break: break-word;
    /* Safari/iOS support */
}

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

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

.message.ai {
    align-self: flex-start;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 0.25rem;
}

.message.user {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
    box-shadow: var(--shadow-sm);
}

.message-header {
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
    opacity: 0.8;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-area {
    background: white;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
}

.input-area textarea {
    border: none;
    resize: none;
    padding: 0.5rem;
    box-shadow: none;
}

.input-area textarea:focus {
    box-shadow: none;
}

/* Status Badges */
.provider-status {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-enabled {
    background: #dcfce7;
    color: #166534;
}

.status-disabled {
    background: #fee2e2;
    color: #991b1b;
}

.provider-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.provider-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.error {
    background: #fef2f2;
    color: #b91c1c;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    border: 1px solid #fecaca;
    display: none;
    font-size: 0.9rem;
}

/* Simple typing indicator */
.typing-indicator {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    padding: 0.5rem;
}

/* Structured Input Styles */
.structured-input-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.choice-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.choice-item:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.choice-item input[type="radio"],
.choice-item input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.choice-content {
    font-size: 0.95rem;
    color: var(--text-main);
}

.choice-key {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    min-width: 1.5rem;
}

.visit-note-content {
    background: #f8fafc;
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-top: 1rem;
    font-size: 0.95rem;
}

.visit-note-content h1,
.visit-note-content h2,
.visit-note-content h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Markdown Content Styles */
.markdown-content ul,
.markdown-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.markdown-content p {
    margin-bottom: 0.75rem;
}

/* Message Choice Display Styles */
.message-choices {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 0.75rem;
}

.message-choice-item {
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.5);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

.message-choice-key {
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary-color);
    margin-right: 0.25rem;
}

/* Message Control Panel */
.message-control-panel {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.message:hover .message-control-panel {
    opacity: 1;
}

.control-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem 0.4rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s;
}

.control-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: scale(1.1);
}

.control-btn.active {
    color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
}

.historical-panel {
    opacity: 1 !important;
}