/* Variables CSS */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--gray-800);
    line-height: 1.5;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--white);
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-800);
}

.header-subtitle {
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Chat Container */
.chat-container {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100vh - 140px);
}

/* Chat Header */
.chat-header {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--gray-700);
}

.btn-restart {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Messages */
.message {
    display: flex;
    gap: 0.75rem;
    max-width: 90%;
    animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--gray-200);
}

.message-content {
    background: var(--gray-100);
    padding: 1rem;
    border-radius: var(--radius-lg);
    border-top-left-radius: 4px;
}

.message.user .message-content {
    background: var(--primary);
    color: var(--white);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: 4px;
}

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

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

.example-text {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.75rem;
    border-radius: var(--radius);
    font-style: italic;
    font-size: 0.9rem;
    color: var(--gray-600);
}

/* Input Area */
.input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.input-wrapper textarea {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-mic, .btn-send {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-mic {
    background: var(--gray-200);
    color: var(--gray-700);
    position: relative;
}

.btn-mic:hover {
    background: var(--gray-300);
}

.btn-mic.recording {
    background: var(--danger);
    color: var(--white);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.btn-mic svg {
    width: 24px;
    height: 24px;
}

.mic-status {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--danger);
    display: none;
}

.btn-mic.recording .mic-status {
    display: block;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

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

.btn-send svg {
    width: 20px;
    height: 20px;
}

.voice-options {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
}

.voice-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--gray-600);
    cursor: pointer;
}

.voice-option input {
    cursor: pointer;
}

/* Preview Panel */
.preview-panel {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100vh - 140px);
}

.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gray-50);
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-800);
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-edit, .btn-download {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-edit {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-edit:hover {
    background: var(--gray-300);
}

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

.btn-download:hover:not(:disabled) {
    background: #059669;
}

.btn-download:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-400);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

/* Protocol Preview Styles */
.protocol-preview {
    font-size: 0.9rem;
}

.protocol-title {
    text-align: center;
    margin-bottom: 1rem;
}

.protocol-title h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-800);
}

.protocol-title h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
}

.protocol-patient {
    background: var(--primary-light);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 500;
}

.protocol-section {
    margin-bottom: 1.5rem;
}

.protocol-section h5 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
}

.protocol-warning {
    background: #fef3c7;
    border: 1px solid var(--warning);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    text-align: center;
}

.protocol-warning strong {
    color: var(--danger);
}

/* Table Styles */
.schedule-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    margin-top: 1rem;
}

.schedule-table th,
.schedule-table td {
    border: 1px solid var(--gray-300);
    padding: 0.5rem 0.25rem;
    text-align: center;
    vertical-align: middle;
}

.schedule-table th {
    background: var(--gray-100);
    font-weight: 600;
}

.schedule-table .palier-cell {
    background: var(--primary-light);
    font-weight: 600;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    min-width: 30px;
}

.schedule-table .week-cell {
    background: var(--gray-50);
    font-weight: 500;
}

.dose-cell {
    font-size: 0.7rem;
    line-height: 1.3;
}

.dose-line {
    white-space: nowrap;
}

.dose-1 { color: #000; }
.dose-half { color: #2563eb; }
.dose-quarter { color: #ea580c; }
.dose-zero { color: #dc2626; }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    z-index: 1000;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

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

.form-section h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--gray-700);
}

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

.form-row > * {
    flex: 1;
}

.form-row input,
.form-row select {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.form-row label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.checkbox-group {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.checkbox-group label {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.btn-add {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px dashed var(--primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    width: 100%;
    transition: all 0.2s;
}

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

.btn-primary {
    background: var(--primary);
    color: var(--white);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Medication Card */
.medication-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.medication-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.medication-header select {
    flex: 1;
    margin-right: 0.5rem;
}

.btn-remove {
    background: var(--danger);
    color: var(--white);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
}

.medication-doses {
    display: flex;
    gap: 0.5rem;
}

.medication-doses label {
    flex: 1;
    text-align: center;
}

.medication-doses input {
    width: 100%;
    text-align: center;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    margin-top: 1rem;
    color: var(--gray-600);
    font-weight: 500;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* ============================================
   HEADER CONFIGURATION STYLES
   ============================================ */

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.current-provider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--gray-100);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.provider-icon {
    font-size: 1.2rem;
}

.provider-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
}

.provider-status.available {
    background: var(--success);
}

.provider-status.unavailable {
    background: var(--danger);
}

.btn-settings {
    background: var(--gray-100);
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-settings:hover {
    background: var(--gray-200);
}

/* ============================================
   PROVIDER CONFIGURATION MODAL
   ============================================ */

.modal-lg {
    max-width: 800px;
}

.provider-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.provider-card {
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

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

.provider-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.provider-card.unavailable {
    opacity: 0.5;
    cursor: not-allowed;
}

.provider-card .icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.provider-card .name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.provider-card .status {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.provider-card .status.available {
    color: var(--success);
}

.provider-card .status.unavailable {
    color: var(--danger);
}

/* Provider Config Fields */
#providerConfigFields {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

#providerConfigFields .field-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

#providerConfigFields label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

#providerConfigFields input,
#providerConfigFields select {
    padding: 0.625rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

#providerConfigFields input:focus,
#providerConfigFields select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.field-hint {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    margin-left: 0.5rem;
}

.btn-small:hover {
    background: var(--gray-200);
}

/* Test Result */
.test-result {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    display: none;
}

.test-result.visible {
    display: block;
}

.test-result.success {
    background: #d1fae5;
    border: 1px solid var(--success);
    color: #065f46;
}

.test-result.error {
    background: #fee2e2;
    border: 1px solid var(--danger);
    color: #991b1b;
}

.test-result pre {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-all;
}
