:root {
    --bg: #fbfbfa;
    --surface: #ffffff;
    --surface-soft: #f7f7f5;
    --sidebar: #f1f1ee;
    --line: #e5e3de;
    --line-strong: #d5d2ca;
    --text: #20201d;
    --muted: #6f6d66;
    --faint: #9a978e;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --green: #067647;
    --amber: #b54708;
    --red: #b42318;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(32, 32, 29, 0.06), 0 8px 24px rgba(32, 32, 29, 0.05);
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
}

body.auth-locked .app-shell,
body.auth-locked .mobile-tabs {
    filter: blur(5px);
    pointer-events: none;
    user-select: none;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(251, 251, 250, 0.88);
    backdrop-filter: blur(18px);
}

.auth-gate.active { display: flex; }

.auth-card {
    width: min(440px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(32, 32, 29, 0.16);
    padding: 24px;
}

.auth-brand { padding: 0; margin-bottom: 28px; }
.auth-card h1 { font-size: 28px; margin-bottom: 10px; }
.auth-card p { color: var(--muted); }
.auth-button { width: 100%; margin-top: 12px; }
.auth-note { font-size: 12px; margin: 14px 0 0; text-align: center; }

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

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 268px;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 14px;
    gap: 14px;
    z-index: 20;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: #20201d;
    color: #fff;
    font-weight: 700;
}

.brand-block strong, .brand-block span { display: block; }
.brand-block span { color: var(--muted); font-size: 12px; }

.sidebar-nav { display: grid; gap: 2px; }

.nav-item, .mobile-tabs a {
    color: var(--muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-item {
    min-height: 34px;
    padding: 7px 9px;
    border-radius: 6px;
    font-weight: 500;
}

.nav-item svg, .mobile-tabs svg, .btn svg, .icon-btn svg { width: 17px; height: 17px; stroke-width: 2; }
.nav-item:hover { background: rgba(32, 32, 29, 0.05); color: var(--text); }
.nav-item.active { background: #fff; color: var(--text); box-shadow: 0 1px 0 rgba(32, 32, 29, 0.04); }

.sidebar-section {
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.section-label, .eyebrow {
    margin: 0 0 8px;
    color: var(--faint);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.team-row {
    width: 100%;
    border: 0;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    text-align: left;
}

.team-row.active, .team-row:hover { background: rgba(32, 32, 29, 0.05); }
.team-row strong, .team-row small { display: block; }
.team-row small { color: var(--muted); font-size: 12px; }

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 700;
    flex: 0 0 auto;
}

.avatar.muted { background: #ece9e2; color: var(--muted); }

.sync-indicator {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    padding: 8px;
}

.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.sync-indicator.online .sync-dot { background: var(--green); }

.workspace {
    margin-left: 268px;
    width: calc(100% - 268px);
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 34px;
    background: rgba(251, 251, 250, 0.86);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.2; }
h2 { margin-bottom: 8px; font-size: 28px; line-height: 1.18; }
h3 { margin-bottom: 0; font-size: 16px; line-height: 1.25; }

.top-actions, .modal-actions, .ocr-actions, .canvas-btn-group { display: flex; align-items: center; gap: 8px; }

.btn, .icon-btn {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn { padding: 0 12px; }
.btn.small { min-height: 31px; padding: 0 10px; font-size: 12px; }
.btn.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn.primary:hover, .icon-btn.dark:hover { background: var(--accent-dark); }
.btn.secondary:hover, .icon-btn:hover { background: var(--surface-soft); border-color: var(--line-strong); }

.icon-btn { width: 36px; padding: 0; }
.icon-btn.dark { border-color: var(--accent); background: var(--accent); color: #fff; }

.page-frame { padding: 28px 34px 54px; max-width: 1280px; }
.view-section { display: none; }
.view-section.active { display: block; }

.intro-row, .page-title-row, .panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
}

.intro-row {
    border-bottom: 1px solid var(--line);
    padding-bottom: 22px;
    margin-bottom: 18px;
}

.muted-text { color: var(--muted); margin-bottom: 0; max-width: 680px; }

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.metric-block, .panel, .progress-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.metric-block { padding: 16px; display: grid; gap: 4px; }
.metric-block span, .metric-block small { color: var(--muted); }
.metric-block strong { font-size: 28px; line-height: 1.1; }

.dashboard-grid, .two-column {
    display: grid;
    grid-template-columns: minmax(0, 1.18fr) minmax(360px, 0.82fr);
    gap: 16px;
}

.panel { padding: 16px; min-width: 0; }
.main-panel, .chat-panel { min-height: 438px; }
.panel-heading { margin-bottom: 14px; }
.text-link { color: var(--accent); text-decoration: none; font-weight: 600; }

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: #eef4ff;
    color: #175cd3;
    font-size: 12px;
    font-weight: 700;
}

.status-pill.warning { background: #fff6ed; color: var(--amber); }

.task-list { display: grid; gap: 8px; }

.task-item {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    padding: 10px;
}

.task-item-left { display: flex; gap: 10px; align-items: flex-start; min-width: 0; }

.checkbox-circle {
    width: 20px;
    height: 20px;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: transparent;
    border-radius: 50%;
    flex: 0 0 auto;
}

.task-item.completed .checkbox-circle { background: var(--green); border-color: var(--green); color: #fff; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-item.completed .task-title { color: var(--muted); text-decoration: line-through; }

.task-meta { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 12px; }
.priority-badge { border-radius: 999px; padding: 1px 7px; font-weight: 700; text-transform: uppercase; font-size: 11px; }
.priority-high, .priority-urgent { background: #fef3f2; color: var(--red); }
.priority-medium { background: #fff6ed; color: var(--amber); }
.priority-low { background: #ecfdf3; color: var(--green); }

.chat-panel { display: flex; flex-direction: column; }
.chat-box {
    flex: 1;
    min-height: 280px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #f8f8f6;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-message {
    max-width: 86%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
    font-size: 13px;
}

.chat-message.user { align-self: flex-end; background: #eff6ff; border-color: #bfdbfe; }
.chat-message.assistant { align-self: flex-start; }
.chat-message.system { align-self: center; max-width: 100%; color: var(--muted); background: transparent; border: 0; text-align: center; font-size: 12px; }

.chat-input-area { display: flex; gap: 8px; margin-top: 10px; }
.chat-input-area input { flex: 1; min-width: 0; }

input[type="text"], input[type="number"], input[type="date"], select {
    min-height: 36px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: 0 10px;
    outline: none;
}

input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
label { color: var(--muted); font-size: 12px; font-weight: 700; }
.field-group { display: grid; gap: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-warn { border-color: #fedf89 !important; background: #fffcf5 !important; }

.projects-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.project-card { padding: 16px; }
.project-card header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.project-card strong { font-size: 17px; }
.project-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.project-stats span { display: block; color: var(--muted); font-size: 12px; }
.project-stats b { font-size: 18px; }

.kanban-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.kanban-column { background: var(--surface-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 360px; }
.kanban-column h3 { display: flex; justify-content: space-between; margin-bottom: 10px; color: var(--muted); font-size: 13px; }

.upload-zone {
    width: 100%;
    min-height: 160px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--muted);
    display: grid;
    place-items: center;
    gap: 4px;
    padding: 22px;
    text-align: center;
}

.upload-zone svg { width: 28px; height: 28px; color: var(--accent); }
.upload-zone strong { color: var(--text); }

.canvas-wrapper { margin-top: 14px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.hide { display: none !important; }
#photo-canvas { width: 100%; height: auto; max-height: 390px; display: block; cursor: crosshair; }
.canvas-actions { border-top: 1px solid var(--line); padding: 10px; display: flex; justify-content: space-between; gap: 10px; }
.color-picker-bar { display: flex; gap: 7px; align-items: center; }
.color-dot { width: 22px; height: 22px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--line-strong); }
.color-dot.active { box-shadow: 0 0 0 2px var(--accent); }
.color-red { background: var(--red); }
.color-green { background: var(--green); }
.color-blue { background: var(--accent); }

.photos-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.gallery-photo-card { border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.gallery-photo-card img, .photo-placeholder { width: 100%; height: 118px; object-fit: cover; display: grid; place-items: center; background: var(--surface-soft); color: var(--muted); }
.gallery-photo-card span { display: block; padding: 8px; font-size: 12px; color: var(--muted); }

.ocr-ticket-preview { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 14px; background: #fffdf7; }
.receipt-lines { display: grid; gap: 6px; margin-bottom: 14px; }
.receipt-lines span { height: 8px; background: #ece6da; border-radius: 4px; }
.receipt-lines span:nth-child(2) { width: 70%; }
.receipt-lines span:nth-child(3) { width: 42%; }
.ocr-fields { display: grid; gap: 10px; margin-bottom: 12px; }
.expense-list { display: grid; gap: 8px; }
.expense-row { display: flex; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 7px; padding: 10px; }
.expense-row small { color: var(--muted); }

.client-portal-header { margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.progress-card { padding: 16px; margin-bottom: 16px; }
.progress-card > div:first-child { display: flex; justify-content: space-between; margin-bottom: 12px; }
.progress-card span { color: var(--muted); }
.progress-card strong { font-size: 24px; }
.progress-bar-container { height: 10px; background: var(--surface-soft); border-radius: 999px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--green); border-radius: inherit; }
.completed-tasks-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.completed-tasks-list li { border: 1px solid var(--line); border-radius: 7px; padding: 10px; }
.completed-tasks-list small { display: block; color: var(--muted); margin-top: 3px; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(32, 32, 29, 0.28);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 50;
}

.modal-overlay.active { display: flex; }
.modal { width: min(460px, 100%); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 24px 80px rgba(32, 32, 29, 0.24); padding: 16px; display: grid; gap: 14px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-header h2 { font-size: 18px; margin: 0; }
.modal-note { color: var(--muted); margin: 0; }

.mobile-tabs { display: none; }

@media (max-width: 960px) {
    .sidebar { display: none; }
    .workspace { margin-left: 0; width: 100%; }
    .topbar { padding: 13px 16px; }
    .page-frame { padding: 18px 16px 88px; }
    .metrics-grid, .dashboard-grid, .two-column, .projects-grid, .kanban-board { grid-template-columns: 1fr; }
    .intro-row, .page-title-row { align-items: stretch; flex-direction: column; }
    .mobile-tabs {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(14px);
        border-top: 1px solid var(--line);
        padding: 7px 5px calc(7px + env(safe-area-inset-bottom));
    }
    .mobile-tabs a { justify-content: center; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
    .mobile-tabs a.active { color: var(--text); }
}

@media (max-width: 560px) {
    h1 { font-size: 21px; }
    h2 { font-size: 24px; }
    .top-actions .secondary { display: none; }
    .field-row, .photos-gallery { grid-template-columns: 1fr; }
    .canvas-actions, .modal-actions { flex-direction: column; align-items: stretch; }
    .btn, .icon-btn { width: 100%; }
    .top-actions .icon-btn { width: 36px; }
}
