:root {
    /* Neutrals */
    --bg-color: #f5f5f7;
    --card-bg: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --border-color: #e5e5ea;
    --divider-color: #f2f2f7;

    /* Accent Color (Easy to change) */
    --accent-color: #007aff;
    --accent-light: rgba(0, 122, 255, 0.1);

    /* Status Colors */
    --status-pending: #ff3b30;
    --status-progress: #ff9f0a;
    --status-completed: #34c759;

    /* UI Elements */
    --header-height: 60px;
    --nav-height: 65px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-size: 16px;
    overflow-x: hidden;
    /* Prevent pull-to-refresh on mobile if possible */
    overscroll-behavior-y: none;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* Layout */
#app-content {
    padding-top: var(--header-height);
    padding-bottom: calc(var(--nav-height) + 20px);
    min-height: 100vh;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    /* Center on larger screens */
    position: relative;
}

.content-padding {
    padding: 0 16px 16px 16px;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 50;
    border-bottom: 1px solid var(--border-color);
    max-width: 600px;
    margin: 0 auto;
}

.app-header h1 {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    flex: 1;
}

.header-left,
.header-right {
    width: 40px;
    /* To balance flex centering */
    display: flex;
    align-items: center;
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    margin-left: -8px;
}

.back-btn i {
    width: 24px;
    height: 24px;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--border-color);
    z-index: 50;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    padding: 8px 16px;
    transition: color 0.2s ease;
}

.nav-item i {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
    stroke-width: 2;
}

.nav-item.active {
    color: var(--accent-color);
}

/* View Management */
.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Search Bar */
.search-wrapper {
    padding: 16px;
    background-color: var(--bg-color);
    position: sticky;
    top: var(--header-height);
    z-index: 40;
}

.search-container {
    background-color: #e3e3e8;
    border-radius: 10px;
    display: flex;
    align-items: center;
    padding: 8px 12px;
}

.search-icon {
    color: var(--text-secondary);
    width: 18px;
    height: 18px;
    margin-right: 8px;
}

.search-container input {
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--text-primary);
    width: 100%;
    outline: none;
}

.search-container input::placeholder {
    color: var(--text-secondary);
}

/* Category Filters */
.categories-filter {
    display: flex;
    overflow-x: auto;
    padding: 0 16px 16px 16px;
    gap: 10px;
    scrollbar-width: none;
    /* Firefox */
}

.categories-filter::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.category-chip {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.category-chip.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* Cards (Manuals) */
.manuals-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.manual-card {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s, box-shadow 0.1s;
    border: 1px solid transparent;
}

.manual-card:active {
    transform: scale(0.98);
    background-color: #fafafa;
}

.manual-icon {
    font-size: 28px;
    background-color: var(--divider-color);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.manual-info {
    flex: 1;
}

.manual-Title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.manual-desc {
    font-size: 14px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state i {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Detail View */
.detail-header {
    padding: 24px 16px 16px;
}

.detail-category {
    font-size: 13px;
    color: var(--accent-color);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.detail-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.2;
}

.detail-desc {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    margin: 24px 16px 12px;
    color: var(--text-primary);
}

/* Materials List */
.materials-box {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    margin: 0 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.materials-list {
    list-style: none;
}

.materials-list li {
    display: flex;
    align-items: center;
    padding: 8px 0;
    font-size: 15px;
    border-bottom: 1px solid var(--divider-color);
}

.materials-list li:last-child {
    border-bottom: none;
}

.materials-list li::before {
    content: "•";
    color: var(--accent-color);
    font-weight: bold;
    margin-right: 12px;
    font-size: 20px;
}

/* Steps List */
.steps-container {
    padding: 0 16px;
}

.step-item {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.step-number {
    background-color: var(--accent-color);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.step-content {
    background-color: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius-md);
    flex: 1;
    font-size: 15px;
    box-shadow: var(--shadow-sm);
    line-height: 1.5;
}

/* Notes Alert */
.notes-alert {
    background-color: rgba(255, 159, 10, 0.1);
    border-left: 4px solid var(--status-progress);
    padding: 16px;
    margin: 24px 16px 40px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    display: flex;
    gap: 12px;
}

.notes-alert i {
    color: var(--status-progress);
    flex-shrink: 0;
}

.notes-alert p {
    font-size: 14px;
    color: #4d3b00;
}

/* Tasks Styles */
.tabs-container {
    padding: 16px;
    background-color: var(--bg-color);
    position: sticky;
    top: var(--header-height);
    z-index: 40;
}

.task-tabs {
    display: flex;
    background-color: #e3e3e8;
    border-radius: 8px;
    padding: 2px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 6px 0;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background-color: var(--card-bg);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tasks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-card {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.task-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    margin-top: 2px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.task-checkbox:checked {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.task-checkbox:checked::after {
    content: "";
    position: absolute;
    left: 7px;
    top: 3px;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.task-content {
    flex: 1;
}

.task-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    transition: color 0.2s;
}

.task-card.completed .task-title {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.task-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.task-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.task-meta-item i {
    width: 14px;
    height: 14px;
}

.task-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-pendiente {
    background-color: rgba(255, 59, 48, 0.1);
    color: var(--status-pending);
}

.badge-en-proceso {
    background-color: rgba(255, 159, 10, 0.1);
    color: var(--status-progress);
}

.badge-completado {
    background-color: rgba(52, 199, 89, 0.1);
    color: var(--status-completed);
}

.task-notes {
    font-size: 13px;
    color: var(--text-secondary);
    background-color: var(--bg-color);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

/* =========================================
   Floating Action Button (FAB) & Forms
   ========================================= */
.fab-button {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: white;
    border: none;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 40;
    transition: transform 0.2s, background-color 0.2s;
}

.fab-button:active {
    transform: scale(0.95);
}

.fab-button i {
    width: 28px;
    height: 28px;
}

/* Modal Dialog */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 450px;
    border: none;
    border-radius: var(--radius-lg);
    background-color: var(--card-bg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    padding: 0;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal[open] {
    opacity: 1;
}

.modal-content {
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 18px;
    margin: 0;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
}

.icon-btn:hover {
    background-color: var(--divider-color);
}

/* Form Elements */
#new-task-form {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-color);
    font-family: inherit;
    font-size: 15px;
    color: var(--text-primary);
    transition: border-color 0.2s;
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent-color);
}

.form-group textarea {
    resize: vertical;
}

.modal-footer {
    padding-top: 16px;
    margin-top: 8px;
}

.btn-primary {
    width: 100%;
    background-color: var(--accent-color);
    color: white;
    font-weight: 600;
    font-size: 16px;
    padding: 14px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-primary:active {
    transform: scale(0.98);
}

/* =========================================
   Desktop / Tablet Responsive Design
   ========================================= */
@media (min-width: 768px) {

    /* Push everything to the right to make space for fixed sidebar */
    body {
        padding-left: 240px;
    }

    #app-content {
        max-width: 800px;
        padding-left: 20px;
        /* Reduced from 220px, as body now handles the offset */
        padding-right: 20px;
        padding-bottom: 40px;
    }

    .app-header {
        /* Centered in the remaining space (viewport width - sidebar width) */
        left: 240px;
        right: 0;
        max-width: 800px;
        padding-left: 16px;
    }

    /* Transform Bottom Nav into a Side Bar docked to the left edge */
    .bottom-nav {
        display: flex !important;
        /* Override JS inline hiding it */
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        /* Reset inheritance from mobile */
        margin: 0;
        /* Reset inheritance from mobile */
        max-width: none;
        /* Reset inheritance from mobile */
        transform: none;
        /* Reset previously applied translation */
        width: 240px;
        height: 100vh;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        padding: calc(var(--header-height) + 30px) 20px 20px;
        border-top: none;
        border-right: 1px solid var(--border-color);
        background-color: var(--card-bg);
        /* Use card background for distinct look */
        box-shadow: 1px 0 10px rgba(0, 0, 0, 0.03);
        /* subtle shadow */
    }

    .nav-item {
        flex-direction: row;
        width: 100%;
        padding: 12px 16px;
        font-size: 15px;
        border-radius: var(--radius-md);
        margin-bottom: 8px;
    }

    .nav-item i {
        margin-bottom: 0;
        margin-right: 12px;
    }

    .nav-item:hover {
        background-color: var(--bg-color);
        /* Gentle hover */
    }

    .nav-item.active {
        background-color: var(--accent-light);
    }

    /* Use Grid Layout for lists */
    .manuals-list,
    .tasks-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .search-wrapper,
    .tabs-container {
        padding: 24px 0 16px;
    }

    .detail-header {
        padding: 24px 0 16px;
    }
}

@media (min-width: 1024px) {

    #app-content,
    .app-header {
        max-width: 1000px;
    }

    .manuals-list,
    .tasks-list {
        grid-template-columns: repeat(3, 1fr);
    }
}