/* Stitch Mobile Design System (v1.1) */
/* Shared Styles for "Bright Stitch" Mobile Pages */

.icon-svg {
    overflow: visible;
}

:root {
    --stitch-bg: #fdfbf7;
    /* Cream White Pastel */
    --stitch-text: #334155;
    /* Soft Slate */
    --stitch-gray: #94a3b8;
    --stitch-border: rgba(0, 0, 0, 0.03);
    --pastel-blue: #eff6ff;
    --pastel-green: #f0fdf4;
    --pastel-orange: #fff7ed;
    --pastel-yellow: #fefce8;
    --pastel-purple: #f5f3ff;
}

body {
    margin: 0;
    padding: 0;
    background: var(--stitch-bg);
    font-family: 'Pretendard', sans-serif;
    color: var(--stitch-text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* 1. Header */
.stitch-header {
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--stitch-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.user-greeting {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--stitch-text);
    display: flex;
    align-items: center;
}

#user-id {
    font-weight: 900;
    color: #0ea5e9;
    /* Professional blue for ID */
    margin-right: 4px;
}

.btn-logout {
    background: #fff;
    border: 2px solid #fee2e2;
    color: #ef4444;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
}

/* 2. Main Container */
.main-container {
    flex: 1;
    padding: 8px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

/* 3. Cards */
.stitch-card {
    background: white;
    border-radius: 20px;
    padding: 12px 16px;
    box-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.03);
    /* Softer Shadow */
    border: 1px solid var(--stitch-border);
    backdrop-filter: blur(5px);
    flex: none;
    box-sizing: border-box;
}

.info-card {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.info-item {
    text-align: center;
}

.info-label {
    font-size: 0.85rem;
    color: var(--stitch-gray);
    margin-bottom: 4px;
    font-weight: 500;
}

.info-value {
    font-size: 1.25rem;
    font-weight: 900;
    color: var(--stitch-text);
    letter-spacing: -0.5px;
}

.val-temp {
    color: #f59e0b;
}

.val-hum {
    color: #3b82f6;
}

/* 4. Action Grid */
.action-grid,
.scenario-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    flex: 1;
    align-content: start;
}

.action-card {
    background: #fff;
    border-radius: 20px;
    padding: 10px;
    text-align: center;
    box-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--stitch-border);
    cursor: pointer;
    transition: all 0.2s;
    aspect-ratio: 1/0.95;
    /* Slightly less than square to save vertical space */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    /* Fix for progress bar clipping */
}

.action-card:active {
    transform: scale(0.95);
    background: #f1f5f9;
}

.action-card.primary {
    background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    border-color: transparent;
}

.action-card.primary .action-title {
    color: #fff;
}

.action-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--stitch-text);
    word-break: keep-all;
    line-height: 1.1;
}

.icon-container {
    width: 60px;
    height: 60px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.icon-svg {
    width: 100%;
    height: 100%;
    display: block;
    transform-box: fill-box;
    /* Crucial for SVG animations */
}

/* 6. Scenario Builder */
.builder-header {
    background: #fff;
    padding: 15px;
    border-radius: 20px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.05);
}

.name-input {
    width: 100%;
    border: none;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--stitch-text);
    padding: 5px;
    background: #f8fafc;
    border-radius: 8px;
    box-sizing: border-box;
    margin-bottom: 5px;
}

.builder-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 120px;
}

.step-block {
    background: #fff;
    padding: 15px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1.5px solid #f1f5f9;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.step-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.step-label {
    font-weight: 800;
    color: #334155;
    font-size: 1rem;
    transition: color 0.2s;
}

.step-clickable {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 5px 10px;
    margin-left: -10px;
    border-radius: 12px;
    transition: background 0.2s;
}

.step-clickable:active {
    background: #f1f5f9;
}

.step-icon {
    font-size: 1.2rem;
    width: 36px;
    height: 36px;
    background: #f8fafc;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.step-val-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #cbd5e1;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
}

.step-input-val {
    width: 50px;
    border: none;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 8px 5px;
    text-align: center;
    font-size: 1rem;
    font-weight: 800;
    color: #334155;
}

.delete-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.2rem;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:active {
    color: #ef4444;
    background: #fee2e2;
    transform: scale(1.1) rotate(90deg);
}

.unit-selector {
    display: flex;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.unit-btn {
    border: none;
    background: transparent;
    padding: 4px 12px;
    border-radius: 7px;
    font-size: 0.85rem;
    font-weight: 800;
    color: #64748b;
    cursor: pointer;
}

.unit-btn.active {
    background: #fff;
    color: #3b82f6;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.state-toggle {
    display: flex;
    background: #f1f5f9;
    border-radius: 20px;
    padding: 2px;
    margin-left: auto;
    margin-right: 10px;
}

.state-btn {
    border: none;
    background: transparent;
    padding: 4px 10px;
    border-radius: 18px;
    font-size: 0.75rem;
    font-weight: 800;
    color: #94a3b8;
    cursor: pointer;
}

.state-btn.active {
    background: #3b82f6;
    color: #fff;
}

.state-btn.active.off {
    background: #64748b;
}

.quick-builder-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 15px 15px 25px 15px;
    display: flex;
    gap: 10px;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.08);
    z-index: 1000;
}

.btn-quick {
    flex: 1;
    padding: 15px;
    border-radius: 12px;
    border: none;
    font-weight: 800;
    font-size: 1.1rem;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-quick:active {
    transform: scale(0.96);
}

.btn-quick.action {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
}

.btn-quick.time {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.save-btn {
    background: #1e293b;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}

.save-btn:active {
    transform: scale(0.95);
    opacity: 0.8;
}

.scenario-manage-card {
    background: #fff;
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.7);
}

.card-header {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--stitch-text);
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.scenario-summary {
    font-size: 0.9rem;
    color: var(--stitch-gray);
    line-height: 1.5;
    padding-left: 10px;
    border-left: 3px solid #e2e8f0;
    margin-bottom: 15px;
}

.btn-advanced-edit {
    width: 100%;
    background: #f1f5f9;
    color: #3b82f6;
    border: 1px solid #e2e8f0;
    padding: 12px;
    border-radius: 12px;
    font-weight: 800;
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
}

.btn-advanced-edit:active {
    background: #e2e8f0;
    transform: scale(0.98);
}

.control-btn {
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid var(--stitch-border);
    box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    aspect-ratio: 1/1.05;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    transform: scale(0.96);
    opacity: 0.9;
}

/* 1-Second Hold Progress Bar */
.hold-bar-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.05);
    z-index: 4;
}

.hold-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 0%;
    height: 6px;
    background: #10b981;
    z-index: 5;
}

/* OFF State: Grayed Out Icon */
.control-btn .icon-svg {
    filter: grayscale(100%) opacity(0.5);
    transition: filter 0.3s;
}

.control-btn .btn-label {
    color: #94a3b8;
}

/* ON States: Pastel Tone Overrides */
.control-btn.active {
    border-color: rgba(0, 0, 0, 0.05);
    box-shadow: 0 8px 15px -5px rgba(0, 0, 0, 0.05);
}

/* Valve A & B (Mint Green) */
#btn-ch1.active,
#btn-ch2.active {
    background: var(--pastel-green);
    border-color: #86efac;
}

#btn-ch1.active .btn-label,
#btn-ch2.active .btn-label {
    color: #166534;
}

/* Pump (Peach Orange) */
#btn-ch3.active {
    background: var(--pastel-orange);
    border-color: #fdba74;
}

#btn-ch3.active .btn-label {
    color: #9a3412;
}

/* Light (Lemon Yellow) */
#btn-ch4.active {
    background: var(--pastel-yellow);
    border-color: #fde047;
}

#btn-ch4.active .btn-label {
    color: #854d0e;
}

/* Auto Mode (Purple Pastel) */
#btn-auto.active {
    background: var(--pastel-purple);
    border-color: #c084fc;
}

#btn-auto.active .btn-label {
    color: #7e22ce;
}

.control-btn.active .icon-svg {
    filter: none;
}

/* 5. Animations & Effects */
@keyframes pulse-glow {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 0.6;
    }
}

.pulse-target {
    opacity: 0;
    transition: opacity 0.3s;
}

.control-btn.active .pulse-target {
    animation: pulse-glow 2s ease-in-out infinite;
    transform-origin: center;
}

.pulse-active {
    animation: pulse-blue 2s infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spin-target {
    transform-origin: center;
    transition: transform 0.5s;
}

.control-btn.active .spin-target {
    animation: spin 3s linear infinite;
}

.control-btn.active .spin-fast {
    animation: spin 0.8s linear infinite;
}

@keyframes pulse-blue {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

/* Phase 171: Scenario Active Bar UI */
.scenario-active-bar {
    grid-column: span 2;
    background: #111827;
    color: #10b981;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: -4px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 5;
    flex: none;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    display: inline-block;
    animation: dot-pulse 1.5s infinite;
}

@keyframes dot-pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.btn-status {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-left: 4px;
    font-weight: 500;
}

.active .btn-status {
    opacity: 1;
    font-weight: 800;
}

/* 7. Scenario Dashboard Integration */
.scenario-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 15px;
    text-align: left;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}

.scenario-item:active {
    transform: scale(0.98);
    background: #f1f5f9;
}

.scenario-desc {
    font-size: 0.85rem;
    color: var(--stitch-gray);
}

.scenario-setup-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 5px;
    opacity: 0.6;
}

.config-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    border: 1px solid #e2e8f0;
}

.config-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: #334155;
}

.config-input-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.config-input {
    width: 60px;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    text-align: center;
    font-size: 1rem;
    font-weight: bold;
}

.btn-full {
    grid-column: span 2;
    aspect-ratio: auto;
    height: 56px;
    flex-direction: row;
    gap: 12px;
    padding: 0 20px;
    justify-content: center;
}

.btn-scenario {
    background: var(--pastel-blue);
    border: 1px solid #93c5fd;
}

.btn-scenario .btn-label {
    color: #1e40af !important;
    font-weight: 800;
}

/* 5. Modal & Popups (Refined for Consistency) */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-box {
    background: white;
    padding: 35px 25px;
    border-radius: 24px;
    text-align: center;
    width: 85%;
    max-width: 320px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--stitch-text);
    margin-bottom: 12px;
}

.modal-msg {
    color: var(--stitch-gray);
    margin-bottom: 30px;
    line-height: 1.6;
    font-size: 1.05rem;
    word-break: keep-all;
    font-weight: 500;
}

.modal-btn {
    border: none;
    padding: 15px;
    border-radius: 15px;
    width: 100%;
    font-weight: 800;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.modal-btn:active {
    transform: scale(0.97);
    opacity: 0.9;
}

.modal-btn.secondary {
    background: white;
    border: 2px solid #e2e8f0;
    color: var(--stitch-gray);
    box-shadow: none;
}

/* Theme Overrides */
.modal-box.success {
    border-top: none;
}

.modal-box.success .modal-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.modal-box.danger {
    border-top: none;
}

.modal-box.danger .modal-btn,
.modal-box.warning .modal-btn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes popIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}