/* =============================================
   CRM Greenolia — Light theme (shadcn-inspired)
   ============================================= */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* === Variables === */
:root {
    --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;

    --bg: #ffffff;
    --bg-muted: #f8faf9;
    --bg-subtle: #f1f5f3;
    --bg-sidebar: #fafcfb;
    --bg-input: #ffffff;
    --bg-hover: #f1f5f3;

    --fg: #0a1f12;
    --fg-muted: #5f7068;
    --fg-subtle: #8a9b91;

    --border: #dfe7e2;
    --border-hover: #c4d0c8;
    --ring: rgba(22, 101, 52, 0.2);

    --primary: #16a34a;
    --primary-fg: #ffffff;
    --primary-hover: #15803d;
    --primary-muted: rgba(22, 163, 74, 0.08);
    --primary-light: #dcfce7;

    --green: #16a34a;
    --green-bg: #dcfce7;
    --orange: #ea580c;
    --orange-bg: #fff7ed;
    --red: #dc2626;
    --red-bg: #fef2f2;
    --blue: #2563eb;
    --blue-bg: #eff6ff;
    --violet: #7c3aed;
    --violet-bg: #f5f3ff;
    --amber: #d97706;
    --amber-bg: #fffbeb;
    --slate: #64748b;
    --slate-bg: #f1f5f9;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --sidebar-w: 240px;

    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
    font-family: var(--font-sans);
    background: var(--bg-muted);
    color: var(--fg);
    min-height: 100vh;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }
::selection { background: var(--primary-light); color: var(--fg); }

/* === Sidebar === */
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 100;
    transition: transform 0.25s ease;
}
.sidebar-header {
    padding: 1.5rem 1.25rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.025em;
}
.sidebar-header h2::before {
    content: '●';
    margin-right: 0.4rem;
    font-size: 0.6rem;
    vertical-align: middle;
    color: var(--green);
}
.sidebar-close {
    display: none; background: none; border: none;
    color: var(--fg-muted); font-size: 1.25rem;
    position: absolute; top: 1.25rem; right: 1rem;
    cursor: pointer; border-radius: var(--radius);
    width: 2rem; height: 2rem;
    display: none; align-items: center; justify-content: center;
    transition: background var(--transition);
}
.sidebar-close:hover { background: var(--bg-hover); }
.sidebar-nav {
    list-style: none; flex: 1;
    padding: 0.5rem 0.75rem;
}
.sidebar-nav li a {
    display: flex; align-items: center; gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    color: var(--fg-muted);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius);
    transition: all var(--transition);
    margin-bottom: 0.125rem;
}
.sidebar-nav li a:hover {
    background: var(--bg-hover);
    color: var(--fg);
    text-decoration: none;
}
.sidebar-nav li a.active {
    background: var(--primary-muted);
    color: var(--primary);
    font-weight: 600;
}
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg-muted);
}
.sidebar-user {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--fg);
    margin-bottom: 0.125rem;
}
.sidebar-logout {
    color: var(--fg-subtle);
    font-size: 0.8rem;
    transition: color var(--transition);
}
.sidebar-logout:hover { color: var(--red); }

/* === Main content === */
.main-content {
    margin-left: var(--sidebar-w);
    padding: 2rem 2.5rem;
    min-height: 100vh;
    max-width: 1400px;
}
.hamburger {
    display: none; background: none; border: 1px solid var(--border);
    color: var(--fg-muted); font-size: 1.25rem; cursor: pointer;
    margin-bottom: 1rem; border-radius: var(--radius);
    width: 2.5rem; height: 2.5rem;
    align-items: center; justify-content: center;
    transition: all var(--transition);
}
.hamburger:hover { background: var(--bg-hover); border-color: var(--border-hover); }

/* === Page header === */
.page-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap; gap: 0.75rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--fg);
}

/* === Cards === */
.card {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* === KPI grid === */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.kpi-card {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow); }
.kpi-card-warning { border-color: var(--orange); border-left: 3px solid var(--orange); }
.kpi-value {
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--fg);
    letter-spacing: -0.03em;
    line-height: 1.2;
}
.kpi-card-warning .kpi-value { color: var(--orange); }
.kpi-label {
    color: var(--fg-subtle);
    margin-top: 0.25rem;
    font-size: 0.8rem;
    font-weight: 500;
}

/* === Pipeline === */
.pipeline-columns {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}
.pipeline-column {
    flex: 1;
    min-width: 0;
    background: var(--bg-subtle);
    border-radius: var(--radius-lg);
    padding: 0.75rem;
}
.pipeline-column-header {
    padding: 0.625rem 0.75rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--fg-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.pipeline-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 3rem;
}

/* === Pipeline card === */
.pipeline-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}
.pipeline-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow), 0 0 0 1px var(--primary);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.375rem;
}
.card-name { font-weight: 600; font-size: 0.9rem; color: var(--fg); }
.card-phone { margin-bottom: 0.25rem; }
.card-phone a { color: var(--primary); font-size: 0.85rem; font-family: var(--font-mono); font-weight: 400; }
.card-details { color: var(--fg-subtle); font-size: 0.8rem; }
.card-meta { display: flex; gap: 0.375rem; flex-wrap: wrap; margin: 0.5rem 0 0; }
.card-actions {
    display: flex; gap: 0.375rem;
    align-items: center; margin-top: 0.625rem;
    padding-top: 0.625rem;
    border-top: 1px solid var(--border);
}

/* === Pastilles aging === */
.pastille {
    width: 9px; height: 9px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 0 2px var(--bg);
}
.aging-green { background: var(--green); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--green-bg); }
.aging-orange { background: var(--orange); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--orange-bg); }
.aging-red { background: var(--red); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--red-bg); }

/* === Badges === */
.badge {
    display: inline-flex; align-items: center;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-violet { background: var(--violet-bg); color: var(--violet); }
.badge-grey { background: var(--slate-bg); color: var(--slate); }
.badge-gold { background: var(--amber-bg); color: var(--amber); }
.badge-attempts { background: var(--slate-bg); color: var(--slate); }
.badge-callback { background: var(--blue-bg); color: var(--blue); font-size: 0.7rem; }

/* === Table === */
.table-container {
    overflow-x: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.leads-table { width: 100%; border-collapse: collapse; }
.leads-table th, .leads-table td {
    padding: 0.625rem 0.875rem;
    text-align: left;
}
.leads-table th {
    color: var(--fg-subtle);
    font-weight: 600;
    font-size: 0.775rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    background: var(--bg-muted);
    transition: color var(--transition);
}
.leads-table th:hover { color: var(--primary); }
.leads-table th.sorted-asc::after { content: ' ↑'; color: var(--primary); }
.leads-table th.sorted-desc::after { content: ' ↓'; color: var(--primary); }
.leads-table td {
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.leads-table tbody tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; transition: background var(--transition); }
.clickable-row:hover { background: var(--bg-muted); }

/* === Filters bar === */
.filters-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}
.input-search { flex: 1; min-width: 220px; }

/* === Forms === */
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="number"], select, textarea {
    background: var(--bg-input);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    width: auto;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--fg-subtle); }
.input-full { width: 100%; }
.form-group { margin-bottom: 0.875rem; }
.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--fg-muted);
}
.form-inline { display: flex; gap: 0.5rem; align-items: center; }
textarea { resize: vertical; min-height: 80px; }
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%235f7068' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.25rem 1.25rem;
    padding-right: 2.25rem;
}

/* === Buttons === */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--fg);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    gap: 0.375rem;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}
.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    text-decoration: none;
    color: var(--fg);
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.775rem; }
.btn-primary {
    background: var(--primary);
    color: var(--primary-fg);
    border-color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--primary-fg);
}
.btn-success {
    background: var(--green-bg);
    color: var(--green);
    border-color: transparent;
}
.btn-success:hover {
    background: var(--primary-light);
    border-color: var(--green);
}
.btn-block { width: 100%; }
.btn.active {
    background: var(--primary);
    color: var(--primary-fg);
    border-color: var(--primary);
}

/* === Status select (pipeline) === */
.status-select {
    padding: 0.275rem 2rem 0.275rem 0.5rem;
    font-size: 0.775rem;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%235f7068' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.35rem center;
    background-repeat: no-repeat;
    background-size: 1rem 1rem;
}

/* === Period filter === */
.period-filter { display: flex; gap: 0.25rem; }
.period-filter .btn {
    border-radius: var(--radius);
    font-size: 0.775rem;
    padding: 0.3rem 0.75rem;
}

/* === Lead detail === */
.lead-detail {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.25rem;
}
.lead-left, .lead-right { min-width: 0; }
.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem 1.25rem;
    align-items: baseline;
}
.info-label {
    color: var(--fg-subtle);
    font-size: 0.8rem;
    font-weight: 500;
}
.info-value {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--fg);
}
.attempts-list, .history-list { margin-top: 0.5rem; }
.attempt-item, .history-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    display: flex;
    gap: 0.625rem;
    flex-wrap: wrap;
    align-items: baseline;
}
.attempt-item:last-child, .history-item:last-child { border-bottom: none; }
.attempt-date, .history-date { color: var(--fg-subtle); font-family: var(--font-mono); font-size: 0.75rem; }
.attempt-user, .history-user { font-weight: 600; color: var(--fg); }
.attempt-note { color: var(--fg-muted); font-style: italic; }
.history-field {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    background: var(--primary-muted);
    border-radius: 4px;
}
.history-old { color: var(--red); text-decoration: line-through; opacity: 0.7; }
.history-new { color: var(--green); font-weight: 600; }
.text-muted { color: var(--fg-subtle); }

/* === Flash messages === */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    animation: flashIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.flash-success {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid #bbf7d0;
}
.flash-error {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #fecaca;
}
.flash-warning {
    background: var(--orange-bg);
    color: var(--orange);
    border: 1px solid #fed7aa;
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Pagination === */
.pagination {
    display: flex;
    gap: 0.25rem;
    margin-top: 1rem;
    justify-content: center;
}
.pagination .btn { min-width: 2rem; }

/* === Login page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--bg-muted) 0%, #ecfdf5 50%, var(--bg-muted) 100%);
}
.login-card {
    background: var(--bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}
.login-card h1 {
    text-align: center;
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 0.25rem;
}
.login-card h1::before {
    content: '●';
    margin-right: 0.4rem;
    font-size: 0.6rem;
    vertical-align: middle;
}
.login-subtitle {
    text-align: center;
    color: var(--fg-subtle);
    margin-bottom: 1.75rem;
    font-size: 0.9rem;
}
.login-card .form-group input {
    width: 100%;
}
.login-card .btn-block {
    margin-top: 0.5rem;
    padding: 0.625rem 1rem;
}

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--fg-subtle);
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-close { display: flex; }
    .main-content { margin-left: 0; padding: 1.25rem; }
    .hamburger { display: flex; }
    .pipeline-columns { flex-direction: column; }
    .lead-detail { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .filters-bar { flex-direction: column; }
    .input-search { min-width: unset; width: 100%; }
    .page-header h1 { font-size: 1.25rem; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .login-card { margin: 1rem; padding: 1.75rem; }
}
