:root {
  --bg: #f6f3ef;
  --panel: #ffffff;
  --panel-soft: #fff9f2;
  --text: #251b16;
  --muted: #7c6c63;
  --line: #eadfd5;
  --brand: #8f1d18;
  --brand-2: #c4552d;
  --green: #0f8b57;
  --yellow: #c99700;
  --blue: #1d67c1;
  --orange: #e06d22;
  --red: #c7352e;
  --gray: #7b818a;
  --shadow: 0 20px 50px rgba(75, 36, 20, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 292px; padding: 24px; background: #221713; color: white; display: flex; flex-direction: column; gap: 24px; z-index: 20; }
.brand { display: flex; gap: 14px; align-items: center; }
.brand-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, #9e211c, #e97a3b); font-size: 24px; }
.brand-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; display: block; }
.brand strong { display: block; font-size: 18px; }
.brand span, .sidebar-card small { color: #d9c7bc; font-size: 12px; }
.nav { display: grid; gap: 8px; }
.nav button { width: 100%; text-align: left; color: #f7eee8; background: transparent; border-radius: 14px; padding: 13px 14px; display: flex; gap: 10px; align-items: center; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.12); }
.sidebar-card { margin-top: auto; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); padding: 16px; border-radius: 18px; display: grid; gap: 10px; }

.app-shell { margin-left: 292px; min-height: 100vh; padding: 28px; }
.topbar { display: grid; grid-template-columns: auto 1fr minmax(280px, 440px); align-items: center; gap: 18px; margin-bottom: 18px; }
.icon-button { width: 44px; height: 44px; border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: 0 6px 20px rgba(0,0,0,.06); display: flex; align-items: center; justify-content: center; font-size: 18px; padding: 0; }
#menuToggle { display: none; }
.eyebrow { margin: 0 0 4px; text-transform: uppercase; letter-spacing: .08em; color: var(--brand-2); font-weight: 800; font-size: 12px; }
h1, h2, h3 { margin: 0; }
.quick-search { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 0 16px; height: 52px; box-shadow: var(--shadow); }
.quick-search input { border: 0; outline: 0; width: 100%; background: transparent; }

.alerts-bar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.alert-card { background: var(--panel); border-left: 5px solid var(--brand); border-radius: 16px; padding: 14px; box-shadow: 0 10px 30px rgba(60, 31, 19, .08); }
.alert-card strong { display: block; font-size: 20px; }
.alert-card span { color: var(--muted); font-size: 13px; }
.content { display: grid; gap: 18px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 20px; box-shadow: var(--shadow); }
.card-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.primary, .secondary, .ghost, .danger { min-height: 42px; padding: 0 15px; border-radius: 13px; font-weight: 750; }
.primary { color: white; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.secondary { background: #f1e6dc; color: var(--text); }
.ghost { background: rgba(255,255,255,.13); color: inherit; border: 1px solid rgba(255,255,255,.14); }
.full { width: 100%; }
.danger { color: white; background: var(--red); }

.metric { background: linear-gradient(180deg, #fff, #fff8f1); border: 1px solid var(--line); border-radius: 20px; padding: 18px; }
.metric strong { display: block; font-size: clamp(26px, 4vw, 38px); }
.metric span { color: var(--muted); }
.filters { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
input, select, textarea { border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fffdfa; color: var(--text); min-width: 0; }
textarea { min-height: 92px; resize: vertical; }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 700; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 900px; background: white; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; background: #fff8f1; }
tr:hover td { background: #fffaf5; }
.visit-row-canceled td { background: #ffe9e8; color: #7f1f1a; }
.visit-row-canceled:hover td { background: #ffdeda; }
.visit-row-canceled td:first-child { box-shadow: inset 4px 0 0 var(--red); }
.visit-row-canceled td:not(:last-child) { text-decoration: line-through; text-decoration-thickness: 1.5px; text-decoration-color: #b13028; }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-green { color: var(--green); background: #e7f7ef; }
.status-yellow { color: #7a6000; background: #fff3bd; }
.status-blue { color: var(--blue); background: #e8f1ff; }
.status-orange { color: var(--orange); background: #fff0e4; }
.status-red { color: var(--red); background: #ffe9e8; }
.status-gray { color: var(--gray); background: #f0f1f3; }
.link-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.link-buttons a, .mini-btn { text-decoration: none; color: var(--brand); background: #fff0e8; padding: 7px 9px; border-radius: 10px; font-size: 12px; font-weight: 800; }

.kanban { display: grid; grid-template-columns: repeat(10, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kanban-column { background: #f8eee5; border: 1px solid var(--line); border-radius: 18px; padding: 12px; min-height: 260px; }
.kanban-column h3 { font-size: 14px; margin-bottom: 10px; display: flex; justify-content: space-between; gap: 8px; }
.deal-card { background: white; border-radius: 15px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); display: grid; gap: 8px; }
.deal-card small { color: var(--muted); }
.calendar { display: grid; gap: 10px; }
.timeline-row { display: grid; grid-template-columns: 82px 1fr; gap: 14px; align-items: stretch; }
.timeline-time { color: var(--brand); font-weight: 900; padding-top: 14px; }
.timeline-card { border-left: 5px solid var(--brand-2); background: white; border-radius: 16px; padding: 14px; box-shadow: 0 10px 25px rgba(80, 34, 15, .08); }
.timeline-card--action { display: grid; gap: 8px; background: linear-gradient(180deg, #fffdfb, #fff6ef); }
.timeline-card--action p { margin: 0; font-weight: 700; }
.timeline-card--action small { color: var(--muted); }

.dialog { border: 0; padding: 0; background: transparent; width: min(920px, calc(100vw - 28px)); max-height: calc(100vh - 20px); }
.dialog::backdrop { background: rgba(30, 17, 11, .5); backdrop-filter: blur(4px); }
.dialog-card { background: white; border-radius: 24px; padding: 22px; box-shadow: var(--shadow); max-height: calc(100vh - 20px); overflow: auto; }
.dialog-card header, .dialog-card footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-card footer { margin-top: 18px; justify-content: end; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; max-height: min(68vh, 720px); overflow: auto; padding-right: 6px; }
.form-grid .wide { grid-column: 1 / -1; }
.close-summary { display: grid; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: #fff8f1; margin-top: 18px; }
.close-summary small { color: var(--muted); }
.visit-cards { display: grid; gap: 14px; }
.visit-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: 0 8px 24px rgba(60,30,15,.07); display: grid; gap: 10px; }
.visit-card--canceled { background: #ffe9e8; border-color: #f0b0ac; }
.visit-card--canceled p, .visit-card--canceled .visit-card-meta span { text-decoration: line-through; text-decoration-color: #b13028; color: #7f1f1a; }
.visit-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.visit-card-top strong { display: block; font-size: 16px; }
.visit-card-top small { color: var(--muted); font-size: 12px; }
.visit-card-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); }
.visit-card-meta span { background: #f5ece4; border-radius: 8px; padding: 4px 8px; }
.visit-card-comments, .visit-card-articles, .visit-card-next, .visit-card-follow { margin: 0; font-size: 13px; color: var(--text); }
.visit-card-next { font-weight: 700; color: var(--brand-2); }
.visit-card-follow small { color: var(--muted); }
.visit-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.visit-card .actions button { flex: 1 1 auto; min-height: 42px; }
.deadline-dialog-body { display: grid; gap: 14px; margin-top: 12px; }
.deadline-metrics .metric strong { font-size: 30px; }

.empty-state { text-align: center; padding: 44px; color: var(--muted); }
.empty-state div { font-size: 42px; }
.import-box { border: 2px dashed #d6bda8; border-radius: 18px; padding: 20px; background: #fffaf5; }
.validation-list { display: grid; gap: 8px; margin-top: 12px; }
.validation-list li { color: var(--red); }

.dialog-fullscreen { width: min(1080px, calc(100vw - 28px)); max-width: none; max-height: calc(100vh - 28px); }
.dialog-card-full { width: 100%; height: calc(100vh - 28px); display: grid; grid-template-rows: auto 1fr auto; }
.picker-layout { display: grid; grid-template-rows: auto 1fr; gap: 10px; min-height: 0; margin-top: 14px; }
.picker-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.picker-tab { min-height: 40px; padding: 0 14px; border-radius: 999px; background: #f4e8dc; color: var(--text); font-weight: 800; box-shadow: inset 0 0 0 1px rgba(143, 29, 24, .05); }
.picker-tab.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 10px 24px rgba(143, 29, 24, .18); }
.picker-panel { border: 1px solid var(--line); border-radius: 20px; background: linear-gradient(180deg, #fffdfb, #fff8f1); padding: 14px; min-height: 0; display: none; gap: 10px; box-shadow: inset 0 1px 0 rgba(255,255,255,.7); }
.picker-panel.active { display: grid; }
.picker-list, .picker-selected { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: white; min-height: 220px; max-height: 52vh; padding: 10px; display: grid; gap: 8px; align-content: start; box-shadow: 0 10px 26px rgba(60, 31, 19, .05); }
.picker-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; border: 1px solid transparent; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.picker-item:hover { background: #fff5ec; border-color: #f2d8c4; transform: translateY(-1px); }
.picker-item input { min-width: auto; }
.picker-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: linear-gradient(180deg, #fff7f1, #fff0e5); border: 1px solid #f1dcc9; border-radius: 14px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 16px rgba(60, 31, 19, .05); }
.picker-chip button { min-height: 30px; padding: 0 10px; border-radius: 999px; background: #fff; border: 1px solid #ead7c7; }
.picker-empty { color: var(--muted); font-size: 13px; padding: 8px; }
.cross-sell-layout { display: grid; gap: 12px; margin-top: 12px; }
.cross-sell-list-wrap { border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: #fffaf5; }
.cross-sell-selected { display: flex; flex-wrap: wrap; gap: 8px; min-height: 46px; border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: #fffdfb; }
.cross-sell-chip { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; background: #f5ece4; color: var(--text); border: 1px solid #eadbcf; }
.cross-sell-inline { display: grid; gap: 8px; }
.cross-sell-inline summary { cursor: pointer; color: var(--brand); font-weight: 800; display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px; background: #fff2e7; border: 1px solid #f0ddcd; width: fit-content; }
.cross-sell-inline summary::marker, .cross-sell-inline summary::-webkit-details-marker { display: none; }
.cross-sell-inline-list { display: flex; flex-wrap: wrap; gap: 6px; }
.cross-sell-recommendations { display: grid; gap: 8px; min-width: 260px; }
.cross-sell-card { display: grid; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fffaf5; }
.cross-sell-card strong { color: var(--brand); }
.cross-sell-card small { color: var(--muted); }
.cross-sell-card button { justify-self: start; min-height: 34px; }
.incident-guide { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.incident-guide article { background: linear-gradient(180deg, #fffaf5, #fff3e9); border: 1px solid var(--line); border-radius: 18px; padding: 14px; box-shadow: 0 10px 24px rgba(60, 31, 19, .05); }
.incident-guide strong { display: block; margin-bottom: 6px; color: var(--brand); }
.incident-guide p { margin: 0; color: var(--muted); font-size: 13px; }
.incident-process { display: block; }
.incident-process summary { cursor: pointer; color: var(--brand); font-weight: 800; display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; background: #fff2e7; border: 1px solid #f0ddcd; box-shadow: 0 6px 16px rgba(60, 31, 19, .05); }
.incident-process summary::marker, .incident-process summary::-webkit-details-marker { display: none; }
.incident-process-row { padding: 12px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.incident-process-main { min-width: 0; }
.incident-process-main strong { display: inline-block; margin-right: 8px; }
.incident-process-main span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.incident-process-main p { margin: 4px 0 0; }
.incident-actions { display: flex; gap: 8px; flex-wrap: nowrap; }
.incident-icon { width: 38px; height: 38px; min-height: 38px; padding: 0; border-radius: 999px; display: inline-grid; place-items: center; font-size: 15px; background: linear-gradient(180deg, #fff, #fff4eb); border: 1px solid #edd9c8; box-shadow: 0 8px 18px rgba(60, 31, 19, .08); color: var(--brand); }
.incident-icon:hover { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; transform: translateY(-1px); }
.incident-event-edit { width: 32px; height: 32px; min-height: 32px; font-size: 12px; flex: 0 0 auto; margin-top: 2px; }

.branding-preview { border: 1px dashed var(--line); border-radius: 14px; min-height: 96px; display: grid; place-items: center; background: #fffaf5; overflow: hidden; }
.branding-preview span { color: var(--muted); font-size: 13px; }
.branding-preview img { max-height: 160px; width: auto; max-width: 100%; display: block; object-fit: contain; }

body.auth-mode .sidebar,
body.auth-mode .alerts-bar,
body.auth-mode .quick-search,
body.auth-mode #menuToggle { display: none !important; }
body.auth-mode .app-shell { margin-left: 0; max-width: 760px; margin-inline: auto; padding-top: 36px; }
.auth-card { max-width: 540px; margin: 24px auto 0; }
.auth-card p { color: var(--muted); margin-top: 8px; }
.auth-error { color: var(--red); font-weight: 700; min-height: 20px; }

@media (max-width: 1100px) {
  .alerts-bar, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { grid-template-columns: auto 1fr; }
  .quick-search { grid-column: 1 / -1; }
}
@media (max-width: 780px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    width: min(88vw, 320px);
    padding: 18px 14px 16px;
    z-index: 50;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-card { margin-top: 12px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .app-shell::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(25, 15, 10, .42);
    z-index: 40;
  }
  .app-shell { margin-left: 0; padding: 14px; }
  #menuToggle { display: block; }
  .topbar { gap: 10px; margin-bottom: 12px; }
  h1 { font-size: 24px; line-height: 1.2; }
  h2 { font-size: 20px; line-height: 1.25; }
  .card { padding: 14px; border-radius: 16px; }
  .card-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .card-header .actions { width: 100%; }
  .actions { width: 100%; }
  .actions .primary,
  .actions .secondary,
  .actions .danger { flex: 1 1 auto; }
  .table-wrap { border-radius: 12px; }
  table { min-width: 640px; }
  th, td { padding: 10px 10px; }
  .alerts-bar, .cols-4, .filters, .form-grid { grid-template-columns: 1fr; }
  .incident-guide { grid-template-columns: 1fr; }
  .incident-process-row { flex-direction: column; }
  .incident-actions { flex-wrap: wrap; }
  .timeline-row { grid-template-columns: 1fr; gap: 2px; }
  .timeline-time { padding-top: 0; font-size: 13px; }
  .dialog { width: calc(100vw - 10px); max-height: calc(100vh - 10px); }
  .dialog-card { border-radius: 16px; padding: 14px; max-height: calc(100vh - 10px); }
  .dialog-card header { position: sticky; top: 0; background: white; z-index: 2; padding-bottom: 8px; }
  .dialog-card footer { position: sticky; bottom: 0; background: white; padding-top: 10px; }
  .form-grid { margin-top: 12px; max-height: none; overflow: visible; padding-right: 0; }
  .picker-list, .picker-selected { max-height: 34vh; }
  .close-summary { margin-top: 12px; padding: 12px; }
  .import-box { padding: 14px; }
  .primary, .secondary, .ghost, .danger { min-height: 48px; }
}
@media print {
  .sidebar, .topbar, .alerts-bar, .actions, .filters { display: none !important; }
  .app-shell { margin: 0; padding: 0; }
  .card { box-shadow: none; border: 0; }
}
