/* ===== Pull to Refresh ===== */
.pull-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #6b7280;
    background: #f3f4f6;
    transform: translateY(-50px);
    opacity: 0;
    transition: transform 0.2s, opacity 0.2s;
    z-index: 9999;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
html {
    background: #f3f4f6 !important;
    height: 100%;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f3f4f6 !important;
    color: #1f2937;
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
    min-height: 100dvh;
    min-height: 100lvh;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ===== Task Banner (sticky top) ===== */
.task-banner {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #1e293b;
    color: #fff;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.task-banner .task-info { flex: 1; min-width: 0; }
.task-banner .task-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-banner .task-path { font-size: 0.7rem; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-banner .btn-advance,
.task-banner .btn-unassign {
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
    cursor: pointer;
    font-weight: 700;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.task-banner .btn-view {
    border: none;
    border-radius: 8px;
    width: 76px;
    height: 38px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #3b82f6;
    color: #fff;
    text-decoration: none;
}
.task-banner .btn-view:hover { text-decoration: none; }
.task-banner .btn-advance { background: #22c55e; color: #fff; }
.task-banner .btn-advance:active { background: #16a34a; }
.task-banner .btn-unassign { background: #ef4444; color: #fff; }
.task-banner .btn-unassign:active { background: #dc2626; }

/* ===== Page Container ===== */
.page { padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px; max-width: 600px; margin: 0 auto; }
.page h1 { font-size: 1.4rem; margin-bottom: 12px; }
.page h2 { font-size: 1.1rem; margin-bottom: 8px; color: #374151; }

/* ===== Cards ===== */
.card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s;
}
a.card:hover, .card-link:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    text-decoration: none;
}

/* ===== Forms Grid ===== */
.forms-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: inherit;
    background: #fff;
    border-radius: 6px;
    padding: 16px 12px;
    aspect-ratio: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}
.form-card::before {
    content: '';
    position: absolute;
    inset: -6px;
    background: url('/static/container-watermark.png') center / 100% 100% no-repeat;
    opacity: 0.35;
    pointer-events: none;
}
.form-card h2 {
    position: relative;
    font-size: 1rem;
    margin-bottom: 4px;
}
.form-card .text-muted {
    position: relative;
    font-size: 0.8rem;
}
.form-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    text-decoration: none;
}

/* ===== Admin Dashboard Grid ===== */
.admin-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}
.admin-tile {
    display: block;
    text-decoration: none;
    color: #500000;
    background: #fff;
    border-radius: 10px;
    padding: 20px 16px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.15s;
    border: 2px solid #500000;
}
.admin-tile::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('/static/container-side-watermark.png') center / cover no-repeat;
    opacity: 0.3;
    pointer-events: none;
}
.admin-tile h2 {
    position: relative;
    font-size: 1.05rem;
    margin-bottom: 4px;
    color: #500000;
}
.admin-tile .text-muted {
    position: relative;
    font-size: 0.85rem;
    color: #7a3030;
}
.admin-tile:hover {
    box-shadow: 0 4px 16px rgba(80,0,0,0.25);
    text-decoration: none;
}
.admin-cycle-banner {
    display: block;
    text-decoration: none;
    color: #fff;
    background: #2563eb;
    border-radius: 10px;
    padding: 20px 16px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.15s;
    margin-top: 12px;
}
.admin-cycle-banner::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('/static/container-side-watermark.png') center / cover no-repeat;
    opacity: 0.3;
    pointer-events: none;
}
.admin-cycle-banner h2 {
    position: relative;
    font-size: 1.1rem;
    margin-bottom: 4px;
    color: #fff;
}
.admin-cycle-banner p {
    position: relative;
    font-size: 0.85rem;
    opacity: 0.85;
    margin: 0;
}
.admin-cycle-banner:hover {
    box-shadow: 0 4px 16px rgba(37,99,235,0.35);
    text-decoration: none;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9rem;
}
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    -webkit-appearance: none;
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input[type="file"] {
    padding: 8px;
    font-size: 0.9rem;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    width: 100%;
    text-decoration: none;
    transition: opacity 0.15s;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn:active { opacity: 0.8; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-secondary { background: #6b7280; color: #fff; }

/* ===== Alerts ===== */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ===== Task Grid ===== */
.task-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.task-square {
    position: relative;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    color: #fff;
    text-align: left;
    cursor: pointer;
    padding: 16px 10px 8px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
    text-decoration: none;
    transition: transform 0.1s, box-shadow 0.1s;
    overflow: hidden;
}
.task-square::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('/static/container-side-watermark.png') center / cover no-repeat;
    opacity: 0.3;
    pointer-events: none;
}
.task-square .task-name {
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.25;
    word-break: break-word;
}
.task-square .task-meta {
    font-size: 0.65rem;
    opacity: 0.85;
    margin-top: 3px;
    line-height: 1.3;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.task-assignee-strip {
    position: absolute;
    top: 0;
    left: 0;
    width: calc(50% - 2px);
    background: transparent;
    color: #fff;
    border-bottom: 2px solid var(--pill-border);
    border-right: 2px solid var(--pill-border);
    font-size: 0.5rem;
    font-weight: 700;
    padding: 2px 0;
    text-align: center;
    text-shadow: none;
    line-height: 1.3;
    border-bottom-right-radius: 6px;
}
/* Gradient pill border for batch cards */
.task-square[data-batch-gradient] .task-assignee-strip {
    border-color: transparent;
}
.task-square[data-batch-gradient] .task-assignee-strip::after {
    content: '';
    position: absolute;
    inset: 0;
    border-bottom-right-radius: 6px;
    padding: 0 2px 2px 0;
    background: var(--gradient-light);
    background-size: calc(200% + 8px) 100%;
    background-position: left;
    -webkit-mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
}
.task-square .task-batch-count {
    position: absolute;
    right: 0;
    top: 0;
    width: calc(50% - 2px);
    font-size: 0.5rem;
    font-weight: 700;
    color: #fff;
    background: transparent;
    border-bottom: 2px solid var(--pill-border);
    border-left: 2px solid var(--pill-border);
    padding: 2px 0;
    text-align: center;
    text-shadow: none;
    line-height: 1.3;
    border-bottom-left-radius: 6px;
}
.task-square[data-batch-gradient] .task-batch-count {
    border-color: transparent;
}
.task-square[data-batch-gradient] .task-batch-count::after {
    content: '';
    position: absolute;
    inset: 0;
    border-bottom-left-radius: 6px;
    padding: 0 0 2px 2px;
    background: var(--gradient-light);
    background-size: calc(200% + 8px) 100%;
    background-position: right;
    -webkit-mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
}
.task-square:hover {
    transform: scale(1.03);
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    text-decoration: none;
}
.task-red    { background: #dc2626; }
.task-yellow { background: #eab308; }
.task-blue   { background: #3b82f6; }
.task-green  { background: #16a34a; }

/* ===== Bottom Tab Bubble ===== */
.tab-bubble {
    position: fixed;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    z-index: 200;
    background: #fff;
    border-radius: 28px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.08);
}
.tab-bubble a {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.6rem;
    color: #9ca3af;
    padding: 4px 10px;
    text-decoration: none;
    gap: 1px;
    transition: color 0.15s;
    font-weight: 500;
}
.tab-bubble a.active { color: #2563eb; font-weight: 700; }
.tab-bubble a .tab-icon { font-size: 1.25rem; }

/* ===== Expanded Tab Panel ===== */
.tab-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 199;
}
.tab-overlay.open { display: block; }
.tab-expanded {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 201;
    background: #fff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 33vh;
    overflow-y: auto;
}
.tab-expanded.open {
    transform: translateY(0);
}
.tab-expanded-handle {
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0 auto 12px;
}
.tab-expanded-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.tab-expanded-grid a {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #374151;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 10px 4px;
    border-radius: 12px;
    transition: background 0.15s;
    gap: 2px;
}
.tab-expanded-grid a:hover { background: #f3f4f6; text-decoration: none; }
.tab-expanded-grid a.active { color: #2563eb; font-weight: 700; }
.tab-expanded-grid a .tab-icon { font-size: 1.4rem; }
.tab-expanded-grid .edit-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #6b7280;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 10px 4px;
    border-radius: 12px;
    border: 1px dashed #d1d5db;
    cursor: pointer;
    background: none;
    gap: 2px;
}
.tab-expanded-grid .edit-btn:hover { background: #f3f4f6; }
.tab-expanded-grid .edit-btn .tab-icon { font-size: 1.4rem; }

/* ===== Edit Mode ===== */
.tab-edit-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.tab-edit-panel {
    background: #fff;
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.tab-edit-panel h3 { font-size: 1rem; margin-bottom: 12px; color: #1f2937; }
.tab-edit-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.9rem;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.25s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    position: relative;
    z-index: 0;
    background: #fff;
    border-radius: 8px;
}
.tab-edit-item .drag-handle { color: #d1d5db; font-size: 1.1rem; }
.tab-edit-item .edit-icon { font-size: 1.2rem; width: 28px; text-align: center; }
.tab-edit-item .edit-label { flex: 1; font-weight: 500; }
.tab-edit-item.dragging {
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    transform: scale(1.04);
    opacity: 0.95;
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}
.tab-edit-item.drag-placeholder {
    opacity: 0;
    pointer-events: none;
}

/* ===== Misc ===== */
.text-muted { color: #6b7280; font-size: 0.85rem; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }

/* Tables - responsive */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #e5e7eb; }
th { background: #f9fafb; font-weight: 600; position: sticky; top: 0; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
}
.badge-new { background: #eab308; }
.badge-ordered { background: #3b82f6; }
.badge-received { background: #22c55e; }

/* ===== Progress bar ===== */
.progress-bar {
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-bar .progress-fill {
    height: 100%;
    background: #22c55e;
    border-radius: 3px;
    transition: width 0.3s;
}
