:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --error-color: #ef4444;
    --success-color: #22c55e;

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header */
.main-header {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 1rem;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.header-icon {
    width: 2rem;
    height: 2rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.header-subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text-main);
    border-bottom: 2px solid var(--background-color);
    padding-bottom: 0.5rem;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

@media (min-width: 640px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.full-width {
    grid-column: 1 / -1;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 0.75rem;
    width: 1rem;
    height: 1rem;
    color: var(--text-muted);
    pointer-events: none;
}

input[type="text"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 0.625rem 0.75rem 0.625rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--background-color);
}

textarea {
    padding-left: 0.75rem;
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background-color: white;
}

/* Dynamic Sections */
.dynamic-section {
    border-left: 4px solid var(--primary-color);
    position: relative;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.section-name-group {
    flex: 1;
}

.section-name-input {
    font-weight: 600;
    font-size: 1rem;
    border: none;
    border-bottom: 2px solid var(--border-color);
    border-radius: 0;
    padding: 0.5rem 0;
    background: transparent;
}

.section-name-input:focus {
    box-shadow: none;
    border-color: var(--primary-color);
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
    background-color: #fee2e2;
    color: var(--error-color);
}

/* Subsections */
.subsections-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.subsection-item {
    background-color: #f1f5f9;
    padding: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    position: relative;
}

.subsection-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.subsection-number {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    background: #e2e8f0;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
}

/* File Upload */
.file-upload-wrapper {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    background: white;
    cursor: pointer;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-upload-wrapper:hover {
    border-color: var(--primary-color);
    background-color: #eff6ff;
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
}

.file-preview {
    position: relative;
    width: 100%;
    max-height: 200px;
    display: flex;
    justify-content: center;
}

.file-preview.hidden {
    display: none;
}

.file-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.remove-file-btn {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    color: var(--error-color);
}

/* Signature */
.signature-wrapper {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #fafafa;
    /* Slight distinctive background */
    padding: 0.5rem;
}

canvas#signatureCanvas {
    width: 100%;
    height: 200px;
    background: white;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-color);
    cursor: crosshair;
}

.signature-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* Buttons and Actions */
.actions-container {
    text-align: center;
    margin-bottom: 1.5rem;
}

.form-footer {
    position: sticky;
    bottom: 0;
    background: white;
    /* Glass effect if possible, but keep simple for now */
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.05);
    margin: 0 -1rem -1rem -1rem;
    /* Stretch full width */
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: white;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn-secondary:hover {
    background-color: #eff6ff;
}

.btn-outline {
    background: transparent;
    border: 1px dashed var(--secondary-color);
    color: var(--secondary-color);
    width: 100%;
    padding: 0.5rem;
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f8fafc;
}

.btn-text {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
}

.btn-text:hover {
    color: var(--error-color);
    text-decoration: underline;
}

.btn-lg {
    width: 100%;
    font-size: 1.1rem;
    padding: 1rem;
}

/* Helper Text */
.helper-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Header Override for Dashboard */
.btn-header {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.btn-header:hover {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

/* Dashboard List */
.protocol-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.protocol-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}

.protocol-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
    border-color: var(--primary-color);
}

.protocol-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.protocol-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.75rem;
}

.protocol-actions {
    display: flex;
    gap: 0.5rem;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-style: italic;
}

/* Visibility */
.hidden {
    display: none !important;
}

/* Icon Buttons */
.btn-icon-large {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-large:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Form Footer Update */
.form-footer {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.form-footer .btn {
    flex: 1;
}