/* CostPilot — Mobile-first ERP stylesheet */

:root {
    --color-primary: #4a6fa5;
    --color-primary-dark: #3b5d8a;
    --color-bg: #f0f2f5;
    --color-surface: #fff;
    --color-text: #1a1a2e;
    --color-text-muted: #555;
    --color-text-light: #888;
    --color-border: #e0e0e0;
    --color-success: #28a745;
    --color-success-bg: #d4edda;
    --color-success-text: #155724;
    --color-warning: #ffc107;
    --color-warning-bg: #fff3cd;
    --color-warning-text: #856404;
    --color-danger: #dc3545;
    --color-danger-bg: #f8d7da;
    --color-danger-text: #721c24;
    --color-info-bg: #d1ecf1;
    --color-info-text: #0c5460;
    --color-muted-bg: #e2e3e5;
    --color-muted-text: #383d41;
    --radius: 8px;
    --shadow: 0 1px 4px rgba(0,0,0,0.08);
    --sidebar-width: 220px;
    --header-height: 56px;
    --bottom-bar-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.875rem;
    line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Header ===== */
.app-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: var(--header-height);
    background: var(--color-text);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
}
.app-header .logo { font-size: 1.1rem; font-weight: 700; color: #fff; text-decoration: none; white-space: nowrap; }
.app-header .tenant-info { font-size: 0.8rem; color: rgba(255,255,255,0.7); margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.app-header .role-badge { background: var(--color-primary); padding: 0.15rem 0.5rem; border-radius: 3px; font-size: 0.7rem; }
.app-header .logout-link { color: rgba(255,255,255,0.8); font-size: 0.8rem; margin-left: 0.5rem; }
.app-header .logout-link:hover { color: #fff; text-decoration: none; }
.app-header .menu-toggle { display: none; background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; padding: 0.25rem; }

/* ===== Sidebar ===== */
.sidebar {
    position: fixed; top: var(--header-height); left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    z-index: 90;
    padding: 0.5rem 0;
}
.sidebar a {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background 0.15s;
}
.sidebar a:hover { background: var(--color-bg); text-decoration: none; }
.sidebar a.active { background: #e8eef6; color: var(--color-primary); font-weight: 600; }
.sidebar .nav-section { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-light); padding: 0.75rem 1rem 0.25rem; font-weight: 600; }
.sidebar .nav-icon { width: 1.25rem; text-align: center; }

/* ===== Main content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    padding: 1.25rem;
    min-height: calc(100vh - var(--header-height));
}

/* ===== Bottom tab bar (mobile) ===== */
.bottom-bar {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    height: var(--bottom-bar-height);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    justify-content: space-around;
    align-items: center;
}
.bottom-bar a {
    display: flex; flex-direction: column; align-items: center;
    font-size: 0.65rem; color: var(--color-text-muted); text-decoration: none;
    padding: 0.25rem;
}
.bottom-bar a .tab-icon { font-size: 1.25rem; margin-bottom: 0.1rem; }
.bottom-bar a.active { color: var(--color-primary); font-weight: 600; }

/* ===== Page title ===== */
.page-title { font-size: 1.25rem; color: var(--color-text); margin-bottom: 1rem; }

/* ===== Card ===== */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card h2 { font-size: 1.1rem; margin-bottom: 0.75rem; color: var(--color-text); }

/* ===== Summary cards grid ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.kpi-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    text-align: center;
}
.kpi-card .kpi-label { font-size: 0.75rem; color: var(--color-text-light); margin-bottom: 0.25rem; }
.kpi-card .kpi-value { font-size: 1.25rem; font-weight: 700; color: var(--color-text); }

/* ===== Detail grid ===== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; }
.detail-item label { font-size: 0.75rem; color: var(--color-text-light); display: block; }
.detail-item span { font-size: 0.95rem; color: var(--color-text); }

/* ===== Buttons ===== */
.btn {
    display: inline-block; padding: 0.5rem 1rem;
    background: var(--color-primary); color: #fff;
    text-decoration: none; border-radius: 4px;
    font-size: 0.875rem; border: none; cursor: pointer;
    line-height: 1.4;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; color: #fff; }
.btn-back { background: #6c757d; }
.btn-back:hover { background: #5a6268; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-success { background: var(--color-success); }
.btn-success:hover { background: #218838; }
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: #c82333; }
.btn-warning { background: var(--color-warning); color: #333; }
.btn-warning:hover { background: #e0a800; }
.btn-export { background: var(--color-success); }
.btn-export:hover { background: #218838; }
.actions { margin-bottom: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ===== Filters ===== */
.filters {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: flex-end;
    box-shadow: var(--shadow);
}
.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label { font-size: 0.75rem; font-weight: 500; color: var(--color-text-muted); }
.filter-group input, .filter-group select {
    padding: 0.4rem 0.5rem; border: 1px solid #ccc; border-radius: 4px; font-size: 0.875rem;
}
.filter-toggle { display: none; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 0.6rem; text-align: left; border-bottom: 1px solid #eee; font-size: 0.8rem; }
th { background: #f8f9fa; font-weight: 600; color: var(--color-text-muted); position: sticky; top: 0; z-index: 1; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { background: #e9ecef; }
th .sort-arrow { font-size: 0.7rem; margin-left: 0.25rem; }
.total-row td { font-weight: 700; border-top: 2px solid #ccc; }
.total-ok { color: var(--color-success-text); }
.total-bad { color: var(--color-danger); }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 3px; font-size: 0.7rem; font-weight: 500; }
.badge-active { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-closed { background: var(--color-muted-bg); color: var(--color-muted-text); }
.badge-paid { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-pending { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-rejected { background: var(--color-danger-bg); color: var(--color-danger-text); }
.badge-manual { background: var(--color-info-bg); color: var(--color-info-text); }
.badge-generated { background: var(--color-muted-bg); color: var(--color-muted-text); }

/* ===== Forms ===== */
.form-card { max-width: 600px; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.85rem; color: var(--color-text); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 0.5rem 0.625rem; border: 1px solid #ccc; border-radius: 4px; font-size: 0.875rem;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(74,111,165,0.2);
}
.form-group .helptext { font-size: 0.75rem; color: var(--color-text-light); margin-top: 0.25rem; }
.form-group .errorlist { list-style: none; color: var(--color-danger); font-size: 0.8rem; margin-top: 0.25rem; }

/* ===== Inline form ===== */
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid #eee; }
.inline-form .fg { display: flex; flex-direction: column; gap: 0.2rem; }
.inline-form label { font-size: 0.75rem; color: var(--color-text-muted); }
.inline-form input, .inline-form select { padding: 0.4rem 0.5rem; border: 1px solid #ccc; border-radius: 4px; font-size: 0.875rem; }

/* ===== Profit colors ===== */
.profit-positive { color: var(--color-success-text); }
.profit-negative { color: var(--color-danger); }

/* ===== Pagination ===== */
.pagination { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }
.pagination a, .pagination span { display: inline-block; padding: 0.4rem 0.75rem; border-radius: 4px; font-size: 0.875rem; text-decoration: none; }
.pagination a { background: var(--color-surface); color: var(--color-primary); border: 1px solid #ddd; }
.pagination a:hover { background: #e9ecef; text-decoration: none; }
.pagination .current { background: var(--color-primary); color: #fff; border: 1px solid var(--color-primary); }

/* ===== Toast messages ===== */
.messages { list-style: none; margin-bottom: 1rem; }
.messages li { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 0.5rem; font-size: 0.875rem; display: flex; justify-content: space-between; align-items: center; }
.messages .success { background: var(--color-success-bg); color: var(--color-success-text); }
.messages .error { background: var(--color-danger-bg); color: var(--color-danger-text); }
.messages .warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.messages .info { background: var(--color-info-bg); color: var(--color-info-text); }
.messages .dismiss { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: inherit; opacity: 0.6; }
.messages .dismiss:hover { opacity: 1; }

/* ===== Empty state ===== */
.empty { text-align: center; padding: 2rem; color: var(--color-text-light); }

/* ===== Totals bar ===== */
.totals-bar { background: var(--color-surface); border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 0.5rem; box-shadow: var(--shadow); display: flex; gap: 2rem; font-size: 0.875rem; font-weight: 600; color: var(--color-text); }

/* ===== Summary row (reports) ===== */
.summary-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }

/* ===== Charts ===== */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.chart-card { background: var(--color-surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.chart-card h3 { font-size: 0.95rem; margin-bottom: 0.75rem; color: var(--color-text); }
canvas { max-width: 100%; }

/* ===== Worker card (payroll) ===== */
.worker-card { background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; overflow: hidden; }
.worker-card h2 { font-size: 1rem; padding: 0.75rem 1rem; background: #f8f9fa; color: var(--color-text); border-bottom: 1px solid #eee; }
.extras-row td { color: var(--color-text-light); font-style: italic; }

/* ===== Quick actions ===== */
.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.quick-action {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 0.75rem 1rem; text-decoration: none; color: var(--color-text);
    font-size: 0.875rem; font-weight: 500; transition: box-shadow 0.15s;
}
.quick-action:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.15); text-decoration: none; }
.quick-action .qa-icon { font-size: 1.25rem; }

/* ===== Recent activity ===== */
.recent-list { list-style: none; }
.recent-list li { padding: 0.5rem 0; border-bottom: 1px solid #eee; font-size: 0.85rem; display: flex; justify-content: space-between; }
.recent-list li:last-child { border-bottom: none; }

/* ===== Generate actions ===== */
.generate-actions { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid #eee; }

/* ===== Login page (standalone, no base) ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { background: var(--color-surface); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 2rem; width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.5rem; text-align: center; margin-bottom: 1.5rem; color: var(--color-text); }
.error-list { background: #fef2f2; border: 1px solid #fca5a5; border-radius: 4px; padding: 0.75rem; margin-bottom: 1rem; color: #991b1b; font-size: 0.875rem; list-style: none; }

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
    .app-header .menu-toggle { display: block; }
    .sidebar { left: -100%; transition: left 0.3s; }
    .sidebar.open { left: 0; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 85; }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-left: 0; padding-bottom: calc(var(--bottom-bar-height) + 1rem); }
    .bottom-bar { display: flex; }
    .detail-grid { grid-template-columns: 1fr; }
    .charts-row { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .filter-toggle { display: block; width: 100%; padding: 0.5rem; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 0.5rem; cursor: pointer; text-align: center; font-size: 0.85rem; color: var(--color-text-muted); }
    .filters.collapsed { display: none; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-width: 180px; }
}
