:root {
  --bg: #f5efe9;
  --bg-soft: #fbf8f5;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: #fff;
  --border: rgba(94, 62, 34, 0.12);
  --text: #1f1a18;
  --muted: #6d615d;
  --primary: #8d5b3b;
  --primary-strong: #6d4027;
  --accent: #d9b38c;
  --success: #2f8f5b;
  --warning: #d8922d;
  --danger: #c65445;
  --shadow: 0 22px 60px rgba(70, 38, 18, 0.12);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(135deg, #fefbf9 0%, #f2e9df 100%);
  font-family: 'Inter', sans-serif;
  color: var(--text);
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top left, #f4d7b7 0%, rgba(244, 215, 183, 0) 22%),
    linear-gradient(135deg, #fcf7f2 0%, #f1e3d4 100%);
}

.login-card {
  width: min(460px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(112, 74, 48, 0.08);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #b77d57);
  color: white;
  font-weight: 800;
  border-radius: 18px;
  box-shadow: 0 14px 28px rgba(141, 91, 59, 0.22);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  font-weight: 700;
}

h1, h2, h3, p {
  margin: 0;
}

.login-form {
  display: grid;
  gap: 18px;
}

.login-form label,
.filter-group {
  display: grid;
  gap: 8px;
}

.login-form span,
.filter-group label {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

input, select {
  border: 1px solid rgba(90, 69, 54, 0.12);
  background: rgba(255,255,255,0.75);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  outline: none;
}

input:focus, select:focus {
  border-color: rgba(141, 91, 59, 0.45);
  box-shadow: 0 0 0 4px rgba(141, 91, 59, 0.08);
}

.multi-select {
  position: relative;
}

.dropdown-trigger {
  width: 100%;
  border: 1px solid rgba(90, 69, 54, 0.12);
  background: rgba(255,255,255,0.75);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  font-weight: 600;
}

.dropdown-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  background: white;
  border: 1px solid rgba(90, 69, 54, 0.1);
  border-radius: 12px;
  box-shadow: 0 18px 30px rgba(50, 30, 18, 0.12);
  display: grid;
  gap: 8px;
  padding: 10px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}

.check-item input {
  accent-color: var(--primary);
}

button.primary-btn,
button.ghost-btn {
  border-radius: 12px;
  padding: 12px 18px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  box-shadow: 0 16px 30px rgba(109, 64, 39, 0.22);
  font-weight: 700;
}

button.primary-btn:hover,
button.ghost-btn:hover {
  transform: translateY(-1px);
}

button.ghost-btn {
  background: rgba(141, 91, 59, 0.08);
  color: var(--primary-strong);
  font-weight: 600;
}

.login-note {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(47, 143, 91, 0.08);
}

.dashboard {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: rgba(40, 27, 21, 0.96);
  color: white;
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.logo-block {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 8px;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #d4a173, #9c5d3d);
  font-weight: 800;
  color: white;
}

.logo-block small {
  display: block;
  color: rgba(255,255,255,0.72);
}

.nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: rgba(255,255,255,0.78);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
}

.nav-item.active {
  background: rgba(255,255,255,0.08);
  color: white;
}

.sidebar-card {
  border-radius: 18px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 18px;
  display: grid;
  gap: 8px;
}

.sidebar-card p {
  color: rgba(255,255,255,0.66);
}

.sidebar-card strong {
  font-size: 24px;
}

/* ── Topbar user block ──────────────────────── */
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 1px solid var(--border);
  padding-left: 14px;
  margin-left: 4px;
}

.topbar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-panel {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  gap: 12px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 14px;
  padding: 18px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}

.wide {
  align-self: end;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 18px 32px rgba(68, 41, 22, 0.06);
}

.stat-card .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.stat-card .value {
  display: block;
  margin-top: 14px;
  font-size: clamp(1.5rem, 2vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.stat-card .trend {
  display: inline-flex;
  margin-top: 12px;
  padding: 6px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.trend.up {
  background: rgba(47, 143, 91, 0.1);
  color: var(--success);
}

.trend.down {
  background: rgba(198, 84, 69, 0.1);
  color: var(--danger);
}

.content-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  margin-bottom: 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px 18px 14px;
  box-shadow: 0 18px 32px rgba(68, 41, 22, 0.06);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header h3 {
  font-size: 1.03rem;
}

.panel-header span {
  color: var(--muted);
  font-weight: 700;
}

.mini-chart {
  display: flex;
  align-items: end;
  gap: 12px;
  min-height: 230px;
  padding-top: 20px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  gap: 10px;
  height: 100%;
}

.bar {
  width: 100%;
  max-width: 42px;
  border-radius: 12px 12px 8px 8px;
  background: linear-gradient(180deg, #d7ad82, #82593a);
  min-height: 20px;
  box-shadow: inset 0 -10px 20px rgba(255,255,255,0.18);
}

.bar-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.simple-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(141, 91, 59, 0.03);
}

.simple-list strong {
  font-size: 15px;
}

.tables-panel {
  margin-bottom: 22px;
}

.split {
  margin-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 800px;
}

th, td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(86, 63, 48, 0.08);
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 800;
}

td {
  font-size: 14px;
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status.invoiced {
  background: rgba(47, 143, 91, 0.1);
  color: var(--success);
}

.status.no {
  background: rgba(198, 84, 69, 0.1);
  color: var(--danger);
}

.status.to\ invoice {
  background: rgba(216, 146, 45, 0.12);
  color: var(--warning);
}

@media (max-width: 980px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .main-panel {
    padding: 20px 14px 28px;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .filters {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }
}

/* ── Follow-up badges ──────────────────────────── */
.fu {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.fu.overdue { background: rgba(198,84,69,.12); color: var(--danger); }
.fu.soon    { background: rgba(216,146,45,.12); color: var(--warning); }
.fu.active  { background: rgba(47,143,91,.1);  color: var(--success); }
.fu.cold    { background: rgba(80,70,65,.08);  color: var(--muted); }

/* ── Days badge ────────────────────────────────── */
.days-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.days-green  { background: rgba(47,143,91,.1);  color: var(--success); }
.days-yellow { background: rgba(216,146,45,.12); color: var(--warning); }
.days-orange { background: rgba(198,84,69,.1);  color: #c47030; }
.days-red    { background: rgba(198,84,69,.15); color: var(--danger); }

/* ── Clickable rows ────────────────────────────── */
.clickable-row { cursor: pointer; transition: background .15s; }
.clickable-row:hover { background: rgba(141,91,59,.05); }
.clickable-cell { cursor: pointer; }
.client-name-link { color: var(--primary-strong); font-weight: 600; }
.clickable-row:hover .client-name-link { text-decoration: underline; }
.clickable-cell:hover .client-name-link { text-decoration: underline; }
.client-list-item { cursor: pointer; transition: background .15s; }
.client-list-item:hover { background: rgba(141,91,59,.07) !important; }
.cli-name { font-weight: 600; font-size: 13px; }

/* ── Client detail view ────────────────────────── */
.detail-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

.detail-contact-card,
.detail-followup-card {
  min-height: 180px;
}

.contact-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.contact-avatar {
  width: 52px;
  height: 52px;
  min-width: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  font-weight: 800;
  font-size: 18px;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(109,64,39,.22);
}

.contact-main { flex: 1; min-width: 0; }

.contact-name {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.3;
  word-break: break-word;
}

.contact-vat {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.contact-fields {
  display: grid;
  gap: 8px;
}

.cf {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.cf:last-child { border-bottom: none; }
.cf span { color: var(--muted); font-weight: 600; white-space: nowrap; }
.cf strong { text-align: right; word-break: break-word; }
.cf a { text-decoration: none; }
.cf a:hover { text-decoration: underline; }

/* ── Follow-up card internals ──────────────────── */
.fu-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.fu-stat {
  padding: 10px 12px;
  background: rgba(141,91,59,.04);
  border-radius: 12px;
}
.fu-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.fu-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  font-weight: 800;
}

.fu-alert {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(198,84,69,.08);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.fu-alert-soft {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(216,146,45,.08);
  color: var(--warning);
  font-size: 13px;
}

/* ── Order history ─────────────────────────────── */
.order-history {
  display: grid;
  gap: 6px;
  max-height: 600px;
  overflow-y: auto;
  padding-right: 2px;
}

.order-row {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.order-row-header {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,.6);
}

.order-row.expandable .order-row-header {
  cursor: pointer;
}
.order-row.expandable .order-row-header:hover {
  background: rgba(141,91,59,.04);
}

.order-ref {
  font-weight: 700;
  font-size: 14px;
  color: var(--primary-strong);
}

.order-date {
  color: var(--muted);
  font-size: 13px;
}

.order-total {
  font-weight: 800;
  font-size: 14px;
}

.toggle-icon {
  color: var(--muted);
  font-size: 10px;
  transition: transform .2s;
}

.order-lines {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
  background: rgba(251,248,245,.8);
}
.order-lines.open { display: block; }

.lines-table {
  width: 100%;
  min-width: unset;
  margin-top: 8px;
  font-size: 13px;
}

.lines-table th {
  font-size: 11px;
  padding: 8px 8px;
}

.lines-table td {
  padding: 7px 8px;
}

.detail-loading {
  color: var(--muted);
  font-size: 14px;
  padding: 1.5rem;
  text-align: center;
}

.button.small, .ghost-btn.small {
  padding: 8px 14px;
  font-size: 13px;
}

@media (max-width: 980px) {
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .order-row-header {
    grid-template-columns: 1fr auto auto;
    flex-wrap: wrap;
  }
  .fu-stats-grid { grid-template-columns: 1fr; }
}

/* ── Sort headers ───────────────────────────── */
.th-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.th-sortable:hover { color: var(--primary); }

.sort-arrow {
  font-size: 10px;
  color: var(--muted);
  margin-left: 3px;
  opacity: 0.5;
}
.sort-arrow.active {
  color: var(--primary);
  opacity: 1;
}

/* ── Notes panel ────────────────────────────── */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 1rem 1.25rem 0.5rem;
}

.notes-empty {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  padding: 0.25rem 0;
}

.note-item {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 12px;
}

.note-author {
  font-weight: 600;
  color: var(--primary);
}

.note-date {
  color: var(--muted);
  flex: 1;
}

.note-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
  border-radius: 3px;
}
.note-delete:hover { color: var(--danger); background: #fee2e2; }

.note-text {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
}

.notes-input-row {
  display: flex;
  gap: 10px;
  padding: 0.75rem 1.25rem 1.25rem;
  align-items: flex-end;
}

.note-textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 62px;
  background: var(--panel-strong);
  color: var(--text);
}
.note-textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }

.note-save-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.note-save-btn:hover { background: var(--primary-strong); }

/* ── Client status rows ─────────────────────── */
.cs-row-esperando  { background: rgba(217, 119, 6, 0.08); }
.cs-row-pedido     { background: rgba(47, 143, 91, 0.10); }
.cs-row-descartado { background: rgba(198, 84, 69, 0.08); opacity: 0.65; }

.cs-badge {
  border: none;
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.6;
  transition: filter 0.15s;
}
.cs-badge:hover { filter: brightness(0.9); }
.cs-badge.cs-none       { background: var(--border); color: var(--muted); }
.cs-badge.cs-esperando  { background: #fef3c7; color: #92400e; }
.cs-badge.cs-pedido     { background: #d1fae5; color: #065f46; }
.cs-badge.cs-descartado { background: #fee2e2; color: #991b1b; }

/* ── Search input ───────────────────────────── */
.panel-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--panel-strong);
  color: var(--text);
  width: 220px;
}
.search-input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ── Pagination ─────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.page-btn {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.page-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
}
.page-btn:disabled { opacity: 0.4; cursor: default; }

.page-info { font-size: 13px; color: var(--muted); }
