/* REFERTIUS - Clinical Minimal Design System */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    /* Clinical Palette - Minimalist */
    --primary: #0284c7;
    /* Medical Blue (Keep as requested) */
    --primary-hover: #0369a1;

    --success: #059669;
    /* Muted Green */
    --danger: #dc2626;
    /* Clinical Red */
    --warning: #d97706;
    /* Muted Amber */

    /* Grayscale Dominance */
    --text-main: #111827;
    /* Nearly Black */
    --text-secondary: #4b5563;
    /* Dark Gray */
    --text-tertiary: #9ca3af;
    /* Light Gray */

    --bg-app: #f3f4f6;
    /* Light Gray Background (Hospital Wall) */
    --bg-card: #ffffff;
    /* Pure White (Paper/Chart) */
    --bg-element: #f9fafb;
    /* Very Light Gray (Inputs/Areas) */

    --border: #e5e7eb;
    /* Light Gray Border */
    --border-strong: #d1d5db;
    /* Stronger Border for inputs */

    /* Functional */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    /* very subtle */

    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Courier New', monospace;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    padding: 0;
    min-height: 100vh;
}

.container {
    max-width: 1100px;
    /* Slightly easier to read width */
    margin: 0 auto;
    padding: 20px;
}

/* --- Layout Components --- */

/* Header - Sterile & Functional */
.header {
    background: var(--bg-card);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon svg {
    width: 32px;
    height: 32px;
    display: block;
}

.logo-icon rect {
    fill: var(--primary);
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.01em;
    margin: 0;
    line-height: 1.2;
}

.subtitle {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    margin: 0;
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Badge / Status */
.status-indicator {
    background-color: #f0fdf4;
    color: #166534;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    border: 1px solid #bbf7d0;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
}

.status-dot {
    width: 6px;
    height: 6px;
    background-color: #16a34a;
    border-radius: 50%;
}

/* Main Content Area */
.main {
    margin-bottom: 40px;
}

/* Cards - Paper Metaphor */
.recording-card,
.processing-card,
.referto-card,
.auth-card,
.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 24px 32px;
    margin-bottom: 24px;
}

/* Typography Headings */
h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    /* Dividing line */
}

h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0 0 8px 0;
}

p {
    color: var(--text-secondary);
}

/* --- Interactive Elements --- */

/* Buttons - Professional & Clear */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    height: 38px;
    /* Standard height */
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--border) !important;
    color: var(--text-tertiary) !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

/* Primary Action */
.btn-record {
    /* Fixing the previous "circle button" issue */
    background-color: var(--primary);
    color: #ffffff;
    padding: 12px 24px;
    height: auto;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    width: auto;
    /* Allow width to fit text */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-record:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

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

/* Stop Button */
.btn-stop {
    background-color: var(--bg-card);
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 12px 24px;
    height: auto;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    width: auto;
    animation: none;
    /* Removed distracting pulse */
}

.btn-stop:hover {
    background-color: #fef2f2;
}

.btn-primary {
    background-color: #f3f4f6;
    /* Light Gray (Gray-100) */
    color: #1f2937;
    /* Dark Gray Text */
    border: 1px solid #e5e7eb;
}

.btn-primary:hover {
    background-color: #e5e7eb;
    /* Gray-200 */
    border-color: #d1d5db;
}

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background-color: var(--bg-app);
    border-color: var(--text-secondary);
}

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

.btn-success:hover {
    background-color: #047857;
}

.btn-danger {
    background-color: var(--bg-card);
    color: var(--danger);
    border-color: var(--border);
}

.btn-danger:hover {
    background-color: #fef2f2;
    border-color: var(--danger);
}

.btn-danger-solid {
    background-color: var(--danger);
    color: #ffffff;
}

.btn-full {
    width: 100%;
}

/* Controls Container */
.controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 24px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 24px 0;
    background-color: var(--bg-element);
    /* Subtle separation */
    border-radius: var(--radius-md);
}


/* Recording Visual */
.recording-visual {
    background-color: var(--bg-card);
    padding: 20px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.timer {
    font-family: var(--font-mono);
    font-size: 48px;
    font-weight: 500;
    color: var(--text-main);
    letter-spacing: -2px;
    margin-bottom: 16px;
}

.wave-container {
    height: 48px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.wave {
    width: 6px;
    height: 8px;
    background: var(--text-tertiary);
    border-radius: 4px;
    transition: all 0.1s ease;
}

.wave-container.active .wave {
    background: var(--primary);
    animation: wave-clinical 1.2s ease-in-out infinite;
}

@keyframes wave-clinical {

    0%,
    100% {
        height: 8px;
        opacity: 0.5;
    }

    50% {
        height: 32px;
        opacity: 1;
    }
}


/* Info Box - Clinical Note style */
.info-box {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-element);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-top: 24px;
    font-size: 13px;
    color: var(--text-secondary);
    align-items: flex-start;
}

.info-box svg {
    flex-shrink: 0;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.info-box p {
    margin: 0;
    line-height: 1.4;
}

/* Referto Report */
.referto-meta {
    background-color: var(--bg-element);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* Tighter grid */
    gap: 16px;
    margin-bottom: 24px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-strong);
    padding-right: 16px;
}

.meta-item:last-child {
    border-right: none;
}

.meta-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.meta-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    font-family: var(--font-mono);
}

.referto-content {
    font-family: 'Times New Roman', serif;
    /* Clinical reports often use serif */
    font-size: 16px;
    line-height: 1.6;
    background: #fff;
    padding: 40px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    min-height: 400px;
}

.referto-section-title {
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 2px solid var(--text-main);
    padding-bottom: 4px;
    margin-top: 32px;
    margin-bottom: 12px;
}


/* Forms - Crisp and High Contrast */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-main);
    background-color: var(--bg-card);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--text-main);
    /* Black border on focus */
    box-shadow: none;
}


/* Processing */
.progress-bar {
    height: 4px;
    background-color: var(--border);
    border-radius: 2px;
}

.progress-fill {
    height: 100%;
    background-color: var(--text-main);
}


/* Footer */
.footer {
    text-align: center;
    margin-top: 32px;
    color: var(--text-tertiary);
    font-size: 11px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.footer-note {
    color: var(--warning);
    font-weight: 600;
    margin-top: 4px;
}

/* Common Helpers */
.text-center {
    text-align: center;
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    .referto-meta {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .meta-item {
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-bottom: 12px;
        padding-right: 0;
    }

    .meta-item:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .header {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
        padding: 16px;
    }

    .logo {
        justify-content: center;
        text-align: center;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Toolbar Responsiveness */
    .referto-toolbar {
        padding: 12px;
    }

    .toolbar-row {
        flex-wrap: wrap;
    }

    .utilities-row {
        justify-content: space-between;
    }

    .finalize-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .date-input-group {
        width: 100%;
        justify-content: space-between;
    }

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

    /* Modal Mobile */
    .modal-content {
        margin: 16px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Typography Adjustments */
    h1 {
        font-size: 24px;
    }

    .referto-content {
        padding: 24px;
    }

    /* Filters in List */
    .filters-row {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group input,
    .filter-group select {
        width: 100%;
    }
}

/* Referto Toolbar Styles */
.referto-toolbar {
    background-color: var(--bg-element);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 24px;
}

.toolbar-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.utilities-row {
    justify-content: flex-start;
}

.toolbar-divider {
    height: 1px;
    background-color: var(--border);
    margin: 16px 0;
}

.finalize-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.warning-inline {
    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--warning);
    font-size: 13px;
    background-color: #fffbeb;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid #fcd34d;
}

.finalize-controls {
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
}

.date-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-input-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.date-input-group input {
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    user-select: none;
}

.checkbox-wrapper input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--success);
}

.action-buttons-row {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.action-buttons-row .btn {
    flex: 1;
}

/* Make "New Visit" distinct if disabled */
#newBtn:disabled {
    opacity: 0.6;
    background-color: var(--bg-card);
    border-color: var(--border);
    color: var(--text-tertiary);
    cursor: not-allowed;
}

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

.modal-content {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

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

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    border: none;
    padding: 0;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.error-alert {
    background-color: #fef2f2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid #fee2e2;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn 0.2s ease-out;
}

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

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