:root {
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Light Mode Palette */
    --bg: #f9f9fb;
    --card-bg: #ffffff;
    --border: #e4e4e7;
    --text-primary: #18181b;
    --text-secondary: #71717a;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #ca8a04;
    --danger: #dc2626;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark Mode Palette */
        --bg: #09090b;
        --card-bg: #18181b;
        --border: #27272a;
        --text-primary: #f4f4f5;
        --text-secondary: #a1a1aa;
        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --success: #22c55e;
        --warning: #eab308;
        --danger: #ef4444;
        --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
    }
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Layout Shell */
header {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

header nav a {
    color: var(--text-secondary);
    margin-left: 1.5rem;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.1s ease;
}

header nav a:hover, header nav a.active {
    color: var(--text-primary);
    text-decoration: none;
}

main.container {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Grid & Layout Utilities */
.grid-2 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

/* Pipeline create form + stats row */
.pipeline-form-row {
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
}

.pipeline-create-form {
    flex: 1;
    min-width: 0;
}

/* Pipeline stats — superseded by .pipeline-stats-compact */
.pipeline-stats {
    display: none;
}

@media (max-width: 900px) {
    .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
}

/* Cards & Containers */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    letter-spacing: -0.015em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Typography elements */
h2, h3, h4 {
    letter-spacing: -0.02em;
    font-weight: 600;
}

h2 { font-size: 1.75rem; margin-bottom: 1rem; }
h3 { font-size: 1.25rem; margin-bottom: 0.75rem; }

/* Kanban Pipeline - Desktop */
.pipeline-container {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    min-height: 70vh;
    position: relative;
}

/* Edge-scroll visual feedback */
.pipeline-container::before,
.pipeline-container::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 48px;
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.pipeline-container::before {
    left: 0;
    background: linear-gradient(to right, var(--accent), transparent);
}
.pipeline-container::after {
    right: 0;
    background: linear-gradient(to left, var(--accent), transparent);
}
.pipeline-container.edge-left::before { opacity: 0.25; }
.pipeline-container.edge-right::after  { opacity: 0.25; }

/* Mobile step edge feedback */
.pipeline-steps {
    position: relative;
}
.pipeline-steps.edge-left::before,
.pipeline-steps.edge-right::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 24px;
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.pipeline-steps.edge-left::before {
    left: 0;
    background: linear-gradient(to right, var(--accent), transparent);
}
.pipeline-steps.edge-right::after {
    right: 0;
    background: linear-gradient(to left, var(--accent), transparent);
}
.pipeline-steps.edge-left::before { opacity: 0.3; }
.pipeline-steps.edge-right::after  { opacity: 0.3; }

.pipeline-column {
    flex: 1;
    min-width: 250px;
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
}

/* Pipeline mobile: stepped navigation */
@media (max-width: 768px) {
    .pipeline-container {
        display: block;
        overflow-x: visible;
        min-height: auto;
    }

    .pipeline-column {
        display: none;
        min-width: 100%;
        margin-bottom: 1rem;
    }

    .pipeline-column.active {
        display: flex;
    }

    /* Smooth slide transition for step navigation */
    .pipeline-column.pipeline-enter {
        display: flex;
        opacity: 0;
        transform: translateX(40px);
    }
    .pipeline-column.pipeline-enter-active {
        opacity: 1;
        transform: translateX(0);
        transition: opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1),
                    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    }
    .pipeline-column.pipeline-exit {
        display: flex;
        opacity: 1;
        transform: translateX(0);
    }
    .pipeline-column.pipeline-exit-active {
        opacity: 0;
        transform: translateX(-40px);
        transition: opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1),
                    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .pipeline-column-header {
        cursor: pointer;
        position: sticky;
        top: 0;
        z-index: 5;
        background-color: var(--card-bg);
    }

    /* Step indicator */
    .pipeline-steps {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        padding: 0.5rem 0;
        margin-bottom: 1rem;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    .pipeline-step {
        flex: 0 0 auto;
        padding: 0.5rem 1rem;
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 20px;
        font-size: 0.8rem;
        font-weight: 500;
        white-space: nowrap;
        cursor: pointer;
        transition: all 0.2s ease;
        scroll-snap-align: center;
    }

    .pipeline-step.active {
        background: var(--accent);
        color: white;
        border-color: var(--accent);
    }

    .pipeline-step .count {
        display: inline-block;
        margin-left: 0.25rem;
        padding: 0.1rem 0.4rem;
        background: rgba(0, 0, 0, 0.1);
        border-radius: 10px;
        font-size: 0.7rem;
    }

    .pipeline-step.active .count {
        background: rgba(255, 255, 255, 0.2);
    }
}

.pipeline-column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.25rem 1rem 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
}

.pipeline-column-title {
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.pipeline-column-count {
    background-color: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-weight: 600;
}

.pipeline-cards {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 50vh;
}

.deal-card {
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.85rem;
    cursor: pointer;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
    transition: transform 0.1s ease, border-color 0.1s ease;
}

.deal-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.deal-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.deal-card-company {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.deal-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.deal-card-value {
    font-weight: 600;
    font-size: 0.85rem;
}

/* Drag handle — mobile only */
.deal-card-grip {
    display: none;
}

/* Prevent text selection on the card body (iOS Safari) */
.deal-card {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.deal-card-body {
    -webkit-user-select: text;
    user-select: text;
}

/* Drag & Drop */
.deal-card-grip[draggable="true"] {
    cursor: grab;
}

.deal-card-grip[draggable="true"]:active {
    cursor: grabbing;
}

.deal-card.dragging {
    opacity: 0.4;
    transform: scale(0.97);
    border-style: dashed;
}

/* Mobile: show grip handle */
@media (max-width: 768px) {
    .deal-card {
        position: relative;
        padding-right: 28px; /* tilaa kahvalle */
    }

    .deal-card-grip {
        display: flex;
        position: absolute;
        top: 6px;
        right: 6px;
        width: 20px;
        height: 20px;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        color: var(--text-secondary);
        background-color: rgba(0, 0, 0, 0.04);
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
        z-index: 2;
    }

    .deal-card-grip svg {
        width: 10px;
        height: 10px;
        opacity: 0.5;
    }

    .deal-card-grip[draggable="true"]:active {
        background-color: var(--accent);
        color: #fff;
    }

    .deal-card-grip[draggable="true"]:active svg {
        opacity: 1;
    }
}

.pipeline-cards.drag-over {
    background-color: rgba(37, 99, 235, 0.06);
    border: 2px dashed var(--accent);
    border-radius: 6px;
}


/* Badges & Scores */
.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    text-transform: capitalize;
}

.badge-blue { background-color: rgba(37, 99, 235, 0.1); color: var(--accent); }
.badge-green { background-color: rgba(22, 163, 74, 0.1); color: var(--success); }
.badge-yellow { background-color: rgba(202, 138, 4, 0.1); color: var(--warning); }
.badge-red { background-color: rgba(220, 38, 38, 0.1); color: var(--danger); }

.score-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    background-color: var(--bg);
    border: 2px solid var(--border);
}

.score-high { border-color: var(--success); color: var(--success); }
.score-medium { border-color: var(--warning); color: var(--warning); }
.score-low { border-color: var(--border); color: var(--text-secondary); }

/* Forms & Inputs */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}

input, select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    background-color: var(--card-bg);
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    margin-bottom: 1rem;
    outline: none;
    transition: border-color 0.1s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

button, .btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    background-color: var(--accent);
    color: #ffffff;
    transition: background-color 0.1s ease;
    text-align: center;
}

button:hover, .btn:hover {
    background-color: var(--accent-hover);
    text-decoration: none;
}

.btn-secondary {
    background-color: var(--bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: var(--border);
}

.btn-danger {
    background-color: var(--danger);
}

.btn-danger:hover {
    background-color: #b91c1c;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Timeline & Feed */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-top: 1rem;
    position: relative;
    padding-left: 1.25rem;
}

.timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 4px;
    width: 2px;
    background-color: var(--border);
}

.timeline-item {
    position: relative;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.25rem;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--accent);
    border: 2px solid var(--card-bg);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.timeline-content {
    font-size: 0.9rem;
    background-color: var(--bg);
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Table Design */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background-color: var(--bg);
}

tr:hover td {
    background-color: rgba(0, 0, 0, 0.01);
}

@media (prefers-color-scheme: dark) {
    tr:hover td {
        background-color: rgba(255, 255, 255, 0.01);
    }
}

/* Pipeline stats compact badges */
.pipeline-stats-compact {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    flex-wrap: wrap;
}

.pipe-stats-compact .stat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    border-radius: 10px;
    padding: 0 0.4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    transition: background 0.2s, border-color 0.2s;
}

.pipeline-stats-compact .stat-badge.stat-total {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    margin-left: 0.2rem;
}

@media (max-width: 900px) {
    .card-title {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .pipeline-stats-compact {
        width: 100%;
        justify-content: flex-start;
    }
}
