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

body {
    font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Courier New', monospace;
    background: #f5f5f5;
    color: #1a1a1a;
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    margin-bottom: 16px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 20px;
}

h1 {
    font-size: 28px;
    font-weight: 600;
    color: #4CAF50;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    color: #666666;
}

/* New Template Button */
.new-template-btn {
    background: #0066cc;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.new-template-btn:hover {
    background: #0052a3;
}

.new-template-btn:active {
    transform: translateY(1px);
}

/* Search Section */
.search-section {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 16px 24px;
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.search-input {
    width: 100%;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    padding: 10px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    background: #f9f9f9;
    color: #1a1a1a;
    margin-bottom: 12px;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: #0066cc;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.search-input::placeholder {
    color: #999999;
}

.filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    background: #ffffff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.filter-select:focus {
    outline: none;
    border-color: #0066cc;
}

/* Templates Container */
.templates-container {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    min-height: 400px;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.template-card {
    background: #f9f9f9;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.template-card:hover {
    border-color: #0066cc;
    background: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.15);
}

.template-title {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 4px;
    line-height: 1.4;
}

.template-dotphrase {
    font-size: 12px;
    color: #666666;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 8px;
    opacity: 0.8;
}

.template-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.template-author {
    font-size: 12px;
    color: #666666;
    font-style: italic;
    padding: 4px 8px;
    background: #f5f5f5;
    border-radius: 4px;
}

.template-type-badge {
    background: #e3f2fd;
    color: #0066cc;
    padding: 3px 10px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
}

.template-type-badge.HPI { background: #e3f2fd; color: #0066cc; }
.template-type-badge.Assessment { background: #e8f5e9; color: #2e7d32; }
.template-type-badge.Plan { background: #fff3e0; color: #e65100; }
.template-type-badge.Physical-Exam { background: #f3e5f5; color: #7b1fa2; }
.template-type-badge.Assessment-Education { background: #fce4ec; color: #c2185b; }

.condition-tag {
    background: #f0f0f0;
    color: #666666;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
}

.template-preview {
    font-size: 12px;
    color: #666666;
    line-height: 1.5;
    max-height: 60px;
    overflow: hidden;
    position: relative;
}

.template-preview::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(transparent, #f9f9f9);
}

.template-card:hover .template-preview::after {
    background: linear-gradient(transparent, #ffffff);
}

.template-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 4px;
}

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

.action-btn {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 3px;
    padding: 4px;
    cursor: pointer;
    color: #666666;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #f5f5f5;
    border-color: #999999;
    color: #1a1a1a;
}

.delete-btn:hover {
    background: #ffebee;
    border-color: #ef5350;
    color: #c62828;
}

/* Loading and Empty States */
.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: #666666;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666666;
    font-size: 13px;
}

.create-first-btn {
    background: #0066cc;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 16px;
    transition: background-color 0.2s;
}

.create-first-btn:hover {
    background: #0052a3;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.modal-content {
    background: #ffffff;
    border-radius: 6px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.2s ease-out;
}

.modal-content.large {
    max-width: 800px;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
}

.close-btn {
    background: none;
    border: none;
    color: #666666;
    cursor: pointer;
    padding: 4px;
    border-radius: 3px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

/* Form Styles */
.template-form {
    padding: 24px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: #1a1a1a;
    margin-bottom: 8px;
    font-size: 13px;
}


.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    background: #f9f9f9;
    color: #1a1a1a;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group textarea {
    resize: vertical;
    line-height: 1.5;
    min-height: 200px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #0066cc;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

/* Multi-Select Dropdown */
.multi-select-container {
    position: relative;
}

.multi-select-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    background: #f9f9f9;
    color: #1a1a1a;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: text;
}

.multi-select-input:focus {
    outline: none;
    border-color: #0066cc;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.multi-select-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid #0066cc;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-top: -1px;
}

.multi-select-dropdown.show {
    display: block;
}

.multi-select-option {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}

.multi-select-option:hover {
    background: #f5f5f5;
}

.multi-select-option.hidden {
    display: none;
}

.multi-select-option input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    cursor: pointer;
}

.multi-select-option label {
    flex: 1;
    cursor: pointer;
    margin: 0;
    padding: 0;
    font-weight: 400;
    color: #1a1a1a;
}

.multi-select-empty {
    padding: 12px;
    text-align: center;
    color: #666666;
    font-size: 12px;
    font-style: italic;
}

/* Tag Chips */
.tag-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    min-height: 32px;
    padding: 6px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.tag-chips-container:empty {
    display: none;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s;
    cursor: default;
}

.tag-chip-remove {
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
    margin-left: 2px;
}

.tag-chip-remove:hover {
    opacity: 1;
}

/* Type tag chip colors (matching template cards) */
.tag-chip.type {
    background: #e3f2fd;
    color: #0066cc;
}

.tag-chip.type.HPI { background: #e3f2fd; color: #0066cc; }
.tag-chip.type.Assessment { background: #e8f5e9; color: #2e7d32; }
.tag-chip.type.Plan { background: #fff3e0; color: #e65100; }
.tag-chip.type.Physical-Exam { background: #f3e5f5; color: #7b1fa2; }
.tag-chip.type.Assessment-Education { background: #fce4ec; color: #c2185b; }

/* Condition tag chip colors */
.tag-chip.condition {
    background: #f0f0f0;
    color: #666666;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.btn-primary {
    background: #0066cc;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: #0052a3;
}

.btn-secondary {
    background: #ffffff;
    color: #1a1a1a;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    padding: 8px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f5f5f5;
    border-color: #999999;
}

/* Preview Styles */
.preview-actions {
    display: flex;
    gap: 8px;
}

.template-preview {
    padding: 24px;
}

.template-content-preview {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
    color: #1a1a1a;
}

/* Status Messages */
.status-message {
    padding: 12px 20px;
    margin: 16px 24px;
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}

.status-message.success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.status-message.error {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

/* Back Link */
.back-link {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #e0e0e0;
}

.back-link a {
    color: #0066cc;
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
}

.back-link a:hover {
    color: #0052a3;
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 12px;
    }

    .container {
        max-width: 100%;
    }

    h1 {
        font-size: 24px;
    }

    .subtitle {
        font-size: 13px;
    }

    .controls-section {
        padding: 12px 16px;
    }

    .search-section {
        padding: 12px 16px;
    }

    .filters {
        flex-direction: column;
    }

    .filter-select {
        width: 100%;
    }

    .templates-container {
        padding: 16px;
    }

    .templates-grid {
        grid-template-columns: 1fr;
    }

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

    .modal-content {
        margin: 12px;
        max-height: 95vh;
    }

    .template-form {
        padding: 16px;
    }

    .modal-header {
        padding: 16px 16px 12px;
    }
}
