:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #334155;
    --radius: 10px;
    --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; height: 100%; }
#app { min-height: 100vh; }

button, input, select, textarea {
    font: inherit; color: var(--text);
}

button {
    cursor: pointer; border: none; border-radius: var(--radius);
    padding: 10px 16px; background: var(--primary); color: #fff;
    transition: background 0.15s;
}
button:hover { background: var(--primary-hover); }
button.secondary { background: var(--surface-2); }
button.secondary:hover { background: #475569; }
button.danger { background: var(--danger); }
button.danger:hover { background: #dc2626; }
button.small { padding: 6px 10px; font-size: 13px; }

input, select, textarea {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }

.login-screen {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    padding: 20px;
}
.login-box {
    background: var(--surface); padding: 32px; border-radius: var(--radius);
    width: 100%; max-width: 360px; box-shadow: var(--shadow);
}
.login-box h1 { margin: 0 0 20px; font-size: 22px; }
.login-box input { margin-bottom: 12px; }
.login-box .error { color: var(--danger); margin-top: 10px; font-size: 14px; }

.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
    gap: 12px; flex-wrap: wrap;
}
.topbar .title { font-size: 18px; font-weight: 600; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-muted); }

.tabs {
    display: flex; gap: 4px; padding: 8px 12px 0; background: var(--bg);
    border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tab {
    padding: 10px 16px; background: transparent; color: var(--text-muted);
    border-radius: var(--radius) var(--radius) 0 0; white-space: nowrap;
}
.tab.active { background: var(--surface); color: var(--text); }

.toolbar {
    display: flex; gap: 10px; padding: 12px 16px; align-items: center; flex-wrap: wrap;
}
.toolbar input { max-width: 240px; }

.board {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px; padding: 0 16px 16px; overflow-y: auto; flex: 1;
}

.column {
    background: var(--surface); border-radius: var(--radius);
    display: flex; flex-direction: column; max-height: 100%;
}
.column-header {
    padding: 12px; font-weight: 600; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.column-count { background: var(--surface-2); padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.column-body {
    padding: 8px; overflow-y: auto; flex: 1; min-height: 120px;
}
.column-body.drag-over { background: #1e3a5f; }

.lead-card {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.lead-card:active { cursor: grabbing; }
.lead-card h4 { margin: 0 0 4px; font-size: 15px; }
.lead-card .meta { font-size: 12px; color: var(--text-muted); }
.lead-card .badges { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.badge {
    font-size: 11px; padding: 2px 6px; border-radius: 4px; background: var(--surface-2);
    color: var(--text-muted);
}
.badge.priority-VIP { background: #7f1d1d; color: #fecaca; }
.badge.priority-средний { background: #713f12; color: #fde68a; }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; z-index: 100;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow);
}
.modal-header {
    padding: 16px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px; }
.modal-footer {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

.form-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.form-grid.full { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; color: var(--text-muted); }

.history-item {
    font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.history-item time { color: var(--text-muted); font-size: 11px; }

.calendar-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
    padding: 16px;
}
.cal-day {
    background: var(--surface); min-height: 100px; border-radius: var(--radius);
    padding: 8px; font-size: 13px;
}
.cal-day .day-num { color: var(--text-muted); margin-bottom: 4px; }
.cal-event {
    background: var(--primary); color: #fff; padding: 2px 6px;
    border-radius: 4px; margin-bottom: 4px; font-size: 11px;
    cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.settings-nav {
    display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.settings-nav button { background: var(--surface-2); }
.settings-nav button.active { background: var(--primary); }
.settings-section { padding: 16px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-muted); font-weight: 500; font-size: 13px; }

.toast {
    position: fixed; bottom: 16px; right: 16px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 16px; box-shadow: var(--shadow); z-index: 200;
    animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 768px) {
    .board { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .toolbar input { max-width: 100%; }
    .topbar { flex-direction: column; align-items: flex-start; }
}
