/* CSS Variables - shadcn/ui inspired */
:root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --primary: 222.2 47.4% 11.2%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 222.2 84% 4.9%;
    --radius: 0.5rem;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Header */
.header {
    border-bottom: 1px solid hsl(var(--border));
    padding: 1.5rem 0;
}

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

.header-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.header-description {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
}

/* Main */
.main {
    padding: 2rem 0;
}

/* Card */
.card {
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

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

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: hsl(var(--card-foreground));
}

/* Table */
.table-container {
    overflow-x: auto;
}

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

.table thead {
    border-bottom: 1px solid hsl(var(--border));
}

.table th {
    padding: 0.75rem 1.5rem;
    text-align: left;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
    color: hsl(var(--foreground));
}

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

.table tbody tr:hover {
    background-color: hsl(var(--muted));
}

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

/* Empty State */
.empty-state {
    padding: 4rem 1.5rem !important;
    border-bottom: none !important;
}

.empty-state-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.empty-icon {
    color: hsl(var(--muted-foreground));
    opacity: 0.5;
    margin-bottom: 1rem;
}

.empty-title {
    font-size: 1rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    margin-bottom: 0.5rem;
}

.empty-description {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background-color: hsl(var(--primary) / 0.9);
}

.btn-outline {
    border: 1px solid hsl(var(--input));
    background-color: transparent;
    color: hsl(var(--foreground));
}

.btn-outline:hover:not(:disabled) {
    background-color: hsl(var(--accent));
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-ghost {
    background-color: transparent;
    color: hsl(var(--foreground));
}

.btn-ghost:hover:not(:disabled) {
    background-color: hsl(var(--accent));
}

.btn-destructive {
    background-color: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.btn-destructive:hover:not(:disabled) {
    background-color: hsl(var(--destructive) / 0.9);
}

.btn-icon-danger {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius);
    color: hsl(var(--destructive));
    transition: all 0.15s;
}

.btn-icon-danger:hover {
    background-color: hsl(var(--destructive) / 0.1);
}

.icon {
    width: 1rem;
    height: 1rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background-color: hsl(var(--card));
    border-radius: calc(var(--radius) * 2);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    width: 100%;
    max-width: 42rem;
    max-height: 90vh;
    overflow: auto;
    margin: 1rem;
    animation: slideIn 0.2s;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.modal-close {
    background: transparent;
    border: none;
	cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius);
    color: hsl(var(--muted-foreground));
    transition: all 0.15s;
}

.modal-close:hover {
    background-color: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.modal-body {
    padding: 1.5rem;
}

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

/* Form Elements */
.form-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.label {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.label-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: hsl(var(--muted-foreground));
}

.input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid hsl(var(--input));
    border-radius: var(--radius);
    font-size: 0.875rem;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    transition: all 0.15s;
}

.input:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}

/* Dropzone */
.dropzone {
    border: 2px dashed hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.dropzone:hover {
    border-color: hsl(var(--ring));
    background-color: hsl(var(--muted));
}

.dropzone.dragover {
    border-color: hsl(var(--primary));
    background-color: hsl(var(--primary) / 0.05);
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
	text-align: center;
}

.dropzone-icon {
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.75rem;
}

.dropzone-text {
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    margin-bottom: 0.5rem;
}

.dropzone-highlight {
    font-weight: 500;
    color: hsl(var(--primary));
}

.dropzone-hint {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.file-selected {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: hsl(var(--muted));
    border-radius: var(--radius);
}

.file-icon {
    color: hsl(var(--primary));
    flex-shrink: 0;
}

.file-details {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.125rem;
}

/* Progress */
.progress-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

.progress-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.progress-percentage {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
}

.progress-bar {
    height: 0.5rem;
    background-color: hsl(var(--secondary));
    border-radius: 9999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: hsl(var(--primary));
    transition: width 0.3s ease;
    width: 0%;
}

/* Steps */
.steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.step {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    background-color: hsl(var(--card));
    transition: all 0.15s;
}

.step.active {
    border-color: hsl(var(--primary));
    background-color: hsl(var(--primary) / 0.05);
}

.step.completed {
    border-color: hsl(120 60% 50%);
    background-color: hsl(120 60% 50% / 0.05);
}

.step.error {
    border-color: hsl(var(--destructive));
    background-color: hsl(var(--destructive) / 0.05);
}

.step-indicator {
    flex-shrink: 0;
}

.step-icon {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    background-color: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
}

.step.active .step-icon {
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.step.completed .step-icon {
    background-color: hsl(120 60% 50%);
    color: white;
}

.step.error .step-icon {
    background-color: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.step-content {
    flex: 1;
}

.step-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.step-description {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.125rem;
}

/* Alerts */
.alert {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid;
}

.alert-destructive {
    border-color: hsl(var(--destructive) / 0.5);
    background-color: hsl(var(--destructive) / 0.1);
    color: hsl(var(--destructive));
}

.alert-success {
    border-color: hsl(120 60% 50% / 0.5);
    background-color: hsl(120 60% 50% / 0.1);
    color: hsl(120 60% 30%);
}

.alert-icon {
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.alert-description {
    font-size: 0.8125rem;
    opacity: 0.9;
}

.success-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.stat {
    padding: 0.5rem;
    background-color: hsl(var(--background));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.stat-label {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.125rem;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    background-color: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}

/* Spinner */
.spinner {
    animation: spin 1s linear infinite;
}

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

/* Toast */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 24rem;
}

.toast {
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    padding: 1rem;
    animation: slideInRight 0.3s;
}

@keyframes slideInRight {
    from {
	opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-success {
    border-left: 4px solid hsl(120 60% 50%);
}

.toast-error {
    border-left: 4px solid hsl(var(--destructive));
}

.toast-content {
    font-size: 0.875rem;
    color: hsl(var(--foreground));
}

/* Patients UI */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.patients-toolbar {
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
}

.patients-search-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    width: 100%;
    margin-bottom: -0.5rem;
}

.patients-search-input {
    max-width: 22rem;
    flex: 1;
    min-width: 12rem;
}

.patients-result-meta {
    font-size: 0.8125rem;
    margin-left: auto;
    align-self: center;
}

.patients-split {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 1.5rem;
    align-items: start;
}

.patients-table-wrap {
    max-height: min(70vh, 32rem);
    overflow-y: auto;
}

.table-row-clickable {
    cursor: pointer;
}

.table tbody tr.table-row-clickable.is-selected {
    background-color: hsl(var(--accent));
}

.table tbody tr.table-row-clickable.is-selected:hover {
    background-color: hsl(var(--accent));
}

.patients-detail-body {
    min-height: 14rem;
}

.patients-detail-placeholder {
    padding: 2rem 1.5rem;
}

.patients-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 1.5rem 0;
    flex-wrap: wrap;
}

.patients-detail-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.patients-detail-sub {
    margin-top: 0.25rem;
    font-size: 0.875rem;
}

.patients-detail-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.patient-tabs-wrap {
    border-bottom: 1px solid hsl(var(--border));
    margin: 0;
}

.patient-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.125rem;
    overflow-x: auto;
    padding: 0 1rem;
    -webkit-overflow-scrolling: touch;
}

.patient-tab {
    flex: 0 0 auto;
    padding: 0.625rem 0.75rem;
    margin-bottom: -1px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.patient-tab:hover {
    color: hsl(var(--foreground));
    background-color: hsl(var(--muted) / 0.5);
}

.patient-tab[aria-selected='true'] {
    color: hsl(var(--foreground));
    border-bottom-color: hsl(var(--primary));
    font-weight: 600;
}

.patient-tab-panels {
    padding: 0;
}

.patient-tab-panel {
    display: none;
    padding: 0 0 1rem;
}

.patient-tab-panel.is-active {
    display: block;
}

.patient-tab-table-wrap {
    max-height: min(55vh, 28rem);
    overflow: auto;
    margin: 0 0 0.5rem;
}

.table-patient-sub {
    font-size: 0.8125rem;
}

.table-patient-sub th,
.table-patient-sub td {
    padding: 0.5rem 0.75rem;
    vertical-align: top;
}

.patient-subline {
    font-size: 0.75rem;
    margin-top: 0.25rem;
    line-height: 1.35;
}

.patient-tab-empty {
    padding: 2rem 1.5rem;
    text-align: center;
}

.patient-tab-empty .empty-title {
    font-size: 0.9375rem;
}

.patient-tab-empty .empty-description {
    font-size: 0.875rem;
}

.patient-count-row {
    padding: 0.75rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    border-bottom: 1px solid hsl(var(--border));
}

.patient-count-chip strong {
    font-weight: 600;
    color: hsl(var(--foreground));
}

.patient-dl {
    margin: 0;
    padding: 0 0 0.5rem;
}

.patient-dl-row {
    display: grid;
    grid-template-columns: 11rem 1fr;
    gap: 1rem;
    padding: 0.625rem 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
}

.patient-dl-row:last-child {
    border-bottom: none;
}

.patient-dl-row dt {
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    margin: 0;
}

.patient-dl-row dd {
    font-size: 0.875rem;
    margin: 0;
    color: hsl(var(--foreground));
}

.badge {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 0.125rem 0.5rem;
    border-radius: calc(var(--radius) - 2px);
    line-height: 1.25;
}

.badge-muted {
    background-color: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
}

.badge-destructive {
    background-color: hsl(var(--destructive) / 0.12);
    color: hsl(var(--destructive));
}

.badge-accent {
    background-color: hsl(var(--primary) / 0.1);
    color: hsl(var(--primary));
}

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

.font-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 0.8125rem;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .patients-split {
        grid-template-columns: 1fr;
    }

    .patients-result-meta {
        width: 100%;
        margin-left: 0;
    }

    .patient-dl-row {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal {
        margin: 0.5rem;
    }

    .table {
        font-size: 0.8125rem;
    }

    .table th,
    .table td {
        padding: 0.75rem 1rem;
    }
}

/* Focus Styles */
*:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}