/* Paalupiste CRM - Design System */
:root {
    --red: #CC3333;
    --red-dark: #a82a2a;
    --black: #1A1A1A;
    --dark-gray: #333333;
    --mid-gray: #767676;
    --light-gray: #E6E6E6;
    --bg-gray: #F5F5F5;
    --white: #FFFFFF;
    --green: #16a34a;
    --green-light: #dcfce7;
    --blue: #2563EB;
    --blue-light: #dbeafe;
    --yellow: #f59e0b;
    --yellow-light: #fef3c7;
    --purple: #8b5cf6;
    --sidebar-w: 240px;
    --header-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--black);
    background: var(--bg-gray);
    font-size: 14px;
    line-height: 1.5;
}

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--black);
    color: var(--white);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #333;
}

.sidebar-header img {
    height: 28px;
}

.sidebar-header .app-title {
    font-size: 13px;
    font-weight: 600;
    color: #ccc;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #aaa;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.sidebar-nav a:hover {
    background: #222;
    color: var(--white);
}

.sidebar-nav a.active {
    background: #222;
    color: var(--white);
    border-left: 3px solid var(--red);
    padding-left: 17px;
}

.sidebar-nav .nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.6;
}

.sidebar-nav a:hover .nav-icon,
.sidebar-nav a.active .nav-icon {
    opacity: 1;
}

.sidebar-nav .nav-divider {
    height: 1px;
    background: #333;
    margin: 8px 20px;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid #333;
    font-size: 12px;
    color: #666;
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

/* Header */
.page-header {
    background: var(--white);
    padding: 16px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--light-gray);
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--black);
}

.page-subtitle {
    font-size: 12px;
    color: var(--mid-gray);
    margin-top: 2px;
}

/* Content area */
.content {
    padding: 24px 28px;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--light-gray);
    margin-bottom: 20px;
}

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--mid-gray);
}

.card-body {
    padding: 20px;
}

/* Grid */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Stat cards */
.stat-card {
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--light-gray);
    padding: 20px;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--mid-gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--black);
    margin-top: 4px;
}

.stat-card .stat-sub {
    font-size: 12px;
    color: var(--mid-gray);
    margin-top: 2px;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--mid-gray);
    border-bottom: 2px solid var(--light-gray);
    white-space: nowrap;
}

td {
    padding: 10px 14px;
    border-bottom: 1px solid #f5f5f5;
    font-size: 13px;
}

tr:hover td {
    background: #fafafa;
}

td a {
    color: var(--black);
    text-decoration: none;
    font-weight: 600;
}

td a:hover {
    color: var(--red);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--red);
    color: var(--white);
    border-color: var(--red);
}
.btn-primary:hover { background: var(--red-dark); }

.btn-secondary {
    background: var(--white);
    color: var(--dark-gray);
    border-color: var(--light-gray);
}
.btn-secondary:hover { background: var(--bg-gray); }

.btn-success {
    background: var(--green);
    color: var(--white);
}
.btn-success:hover { background: #15803d; }

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-danger {
    background: var(--white);
    color: var(--red);
    border-color: var(--red);
}
.btn-danger:hover { background: #fef2f2; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}

.badge-draft { background: #f1f5f9; color: #64748b; }
.badge-sent { background: var(--blue-light); color: var(--blue); }
.badge-negotiation { background: var(--yellow-light); color: #b45309; }
.badge-accepted, .badge-confirmed { background: var(--green-light); color: var(--green); }
.badge-rejected, .badge-cancelled { background: #fef2f2; color: var(--red); }
.badge-expired { background: #f1f5f9; color: #94a3b8; }
.badge-in_production { background: #ede9fe; color: var(--purple); }
.badge-shipped, .badge-ready_to_ship { background: #ecfdf5; color: #059669; }
.badge-delivered { background: #f0fdfa; color: #0d9488; }
.badge-invoiced { background: #f8fafc; color: #475569; }
.badge-paid { background: var(--green-light); color: var(--green); }

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--dark-gray);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--light-gray);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--white);
    color: var(--black);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(204, 51, 51, 0.1);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* Flash messages */
.flash {
    padding: 12px 20px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
}

.flash-success {
    background: var(--green-light);
    color: var(--green);
    border: 1px solid #bbf7d0;
}

.flash-error {
    background: #fef2f2;
    color: var(--red);
    border: 1px solid #fecaca;
}

/* Search bar */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.search-bar input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid var(--light-gray);
    border-radius: 6px;
    font-size: 14px;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--red);
}

.search-bar select {
    padding: 8px 12px;
    border: 1px solid var(--light-gray);
    border-radius: 6px;
    font-size: 13px;
    background: var(--white);
}

/* Activity timeline */
.activity-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f5f5f5;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--mid-gray);
    margin-top: 6px;
    flex-shrink: 0;
}

.activity-dot.note { background: var(--blue); }
.activity-dot.call { background: var(--green); }
.activity-dot.email { background: var(--purple); }
.activity-dot.system { background: var(--mid-gray); }
.activity-dot.status_change { background: var(--yellow); }

.activity-content {
    flex: 1;
}

.activity-subject {
    font-weight: 600;
    font-size: 13px;
}

.activity-body {
    font-size: 13px;
    color: var(--mid-gray);
    margin-top: 2px;
}

.activity-time {
    font-size: 11px;
    color: #aaa;
    margin-top: 2px;
}

/* Pipeline kanban */
.kanban-board {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 16px;
}

.kanban-column {
    min-width: 260px;
    max-width: 300px;
    flex-shrink: 0;
}

.kanban-header {
    padding: 10px 14px;
    border-radius: 8px 8px 0 0;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kanban-header .count {
    background: rgba(255,255,255,0.2);
    padding: 1px 7px;
    border-radius: 8px;
    font-size: 11px;
}

.kanban-body {
    background: var(--bg-gray);
    border: 1px solid var(--light-gray);
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 8px;
    min-height: 100px;
}

.kanban-card {
    background: var(--white);
    border: 1px solid var(--light-gray);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.kanban-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.kanban-card .kc-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.kanban-card .kc-sub {
    font-size: 12px;
    color: var(--mid-gray);
}

.kanban-card .kc-amount {
    font-size: 14px;
    font-weight: 700;
    margin-top: 6px;
}

.kanban-card .kc-rot {
    font-size: 11px;
    margin-top: 4px;
    font-weight: 600;
}

.kanban-card.warning {
    border-left: 3px solid #f59e0b;
}
.kanban-card.warning .kc-rot {
    color: #f59e0b;
}

.kanban-card.rotting {
    border-left: 3px solid #ef4444;
    background: #fef2f2;
}
.kanban-card.rotting .kc-rot {
    color: #ef4444;
}

.kanban-card.dragging {
    opacity: 0.4;
    transform: rotate(2deg);
}

.kanban-body.drag-over {
    background: #e0f2fe;
    border-color: #3b82f6;
    border-style: dashed;
}

/* Login page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--black);
}

.login-card {
    background: var(--white);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo img {
    height: 40px;
}

.login-logo .login-subtitle {
    font-size: 12px;
    color: var(--mid-gray);
    margin-top: 8px;
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 600;
}

/* Mobile hamburger */
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--black);
    margin: 5px 0;
    transition: 0.3s;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--mid-gray);
}

.empty-state .empty-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 16px;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 20px;
    justify-content: center;
}

.pagination a,
.pagination span {
    padding: 6px 12px;
    border: 1px solid var(--light-gray);
    border-radius: 4px;
    font-size: 13px;
    text-decoration: none;
    color: var(--dark-gray);
}

.pagination a:hover { background: var(--bg-gray); }
.pagination .current {
    background: var(--red);
    color: var(--white);
    border-color: var(--red);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .hamburger {
        display: block;
    }

    .page-header {
        padding: 12px 16px;
    }

    .content {
        padding: 16px;
    }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .form-row, .form-row-3 {
        grid-template-columns: 1fr;
    }

    .kanban-board {
        flex-direction: column;
    }

    .kanban-column {
        min-width: 100%;
        max-width: 100%;
    }

    .search-bar {
        flex-direction: column;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .page-title { font-size: 16px; }
    .card-body { padding: 14px; }
    td, th { padding: 8px 10px; }
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* Utility */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--mid-gray); }
.text-sm { font-size: 12px; }
.text-red { color: var(--red); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* Calculator table */
.calc-table {
    width: 100%;
    border-collapse: collapse;
}

.calc-table td {
    padding: 6px 14px;
    font-size: 13px;
    border-bottom: 1px solid #eee;
}

.calc-table .calc-section td {
    background: var(--bg-gray);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--mid-gray);
    padding: 8px 14px 6px;
    border-bottom: none;
}

.calc-table .calc-total-cost td {
    background: #f8f8f8;
    font-weight: 600;
    border-top: 2px solid #ddd;
}

.calc-table .calc-margin td {
    color: var(--mid-gray);
    font-style: italic;
}

.calc-table .calc-total td {
    background: var(--black);
    color: var(--white);
    font-weight: 700;
    font-size: 15px;
    padding: 10px 14px;
}

/* Summary lines */
.summary-line {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.summary-line:last-child {
    border-bottom: none;
}

/* Checkbox label */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--red);
}

/* Remove button (icon-only) */
.btn-icon {
    background: none;
    border: none;
    color: var(--mid-gray);
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.btn-icon:hover {
    background: #fee;
    color: var(--red);
}
