/* =============================================
   Habit Stack Builder — style.css
   Warm motivating aesthetic, purple primary
   ============================================= */

:root {
    --bg: #f5f3ff;
    --surface: #ffffff;
    --surface-2: #f0ebff;
    --border: #e2d5ff;
    --text: #1e1b4b;
    --muted: #7c6fa0;
    --primary: #7c3aed;
    --primary-h: #9256f0;
    --pass: #16a34a;
    --gold: #d97706;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(124, 58, 237, 0.08);
    --header-h: 52px;
}

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

html {
    font-size: 14px;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ── */
.site-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.07);
}

.header-inner {
    height: 100%;
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--primary);
    white-space: nowrap;
    flex-shrink: 0;
}

.logo-icon {
    font-size: 1.2rem;
}

.nav-tabs {
    display: flex;
    gap: 3px;
    flex: 1;
    justify-content: center;
}

.tab {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    font-family: inherit;
    font-size: 0.79rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.18s;
}

.tab.active,
.tab:hover {
    background: rgba(124, 58, 237, 0.09);
    color: var(--primary);
    border-color: rgba(124, 58, 237, 0.18);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.stack-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    font-family: inherit;
    font-size: 0.79rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.18s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-h);
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.35);
}

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    border: none;
    color: var(--muted);
}

.btn-ghost:hover {
    color: var(--text);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.76rem;
}

.btn-xs {
    padding: 3px 8px;
    font-size: 0.72rem;
}

/* ── Tab Panels ── */
.tab-panel {
    display: none;
    flex: 1;
    overflow: hidden;
}

.tab-panel.active {
    display: flex;
    flex-direction: column;
}

/* ── Builder Layout ── */
.builder-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 0;
    overflow: hidden;
}

/* ── Chain Panel ── */
.chain-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.chain-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.panel-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.stat-badge {
    font-size: 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 3px 10px;
    color: var(--primary);
    font-weight: 600;
}

.chain-list {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chain-footer {
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── Habit Card ── */
.habit-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    transition: all 0.2s;
    position: relative;
}

.habit-card:not(:last-child)::after {
    content: '↓';
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--border);
    font-size: 1rem;
    z-index: 1;
}

.habit-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.habit-icon {
    font-size: 1.5rem;
    width: 36px;
    text-align: center;
}

.habit-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.habit-trigger {
    font-size: 0.68rem;
    color: var(--muted);
    font-style: italic;
}

.habit-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.habit-time-tag {
    font-size: 0.68rem;
    color: var(--muted);
}

.habit-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.18s;
}

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

/* ── Flowchart Panel ── */
.flowchart-panel {
    background: var(--surface-2);
    overflow-y: auto;
    padding: 14px;
}

.flowchart-svg {
    width: 100%;
    min-height: 200px;
}

/* ── Check-in ── */
.checkin-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
    gap: 16px;
}

.checkin-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkin-title {
    font-size: 1.1rem;
    font-weight: 800;
}

.checkin-date {
    font-size: 0.8rem;
    color: var(--muted);
}

.checkin-progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkin-progress-bar {
    flex: 1;
    height: 8px;
    background: var(--surface-2);
    border-radius: 4px;
    overflow: hidden;
}

.checkin-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #10b981);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.checkin-pct {
    font-size: 0.76rem;
    color: var(--muted);
    white-space: nowrap;
}

.checkin-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkin-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.22s;
}

.checkin-item.done {
    border-color: var(--pass);
    background: rgba(22, 163, 74, 0.06);
}

.checkin-item.done .checkin-item-name {
    text-decoration: line-through;
    opacity: 0.6;
}

.checkin-check {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    transition: all 0.22s;
}

.checkin-item.done .checkin-check {
    background: var(--pass);
    border-color: var(--pass);
    color: white;
}

.checkin-item-icon {
    font-size: 1.2rem;
}

.checkin-item-body {
    flex: 1;
}

.checkin-item-trigger {
    font-size: 0.68rem;
    color: var(--muted);
    font-style: italic;
}

.checkin-item-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.checkin-item-time {
    font-size: 0.68rem;
    color: var(--muted);
}

.checkin-complete {
    text-align: center;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.complete-icon {
    font-size: 3.5rem;
    animation: bounce 0.5s ease;
}

@keyframes bounce {

    0%,
    100% {
        transform: scale(1)
    }

    50% {
        transform: scale(1.3)
    }
}

.checkin-complete h3 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--pass);
}

.checkin-complete p {
    font-size: 0.85rem;
    color: var(--muted);
}

/* ── Heatmap & Streaks ── */
.heatmap-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
}

.heatmap-title {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 16px;
}

.heatmap-grid {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.heatmap-day {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.heatmap-label {
    font-size: 0.62rem;
    color: var(--muted);
    text-align: center;
    width: 30px;
}

.heatmap-cell {
    width: 30px;
    height: 30px;
    border-radius: 5px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: var(--muted);
    font-weight: 600;
    cursor: default;
}

.heatmap-cell.done {
    background: rgba(22, 163, 74, 0.18);
    border-color: rgba(22, 163, 74, 0.3);
    color: var(--pass);
}

.habit-streaks {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.streak-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.streak-icon {
    font-size: 1.2rem;
}

.streak-name {
    flex: 1;
    font-size: 0.82rem;
    font-weight: 600;
}

.streak-badge {
    font-size: 0.72rem;
    font-weight: 700;
    background: rgba(217, 119, 6, 0.12);
    color: var(--gold);
    border: 1px solid rgba(217, 119, 6, 0.2);
    border-radius: 10px;
    padding: 2px 8px;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(30, 27, 75, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 380px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 8px 32px rgba(124, 58, 237, 0.15);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 0.92rem;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field-group label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.field-group input,
.field-group textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-family: inherit;
    font-size: 0.82rem;
    color: var(--text);
    outline: none;
    transition: border-color 0.18s;
}

.field-group input:focus {
    border-color: var(--primary);
}

.icon-input {
    font-size: 1.2rem;
    width: 60px;
    text-align: center;
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 18px;
    right: 18px;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-size: 0.8rem;
    z-index: 999;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.25s;
    pointer-events: none;
    max-width: 260px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* ── Responsive ── */
@media (max-width: 760px) {
    .builder-layout {
        grid-template-columns: 1fr;
    }

    .flowchart-panel {
        display: none;
    }
}