* { box-sizing: border-box; }
:root {
    font-family: Inter, Segoe UI, Arial, sans-serif;
    color: #1f2937;
    background: #f5f6f8;
}
body { margin: 0; background: #f5f6f8; }
a { color: inherit; text-decoration: none; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.sidebar { background: #17191d; color: #fff; padding: 24px 16px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: #fff; color: #17191d; font-weight: 800; }
.brand strong, .brand span { display: block; }
.brand span { font-size: .78rem; opacity: .68; letter-spacing: .16em; }
.sidebar nav { display: grid; gap: 6px; margin-top: 36px; }
.sidebar nav a { padding: 11px 12px; border-radius: 8px; color: #d7dae0; }
.sidebar nav a.active, .sidebar nav a:hover { background: #2a2e35; color: #fff; }
.sidebar-footer { margin-top: auto; padding-top: 24px; border-top: 1px solid #30343b; }
.signed-user { font-size: .86rem; color: #b8bec8; overflow: hidden; text-overflow: ellipsis; }
.link-button { border: 0; background: transparent; color: #fff; padding: 8px 0 0; cursor: pointer; }
.main-area { padding: 32px; min-width: 0; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 22px; }
h1 { margin: 0 0 6px; font-size: 1.8rem; }
h2 { margin-top: 0; font-size: 1.1rem; }
p { color: #657080; }
.card, .kpi-card { background: #fff; border: 1px solid #e2e5ea; border-radius: 12px; padding: 22px; box-shadow: 0 2px 10px rgba(0,0,0,.03); }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card span { display: block; color: #6b7280; font-size: .82rem; }
.kpi-card strong { display: block; margin-top: 8px; font-size: 1.8rem; }
.table-card { padding: 0; overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid #edf0f3; vertical-align: top; }
th { background: #fafbfc; font-size: .78rem; color: #667085; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: #8a93a1; font-size: .82rem; }
.status { display: inline-block; padding: 5px 9px; border-radius: 999px; background: #eef1f5; font-size: .75rem; font-weight: 700; }
.empty-state { padding: 40px; text-align: center; color: #7d8795; }
.button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid #ccd2da; border-radius: 8px; padding: 10px 15px; background: #fff; cursor: pointer; font: inherit; }
.button.primary { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }
.button.full { width: 100%; }
.form-card { max-width: 800px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: grid; gap: 7px; font-size: .86rem; font-weight: 600; color: #454e5b; }
input, select { width: 100%; padding: 10px 11px; border: 1px solid #cfd5dd; border-radius: 7px; font: inherit; background: #fff; }
fieldset { border: 1px solid #e0e4e9; border-radius: 8px; margin: 20px 0; padding: 14px; }
legend { padding: 0 6px; font-weight: 700; }
.check-row { display: flex; align-items: center; gap: 9px; margin: 7px 0; font-weight: 500; }
.check-row input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.alert.error, .validation { color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1f5; }
.login-card { width: min(420px, 100%); background: #fff; padding: 34px; border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.1); }
.login-brand { color: #17191d; margin-bottom: 30px; }
.login-brand .brand-mark { background: #17191d; color: #fff; }
.login-card form { display: grid; gap: 16px; margin-top: 24px; }
@media (max-width: 950px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .sidebar nav { grid-template-columns: repeat(3, auto); margin-top: 18px; }
    .sidebar-footer { margin-top: 18px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .main-area { padding: 20px; }
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr; }
}

/* V1 operational CRM additions */
textarea { width: 100%; padding: 10px 11px; border: 1px solid #cfd5dd; border-radius: 7px; font: inherit; background: #fff; resize: vertical; }
.alert.success { color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.button.small { padding: 7px 10px; font-size: .82rem; }
.button.tiny { padding: 5px 8px; font-size: .75rem; }
.button.danger { background: #b42318; border-color: #b42318; color: #fff; }
.button.success { background: #15803d; border-color: #15803d; color: #fff; }
.button-stack { display: grid; gap: 10px; }
.header-actions, .inline-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.two-column { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; align-items: start; }
.lead-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, .9fr); gap: 18px; align-items: start; }
.stack { display: grid; gap: 18px; }
.form-card.wide { max-width: none; }
.form-grid.one-column { grid-template-columns: 1fr; margin-bottom: 14px; }
.full-span { grid-column: 1 / -1; }
.office-admin-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid #eef1f4; }
.office-admin-row:last-child { border-bottom: 0; }
.check-row.compact { margin: 0; }
.details-list { display: grid; gap: 10px; margin: 0 0 18px; }
.details-list > div { display: flex; justify-content: space-between; gap: 20px; }
.details-list dt { color: #667085; }
.details-list dd { margin: 0; font-weight: 600; text-align: right; }
.danger-zone { border-color: #fecaca; }
.filters { margin-bottom: 16px; }
.filter-grid { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; align-items: end; }
.filter-action { padding-bottom: 1px; }
.padded { padding: 20px; }
.clickable-row:hover td { background: #fafbfc; }
.eyebrow { color: #667085; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin-bottom: 5px; }
.section-title, .card-heading { display: flex; justify-content: space-between; align-items: start; gap: 14px; }
.card-heading { padding: 20px 20px 8px; }
.card-heading p { margin: 3px 0 0; }
.card-heading a { color: #1d4ed8; font-size: .86rem; font-weight: 600; }
.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.info-grid > div { display: grid; gap: 5px; }
.info-grid span { color: #7a8492; font-size: .78rem; }
.info-grid strong { font-size: .94rem; word-break: break-word; }
.timeline { display: grid; }
.timeline-item { display: grid; grid-template-columns: 14px 1fr; gap: 12px; position: relative; padding-bottom: 18px; }
.timeline-item:not(:last-child)::before { content: ''; position: absolute; left: 5px; top: 13px; bottom: 0; width: 2px; background: #e5e7eb; }
.timeline-dot { width: 12px; height: 12px; border-radius: 50%; background: #344054; margin-top: 4px; z-index: 1; }
.timeline-head { display: flex; justify-content: space-between; gap: 12px; }
.timeline-head span { color: #8a93a1; font-size: .78rem; white-space: nowrap; }
.timeline-item p { margin: 4px 0 0; font-size: .88rem; }
.empty-state.compact { padding: 20px 0; }
.task-list { display: grid; gap: 9px; }
.task-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #eef1f4; }
.task-row:last-child { border-bottom: 0; }
.task-row > div:first-child { display: grid; gap: 3px; }
.task-row span { color: #7a8492; font-size: .78rem; }
.task-done { opacity: .65; }
.state-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.status-success { background: #dcfce7; color: #166534; }
.status-danger { background: #fee2e2; color: #991b1b; }
.status-nova { background: #eff6ff; color: #1d4ed8; }
.status-em_contacto { background: #fef3c7; color: #92400e; }
.status-contactada, .status-aguarda_cliente { background: #f3e8ff; color: #7e22ce; }
.status-orcamento_enviado { background: #e0f2fe; color: #0369a1; }
.status-agendada { background: #dcfce7; color: #166534; }
.status-nao_compareceu { background: #ffedd5; color: #9a3412; }
.status-convertida { background: #d1fae5; color: #065f46; }
.status-perdida { background: #fee2e2; color: #991b1b; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, .8fr); gap: 18px; }
.compact-table { min-width: 650px; }
hr { border: 0; border-top: 1px solid #e5e7eb; margin: 18px 0; }

@media (max-width: 1100px) {
    .two-column, .lead-layout, .dashboard-grid { grid-template-columns: 1fr; }
    .filter-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 650px) {
    .filter-grid, .info-grid, .office-admin-row { grid-template-columns: 1fr; }
    .timeline-head { display: grid; }
}
.notice { margin-bottom: 16px; border-left: 4px solid #1d4ed8; }
.notice p { margin-bottom: 0; }
code { background: #f2f4f7; padding: 2px 5px; border-radius: 4px; }

/* V2 task-first workflow */
.nav-with-badge { display: flex !important; align-items: center; justify-content: space-between; gap: 10px; }
.nav-badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; background: #dc2626; color: #fff; font-size: .7rem; font-weight: 800; }
.nav-section { margin: 20px 12px 4px; color: #7f8794; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.section-subtitle { margin: 3px 0 0; font-size: .84rem; }
.task-priority-card { border-left: 4px solid #2563eb; }
.prominent-task-list { gap: 0; }
.prominent-task-row { padding: 14px 0; align-items: flex-start; }
.task-main { min-width: 0; display: grid; gap: 6px !important; }
.task-row-heading { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-type { display: inline-flex; width: fit-content; padding: 4px 7px; border-radius: 6px; background: #eef2ff; color: #3730a3 !important; font-size: .7rem !important; font-weight: 800; letter-spacing: .02em; }
.task-deadline { display: grid; gap: 2px; color: #475467 !important; font-size: .78rem !important; white-space: nowrap; }
.task-deadline strong { color: inherit; }
.task-deadline span { color: inherit !important; font-size: .7rem !important; }
.deadline-overdue { color: #b42318 !important; }
.deadline-today { color: #b54708 !important; }
.deadline-completed { color: #667085 !important; }
.subtle-danger { color: #b42318; border-color: #fecaca; background: #fff; }
.subtle-danger:hover { background: #fef2f2; }
.close-lead-card p { margin-top: -2px; }
.lost-summary { display: grid; gap: 5px; padding: 12px; background: #f9fafb; border-radius: 8px; }
.lost-summary span { color: #667085; font-size: .75rem; }
.lost-summary p { margin: 4px 0 0; }
.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px; background: rgba(17, 24, 39, .55); }
.modal-card { width: min(540px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: #fff; border-radius: 14px; padding: 24px; box-shadow: 0 24px 80px rgba(0,0,0,.22); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.modal-header h2 { margin-bottom: 0; }
.modal-close { border: 0; background: transparent; font-size: 1.8rem; line-height: 1; color: #667085; cursor: pointer; padding: 0 3px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.task-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.task-tab { border: 1px solid #d0d5dd; background: #fff; color: #344054; border-radius: 999px; padding: 8px 12px; font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer; }
.task-tab span { display: inline-flex; min-width: 22px; height: 20px; align-items: center; justify-content: center; margin-left: 5px; padding: 0 6px; border-radius: 999px; background: #f2f4f7; font-size: .7rem; }
.task-tab.active { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.task-tab.active span { background: rgba(255,255,255,.18); color: #fff; }
.task-filters { margin-bottom: 14px; }
.task-filter-grid { grid-template-columns: 1fr 1fr auto; }
.task-table-card { overflow-x: auto; }
.tasks-table { min-width: 960px; }
.tasks-table td { vertical-align: middle; }
.task-lead-link { display: block; color: #1d4ed8; font-weight: 700; margin-bottom: 3px; }
.task-actions { justify-content: flex-end; flex-wrap: nowrap; }
.task-completed-row { opacity: .68; }
.dashboard-task-row { text-decoration: none; }
.dashboard-task-row:hover { background: #fafbfc; }
.dashboard-task-row > .task-deadline { margin-left: auto; text-align: right; }
.operator-dashboard-intro { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.operator-dashboard-intro h2 { margin-bottom: 4px; }
.operator-dashboard-intro p { margin: 0; }
.operator-kpi-grid { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.kpi-alert strong { color: #b42318; }
.operator-dashboard-grid { grid-template-columns: minmax(320px, .8fr) minmax(0, 1.4fr); }

@media (max-width: 1100px) {
    .operator-kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .operator-dashboard-grid { grid-template-columns: 1fr; }
    .task-filter-grid { grid-template-columns: 1fr 1fr auto; }
}

@media (max-width: 700px) {
    .operator-dashboard-intro { align-items: stretch; flex-direction: column; }
    .operator-dashboard-intro .button { width: 100%; }
    .operator-kpi-grid { grid-template-columns: 1fr; }
    .task-filter-grid { grid-template-columns: 1fr; }
    .task-tabs { display: grid; grid-template-columns: repeat(2, 1fr); }
    .task-tab { border-radius: 8px; }
    .prominent-task-row { display: grid; }
    .task-actions { flex-wrap: wrap; justify-content: flex-start; }
    .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
}
