/* RadioDictate Global Design System */

/* 1. Variables & Theme Configuration */
:root {
    /* Color Palette - Deep Blue/Purple Glassmorphism Theme */
    --primary-50: #f0f9ff;
    --primary-100: #e0f2fe;
    --primary-200: #bae6fd;
    --primary-300: #7dd3fc;
    --primary-400: #38bdf8;
    --primary-500: #0ea5e9;
    --primary-600: #0284c7;
    --primary-700: #0369a1;
    --primary-800: #075985;
    --primary-900: #0c4a6e;

    --accent-purple: #8b5cf6;
    --accent-pink: #ec4899;

    --bg-light: #f8fafc;
    --bg-surface: rgba(255, 255, 255, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.25);

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --border-light: rgba(255, 255, 255, 0.3);
    --border-strong: rgba(226, 232, 240, 0.8);

    /* Gradients */
    --gradient-hero: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --gradient-primary: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    --gradient-accent: linear-gradient(135deg, #8b5cf6 0%, #d946ef 100%);
    --gradient-body: linear-gradient(135deg, #f1f5f9 0%, #cbd5e1 100%);

    /* Shadows */
    --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);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px rgba(14, 165, 233, 0.3);

    /* Spacing & Layout */
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --header-height: 80px;
}

/* Dark Mode Overrides */
body.dark {
    --bg-light: #0f172a;
    --bg-surface: rgba(30, 41, 59, 0.7);
    --bg-surface-alt: rgba(15, 23, 42, 0.5);
    /* Added missing var */
    --bg-glass: rgba(15, 23, 42, 0.4);

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;

    --border-light: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(51, 65, 85, 0.8);

    --gradient-body: linear-gradient(135deg, #0f172a 0%, #020617 100%);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--gradient-body);
    background-attachment: fixed;
    /* Parallax-like effect */
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* 3. Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: 1.2;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

h1 {
    font-size: 2.5rem;
    letter-spacing: -0.05em;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
}

.text-gradient-secondary {
    background: linear-gradient(135deg, var(--secondary-400), var(--secondary-600));
    -webkit-background-clip: text;
    background-clip: text;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.5rem;
}

p {
    margin-bottom: 1rem;
}

a {
    color: var(--primary-500);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-600);
}

/* 4. Layout Components */
.main-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* 5. Navigation (Navbar) */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-light);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

body.dark .navbar {
    background: rgba(15, 23, 42, 0.8);
}

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

.nav-brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-link {
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-500);
    background: var(--primary-50);
}

body.dark .nav-link:hover {
    background: rgba(30, 41, 59, 1);
}

/* 6. Cards & Glassmorphism */
.card {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.card-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

/* 7. Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-size: 1rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
    background: var(--primary-50);
    border-color: var(--primary-200);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    box-shadow: none;
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

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

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

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
    transition: all 0.2s;
}

body.dark .form-control {
    background: rgba(15, 23, 42, 0.6);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

textarea.form-control {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

/* 9. Utilities & Helpers */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-4 {
    margin-top: 2rem;
}

.mb-4 {
    margin-bottom: 2rem;
}

.w-100 {
    width: 100%;
}

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

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

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* 10. Specific App Overrides (Backwards Compatibility) */

/* Document Editor (Main App Specific) */
.editor-container {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: white;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    min-height: 60vh;
}

body.dark .editor-container {
    background: #1e293b;
}

.textarea-main {
    width: 100%;
    height: 100%;
    min-height: 60vh;
    border: none;
    padding: 2rem;
    background: transparent;
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1.25rem;
    line-height: 1.8;
    resize: none;
}

.textarea-main:focus {
    box-shadow: none;
}

/* Recording Button Animation */
.record-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 10px 25px rgba(220, 38, 38, 0.4);
    transition: all 0.3s;
}

.record-btn:hover {
    transform: translateX(-50%) scale(1.1);
}

.record-btn.recording {
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(220, 38, 38, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
    }
}

/* Sidebar for controls (if we move to sidebar layout) */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    padding: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        padding: 0.5rem;
    }

    .nav-links {
        display: none;
    }

    /* Mobile menu needed */
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 1.5rem;
    }
}

.highlight-right {
    background: rgba(34, 197, 94, 0.3);
    color: #166534;
    font-weight: bold;
    padding: 0.1rem 0.2rem;
    border-radius: 0.25rem;
    border: 1px solid rgba(34, 197, 94, 0.5);
}

.highlight-left {
    background: rgba(239, 68, 68, 0.3);
    color: #991b1b;
    font-weight: bold;
    padding: 0.1rem 0.2rem;
    border-radius: 0.25rem;
    border: 1px solid rgba(239, 68, 68, 0.5);
}

body.dark .highlight-right {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.4);
}

body.dark .highlight-left {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
}

/* Settings Overlay */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.settings-content {
    background: var(--bg-light);
    border-radius: 1rem;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-lg);
}

body.dark .settings-content {
    background: var(--bg-dark-secondary);
}

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

body.dark .settings-header {
    border-color: var(--border-dark);
}

.settings-header h3 {
    color: var(--primary-700);
    font-size: 1.25rem;
    margin: 0;
}

body.dark .settings-header h3 {
    color: var(--primary-300);
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.3s ease;
}

body.dark .btn-close {
    color: var(--text-dark);
}

.btn-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.settings-body {
    padding: 1.5rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    gap: 1rem;
}

.setting-info {
    flex: 1;
}

.setting-info h4 {
    color: var(--primary-700);
    font-size: 1rem;
    margin: 0 0 0.5rem 0;
}

body.dark .setting-info h4 {
    color: var(--primary-300);
}

.setting-info p {
    color: var(--text-light);
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0;
    opacity: 0.8;
}

body.dark .setting-info p {
    color: var(--text-dark);
}

.setting-control {
    flex-shrink: 0;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ccc;
    transition: 0.4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked+.toggle-slider {
    background: var(--primary-600);
}

input:checked+.toggle-slider:before {
    transform: translateX(26px);
}

/* Examples */
.examples {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.example-right {
    background: rgba(34, 197, 94, 0.2);
    color: #166534;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
}

.example-left {
    background: rgba(239, 68, 68, 0.2);
    color: #991b1b;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
}

body.dark .example-right {
    color: #4ade80;
}

body.dark .example-left {
    color: #f87171;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-2rem);
    }

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

/* =========================================
   11. Editor & Workspace (Migrated from index.html)
   ========================================= */

/* Specific Styles for Main Editor */
.workspace-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    min-height: calc(100vh - 160px);
}

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

    .sidebar-panel {
        display: none;
        /* Can be toggled on mobile */
    }
}

/* Sidebar Styles */
.sidebar-card {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-700);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.sidebar-menu-item:hover {
    background: var(--bg-surface-alt);
    color: var(--primary-600);
    transform: translateX(2px);
}

.sidebar-menu-item.active {
    background: var(--primary-50);
    color: var(--primary-600);
    font-weight: 600;
}

.draft-item {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.draft-item:hover {
    background: var(--bg-surface-alt);
}

.draft-delete {
    color: var(--danger-500);
    cursor: pointer;
    padding: 2px 6px;
}

.quick-actions-panel {
    margin-top: auto;
    border-top: 1px solid var(--border-light);
    padding-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.quick-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    border: 1px solid transparent;
}

.quick-btn-copy {
    background: var(--primary-50);
    color: var(--primary-700);
    border-color: var(--primary-100);
}

.quick-btn-copy:hover {
    background: var(--primary-100);
    transform: translateY(-1px);
}

.quick-btn-clear {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

.quick-btn-clear:hover {
    background: var(--bg-surface-alt);
    color: var(--danger-600);
    border-color: var(--danger-200);
}

/* Editor Area Styles */
.editor-card {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-light);
    height: 100%;
}

.editor-toolbar {
    padding: 1rem 1.5rem;
    background: #ffffff;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.main-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.editor-main-container {
    flex: 1;
    position: relative;
    background: #FAFAFA;
    padding: 2rem;
    overflow-y: auto;
}

/* Paper Sheet - Dynamic Height */
.paper-sheet {
    background: white;
    box-shadow: var(--shadow-sm);
    width: 100%;
    height: 100%;
    min-height: 50vh;
    max-width: 900px;
    margin: 0 auto;
    border-radius: var(--radius-sm);
    position: relative;
}

/* Unified Font Settings for Perfect Sync */
.editor-font-settings {
    font-family: 'Inter', sans-serif !important;
    font-size: 1.15rem !important;
    line-height: 1.8 !important;
    letter-spacing: normal !important;
    padding: 2.5rem 3rem !important;
    box-sizing: border-box !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

#editor {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    resize: none;
    color: var(--text-primary);
    background: transparent;
    z-index: 2;
    overflow: hidden;
}

#editor:focus {
    outline: none;
}

/* Laterality Highlights */
#highlightLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    color: transparent;
    z-index: 1;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow: auto;
}

#highlightLayer::-webkit-scrollbar {
    display: none;
}

mark.highlight-right {
    background-color: rgba(34, 197, 94, 0.2);
    color: transparent;
    border-bottom: 2px solid var(--success-500);
    border-radius: 4px;
    padding: 2px 0;
}

mark.highlight-left {
    background-color: rgba(239, 68, 68, 0.2);
    color: transparent;
    border-bottom: 2px solid var(--danger-500);
    border-radius: 4px;
    padding: 2px 0;
}

/* Audio Visualizer */
.audio-visualizer {
    height: 4px;
    background: var(--primary-100);
    border-radius: 2px;
    overflow: hidden;
    width: 80px;
    display: none;
}

.mic-button.recording+.audio-visualizer,
.control-btn.mic-active-pulse+.audio-visualizer {
    display: block;
}

.visualizer-bar {
    height: 100%;
    background: var(--primary-500);
    width: 0%;
    transition: width 0.1s;
}

/* Dark Mode Overrides for Editor */
body.dark .sidebar-card,
body.dark .editor-card,
body.dark .paper-sheet,
body.dark .editor-toolbar {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

body.dark .editor-main-container {
    background: var(--bg-surface-alt);
}

body.dark #editor {
    color: var(--text-primary);
}

/* Buttons Refactor (Pill Shape) */
.control-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.5rem;
    border-radius: 50px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-size: 0.95rem;
    height: 44px;
    width: auto;
    /* Allow text to flow */
    min-width: 100px;
}

.control-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
}

.control-btn:active {
    transform: scale(0.95);
}

.btn-record {
    background: var(--primary-600);
    color: white;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

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

.btn-stop {
    background-color: #ef4444 !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    font-weight: 700;
    border: 1px solid #dc2626 !important;
}

.btn-stop:hover {
    background-color: #dc2626 !important;
    transform: translateY(-1px);
}

body.dark .btn-stop {
    background-color: #991b1b !important;
    border-color: #7f1d1d !important;
    color: #fecaca !important;
}

/* Floating Label Inputs (re-added if needed) */
.floating-label-group {
    position: relative;
    margin-bottom: 0.5rem;
}

.floating-input {
    width: 100%;
    padding: 1rem 1rem 0.5rem;
    /* Increased top padding slightly */
    font-size: 1rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: white;
    transition: all 0.2s;
    height: 56px;
    /* Explicit height for touch targets */
}

.floating-input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-100);
    outline: none;
}

.floating-label {
    position: absolute;
    top: 50%;
    left: 0.75rem;
    transform: translateY(-50%);
    background: transparent;
    padding: 0;
    color: var(--text-secondary);
    font-size: 1rem;
    pointer-events: none;
    transition: 0.2s ease all;
    transform-origin: left top;
}

.floating-input:focus~.floating-label,
.floating-input:not(:placeholder-shown)~.floating-label {
    top: 12px;
    transform: translateY(0) scale(0.85);
    color: var(--primary-600);
    font-weight: 500;
}

body.dark .floating-input {
    background: #1e293b;
    border-color: #475569;
    color: white;
}

body.dark .floating-input:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

body.dark .floating-label {
    color: #94a3b8;
}

body.dark .floating-input:focus~.floating-label,
body.dark .floating-input:not(:placeholder-shown)~.floating-label {
    color: #38bdf8;
}

.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 220px;
    font-size: 0.85rem;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-light);
    border-radius: 99px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.custom-select-trigger:hover {
    background: var(--bg-surface);
    border-color: var(--primary-300);
    color: var(--primary-600);
}

body.dark .custom-select-trigger {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

body.dark .custom-select-trigger:hover {
    background: #27272a;
    border-color: var(--primary-700);
}

.custom-select-trigger .arrow {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-secondary);
    margin-left: 10px;
    transition: transform 0.2s;
}

.custom-select-wrapper.open .custom-select-trigger .arrow {
    transform: rotate(180deg);
}

.custom-select-options {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    display: none;
    z-index: 1000;
    overflow: hidden;
    flex-direction: column;
    max-height: 200px;
    overflow-y: auto;
}

body.dark .custom-select-options {
    background: rgba(24, 24, 27, 0.9);
    border-color: var(--border-light);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.custom-select-wrapper.open .custom-select-options {
    display: flex;
    animation: fadeIn 0.15s ease-out;
}

.custom-option {
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.1s;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}

.custom-option:last-child {
    border-bottom: none;
}

.custom-option:hover {
    background: var(--primary-50);
    color: var(--primary-600);
}

body.dark .custom-option:hover {
    background: var(--primary-900);
    color: var(--primary-400);
}

.custom-option.selected {
    background: var(--primary-100);
    color: var(--primary-700);
    font-weight: 600;
}

body.dark .custom-option.selected {
    background: rgba(37, 99, 235, 0.2);
    color: var(--primary-400);
}

.template-actions {
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 0.5rem;
}

.template-card:hover .template-actions {
    opacity: 1;
}

.template-preview {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.empty-state-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

/* Dark Mode Overrides */
body.dark .districts-sidebar {
    background: var(--bg-surface-alt);
    border-color: var(--border-light);
}

body.dark .district-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--primary-300);
}

body.dark .district-btn.active {
    background: rgba(14, 165, 233, 0.15);
    color: var(--primary-400);
    border-color: rgba(14, 165, 233, 0.3);
}

body.dark .templates-content {
    background: var(--bg-surface);
}

body.dark .template-card {
    background: var(--bg-surface-alt);
    border-color: var(--border-light);
}

body.dark .template-title {
    color: var(--text-primary);
}

body.dark .template-preview {
    color: var(--text-secondary);
}

body.dark .template-card:hover {
    background: var(--bg-surface);
    border-color: var(--primary-500);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.text-title {
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 12px;
    font-size: 17px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.text-actions {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.text-item:hover .text-actions {
    opacity: 1;
}

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.action-btn:hover {
    background: #e2e8f0;
    transform: scale(1.2);
}

.text-preview {
    color: #64748b;
    line-height: 1.6;
    font-size: 14px;
}

.text-modality {
    display: inline-block;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 10px;
}

.no-texts {
    text-align: center;
    color: #94a3b8;
    font-style: italic;
    padding: 60px 20px;
    font-size: 16px;
}

/* Success Animation */
.success-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.3);
    display: none;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* Scrollbar Styles */
.texts-list::-webkit-scrollbar,
.body-section::-webkit-scrollbar {
    width: 8px;
}

.texts-list::-webkit-scrollbar-track,
.body-section::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.texts-list::-webkit-scrollbar-thumb,
.body-section::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.texts-list::-webkit-scrollbar-thumb:hover,
.body-section::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .testo-fisso-modal {
        flex-direction: column;
        height: 95vh;
    }

    .body-section {
        border-right: none;
        border-bottom: 2px solid #e2e8f0;
        flex: none;
        max-height: 40vh;
        padding: 20px;
    }

    .human-body-container {
        max-width: 250px;
    }

    .texts-section {
        padding: 20px;
    }

    .modality-filters {
        gap: 10px;
    }

    .modality-filter {
        padding: 8px 12px;
        font-size: 14px;
    }

    .texts-title {
        font-size: 20px;
    }

    .body-label {
        display: none;
    }
}

/* MDC Sources Section */
.sources-section {
    margin-top: 3rem;
    border-top: 1px solid var(--border-light);
    padding-top: 1.5rem;
}

.sources-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: 8px;
    transition: background 0.2s;
    user-select: none;
}

.sources-title:hover {
    background: #f1f5f9;
    color: var(--primary-700);
}

.sources-title::after {
    content: '▼';
    font-size: 0.7em;
    margin-left: auto;
    transition: transform 0.3s;
    opacity: 0.6;
}

.sources-title.expanded::after {
    transform: rotate(180deg);
}

.sources-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out, opacity 0.3s ease-out;
    opacity: 0.5;
    padding: 0 0.75rem;
}

.sources-content.expanded {
    max-height: 500px;
    /* Arbitrary large enough value */
    opacity: 1;
    margin-top: 0.5rem;
}

.source-item {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
}

.source-item:last-child {
    border-bottom: none;
}

/* Dark Mode for Sources */
body.dark .sources-section {
    border-color: var(--border-dark);
}

body.dark .sources-title {
    color: var(--text-secondary);
}

body.dark .sources-title:hover {
    background: var(--bg-surface-alt);
    color: var(--text-primary);
}

body.dark .source-item {
    color: var(--text-muted);
    border-color: var(--border-dark);
}

.dropdown-wrapper {
    display: inline-flex;
}

.dropdown-menu {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 1000;
    min-width: 200px;
}

.dropdown-item {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-light);
}

.dropdown-item:hover {
    background: #f3f4f6;
}

body.dark .dropdown-menu {
    background: var(--bg-dark-secondary);
    border-color: var(--border-dark);
}

body.dark .dropdown-item {
    color: var(--text-dark);
}

body.dark .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

button#restyleDropdown:hover {
    transform: none;
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .navbar,
    .btn,
    .upload-area,
    footer,
    .tools-sidebar,
    .no-print {
        display: none !important;
    }

    .main-wrapper,
    .card {
        padding: 0;
        margin: 0;
        box-shadow: none;
        border: none;
        background: white;
    }

    .viewer-section {
        display: block;
    }

    .dicom-viewer-container {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* 
   -------------------------------------------------------------------------
   TESTI FISSI OVERLAY - NUCLEAR REFACTOR (Guarantee Visibility)
   -------------------------------------------------------------------------
*/

.testo-fisso-overlay {
    /* Critical: Fixed position relative to viewport */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;

    /* High Z-Index to stay on top of everything */
    z-index: 999999 !important;

    /* Solid semi-transparent background */
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(5px);

    /* Flex Center */
    display: none;
    /* JS toggles this to 'flex' */
    align-items: center;
    justify-content: center;
}

.testo-fisso-modal {
    background: white;
    width: 90%;
    max-width: 1000px;
    height: 85vh;
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    /* Ensure opacity is 1 */
    opacity: 1 !important;
    visibility: visible !important;
}

/* Dark Mode Override */
body.dark .testo-fisso-modal {
    background: #1e1e1e !important;
    border: 1px solid #333;
    color: #e5e5e5;
}

/* Internal Layout */
.template-layout-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.districts-sidebar {
    width: 250px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
    padding: 1rem;
}

body.dark .districts-sidebar {
    background: #262626;
    border-color: #404040;
}

.templates-content {
    flex: 1;
    background: #ffffff;
    padding: 1.5rem;
    overflow-y: auto;
}

body.dark .templates-content {
    background: #1e1e1e;
}

/* Editor Footer Controls (Moved from index.html) */
.editor-footer-controls {
    padding: 1rem 2rem;
    background: white;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn-record {
    background: var(--primary-600);
    color: white;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

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

.btn-stop {
    background: var(--danger-500);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-stop:hover {
    background: var(--danger-600);
    transform: translateY(-1px);
}

/* New Restyle Button */
.btn-restyle {
    background: #8b5cf6;
    /* Violet 500 */
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-restyle:hover {
    background: #7c3aed;
    /* Violet 600 */
    transform: translateY(-1px);
}


.mic-active-pulse {
    animation: pulse-ring 2s infinite;
}

body.dark .editor-footer-controls {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

@keyframes pulse-ring {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* App Footer */
.app-footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 0.9rem;
    background: var(--bg-surface);
}

.app-footer p {
    margin: 0.25rem 0;
}

.app-footer .disclaimer {
    font-size: 0.75rem;
    opacity: 0.7;
    max-width: 600px;
    margin: 0.5rem auto 0;
}

body.dark .app-footer {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

/* 
   -------------------------------------------------------------------------
   CALCIUM SCORE REPORT MODAL - PREMIUM MEDICAL DASHBOARD (A4)
   -------------------------------------------------------------------------
*/

#reportSection {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
    overflow-y: auto;
}

.report-modal {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin: auto;
}

/* Paper Container */
.medical-report-paper {
    width: 210mm;
    min-height: 297mm;
    background: white;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    padding: 15mm;
    /* Slightly tighter margins for more content */
    color: #1a1a1a;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Dashboard Header */
.report-dashboard-header {
    border-bottom: 2px solid #000;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.report-main-title {
    font-size: 1.6rem;
    font-weight: 900;
    color: #000;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.scan-meta {
    font-size: 0.8rem;
    color: #666;
    margin-top: 0.25rem;
    font-weight: 500;
}

.report-date-block {
    text-align: right;
    font-size: 0.9rem;
}

/* Dashboard Grid Layout */
.report-dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Row 1: Metrics */
.dashboard-metrics-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 1rem;
}

.metric-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.metric-card.main-metric {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.metric-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #64748b;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 2.5rem;
    font-weight: 900;
    line-height: 1;
    color: #0f172a;
}

.metric-value.small {
    font-size: 1.5rem;
    color: #334155;
}

/* Row 2: Split Anatomy/Interp */
.dashboard-split-row {
    display: grid;
    grid-template-columns: 4fr 5fr;
    /* Anatomy slightly smaller than text */
    gap: 1.5rem;
}

.section-label {
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #000;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0.25rem;
    margin-bottom: 0.75rem;
}

.dense-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.dense-table th {
    text-align: left;
    color: #64748b;
    font-weight: 600;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.dense-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}

.dense-table tr:last-child td {
    border-bottom: none;
}

.dense-table.striped tr:nth-child(even) {
    background-color: #f8fafc;
}

.table-total-row td {
    border-top: 2px solid #e2e8f0;
    font-weight: 700;
    background: #f8fafc;
}

.text-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #334155;
    min-height: 80px;
}

.interpretation-box {
    border-left: 3px solid #3b82f6;
    /* Blue accent */
}

.recommendation-box {
    border-left: 3px solid #f59e0b;
    /* Orange accent */
}

/* Row 3: Meta Header */
.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
}

.section-header-row .section-label {
    border: none;
    margin: 0;
    padding: 0;
}

.section-meta {
    font-size: 0.8rem;
    color: #64748b;
}

/* Row 4: Biblio */
.footer-notes {
    margin-top: auto;
    /* Push to bottom if space permits */
    padding-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.75rem;
    color: #94a3b8;
}

.biblio-list {
    margin: 0;
    padding-left: 1rem;
    list-style-type: none;
}

.biblio-list li {
    margin-bottom: 0.2rem;
    position: relative;
    padding-left: 0.5rem;
}

.biblio-list li::before {
    content: "•";
    position: absolute;
    left: -0.5rem;
}

/* Helpers */
.text-right {
    text-align: right;
}

.font-bold {
    font-weight: 700;
}

.font-mono {
    font-family: 'Roboto Mono', monospace;
}

.text-muted {
    color: #94a3b8;
}

.full-width {
    width: 100%;
}

/* Risk Badges */
.risk-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.risk-minimal {
    background: #dcfce7;
    color: #166534;
}

.risk-mild {
    background: #fef9c3;
    color: #854d0e;
}

.risk-moderate {
    background: #ffedd5;
    color: #9a3412;
}

.risk-severe {
    background: #fee2e2;
    color: #991b1b;
}

/* Actions Bar - Fixed Spacing & Centering */
.report-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    width: 100%;
    margin-top: 1rem;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 2rem;
    border-radius: 99px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn-action.close {
    background: white;
    color: #334155;
    border: 1px solid #e2e8f0;
}

.btn-action.print {
    background: #0f172a;
    color: #fff;
}

.btn-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* 
   ----------------
   PRINT RULES
   ----------------
*/
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        background: white;
        color: black;
        visibility: hidden;
    }

    #reportSection {
        display: block !important;
        position: static;
        background: white;
        width: 100%;
        height: auto;
        padding: 0;
        visibility: visible;
        overflow: visible;
    }

    .report-modal {
        margin: 0;
        width: 100%;
    }

    .medical-report-paper {
        visibility: visible;
        box-shadow: none;
        margin: 0;
        width: 100%;
        min-height: auto;
        padding: 10mm;
        /* maximize print area */
        border: none;
    }

    .medical-report-paper * {
        visibility: visible;
    }

    .no-print {
        display: none !important;
    }

    /* Force Colors for Print */
    .metric-card,
    .text-box,
    .dense-table.striped tr:nth-child(even) {
        background: white !important;
        border: 1px solid #ccc !important;
        color: black !important;
    }

    .biblio-list {
        color: #444 !important;
    }

    .metric-value,
    .report-main-title {
        color: black !important;
    }
}