/* Tema oscuro por defecto; el claro se activa con data-theme="light". */
:root {
  --bg: #0f1113;
  --surface: #171a1d;
  --surface-2: #1f2327;
  --border: #2a2f34;
  --text: #e8e6e1;
  --text-muted: #8f959b;
  --accent: #e2b04a;
  --danger: #e5646b;
  --ok: #5cbf8a;

  --font-title: "Outfit", "Hanken Grotesk", system-ui, sans-serif;
  --font-sans: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

:root[data-theme="light"] {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece6;
  --border: #ddd8cf;
  --text: #1b1d1f;
  --text-muted: #6b7076;
  --accent: #b5841f;
  --danger: #c2414a;
  --ok: #2f8f5b;
}

* { box-sizing: border-box; }

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

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
  padding: 0 10px 20px;
}
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--surface-2); color: var(--text); }

.nav-count {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 0 7px;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}
.clock { font-family: var(--font-mono); margin-right: auto; }
.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 6px;
}
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: inherit;
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  cursor: pointer;
}
.user { color: var(--text); }

.content { padding: 28px 24px; }
.page-title {
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 20px;
}

.flash {
  margin: 16px 24px 0;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.flash-error { border-color: var(--danger); }
.flash-ok { border-color: var(--ok); }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
}

/* Utilidades */
.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); font-size: 13px; }
.inline-form { display: inline; margin: 0; }
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}
.link-button:hover { color: var(--text); }
a { color: var(--accent); }

/* Tarjetas, botones y formularios */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1b1d1f; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { background: none; border-color: var(--danger); color: var(--danger); }

.form-card { max-width: 520px; padding: 22px; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-muted); }
.field input, .field select {
  width: 100%;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; gap: 8px; align-items: center; }
.fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px 14px; display: grid; gap: 12px; margin: 0; }
.fieldset legend { font-size: 13px; color: var(--text-muted); padding: 0 6px; }
.form-actions { display: flex; gap: 10px; }
.danger-zone { margin-top: 24px; }
.toolbar { margin-bottom: 16px; }

/* Tablas */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; }
.table .is-inactive td { color: var(--text-muted); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border); color: var(--text-muted); }
.badge-ok { border-color: var(--ok); color: var(--ok); }

/* Pantalla de ingreso */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: grid; gap: 16px; }
.login-card .brand { padding: 0; font-size: 24px; gap: 14px; }
.login-card .brand-logo { width: 52px; height: 52px; border-radius: 13px; }

/* Campo de contraseña con botón para mostrarla */
.field > .password-field { display: block; position: relative; font-size: inherit; color: inherit; }
.password-field input { padding-right: 44px; }
.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.password-toggle:hover { color: var(--text); background: var(--surface-2); }
.password-toggle:focus-visible { outline: 2px solid var(--accent); }
.password-toggle .icon-hide { display: none; }
.password-toggle[aria-pressed="true"] .icon-show { display: none; }
.password-toggle[aria-pressed="true"] .icon-hide { display: block; }
.login-card p { margin: 0; }
.login-card .flash { margin: 0; }

/* Formularios anchos en dos columnas */
.form-wide { max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-full { grid-column: 1 / -1; }
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
.field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Barra de búsqueda y filtros */
.toolbar-split { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.search { display: flex; gap: 8px; flex: 1; max-width: 480px; }
.search input {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--surface-2); color: var(--text); }
.tab-count { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-left: 4px; }
.row-link { color: var(--text); font-weight: 500; text-decoration: none; }
.row-link:hover { color: var(--accent); }
.empty { color: var(--text-muted); padding: 24px 0; }

/* Estados de cliente */
.badge-active { border-color: var(--ok); color: var(--ok); }
.badge-demo { border-color: var(--accent); color: var(--accent); }
.badge-inactive { color: var(--text-muted); }

/* Resumen de Inicio */
.section-title {
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 12px;
}
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { display: grid; gap: 2px; padding: 16px 18px; text-decoration: none; color: var(--text); }
.stat:hover { border-color: var(--text-muted); }
.stat-value { font-family: var(--font-mono); font-size: 28px; font-weight: 500; }
.stat-label { color: var(--text-muted); font-size: 14px; }

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .search { max-width: none; }
}

/* Utilidades de vencimientos */
.small { font-size: 13px; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.row-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.home-block { margin-bottom: 28px; }

/* Selector Lista / Calendario */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.segment { padding: 5px 14px; border-radius: 6px; color: var(--text-muted); text-decoration: none; font-size: 14px; }
.segment.is-active { background: var(--surface-2); color: var(--text); }

/* Avisos */
.alert-summary {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 500;
}
.alert-overdue { color: var(--danger); }
.alert-soon { color: var(--accent); }
.badge-overdue { border-color: var(--danger); color: var(--danger); }
.badge-soon { border-color: var(--accent); color: var(--accent); }
.badge-paid { border-color: var(--ok); color: var(--ok); }
.due-row.due-paid td { color: var(--text-muted); }
.stat-danger .stat-value { color: var(--danger); }
.stat-warning .stat-value { color: var(--accent); }

/* Calendario */
.calendar-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.calendar-head .section-title { margin: 0; min-width: 180px; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow: hidden; }
.calendar-weekday {
  padding: 8px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.calendar-day {
  min-height: 104px;
  padding: 6px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.calendar-day:nth-child(7n) { border-right: 0; }
.calendar-day.is-other-month { background: var(--bg); }
.calendar-day.is-other-month .calendar-date { opacity: .45; }
.calendar-date { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); padding: 2px 4px; }
.calendar-day.is-today .calendar-date { color: var(--bg); background: var(--accent); border-radius: 4px; align-self: flex-start; font-weight: 500; }
.calendar-weekday-inline { display: none; }
.chip {
  display: block;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  border-left: 3px solid var(--text-muted);
  background: var(--surface-2);
  color: var(--text);
}
.chip-overdue, .chip-today { border-left-color: var(--danger); }
.chip-soon { border-left-color: var(--accent); }
.chip-paid { border-left-color: var(--ok); color: var(--text-muted); text-decoration: line-through; }
a.chip:hover { filter: brightness(1.15); }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.legend .chip { display: inline-block; }

@media (max-width: 760px) {
  /* En el celular el calendario pasa a ser una lista de días con vencimientos. */
  .calendar { grid-template-columns: 1fr; }
  .calendar-weekday, .calendar-day.is-empty, .calendar-day.is-other-month { display: none; }
  .calendar-day { min-height: 0; border-right: 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .calendar-weekday-inline { display: inline; }
  .calendar-date { min-width: 64px; }
  .calendar-head .section-title { min-width: 0; }
  .row-actions { justify-content: flex-start; }
}

/* Tablero de tareas */
.text-danger { color: var(--danger); }
.board-hint { margin: -4px 0 14px; }
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.board-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  min-height: 200px;
  transition: border-color .15s, background .15s;
}
.board-column.is-over { border-color: var(--accent); background: var(--surface-2); }
.board-column-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 10px; }
.board-column-head h2 { font-family: var(--font-title); font-weight: 600; font-size: 16px; margin: 0; }
.board-column-head .tab-count { margin-left: 0; }
.column-add {
  margin-left: auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 18px;
}
.column-add:hover { background: var(--surface-2); color: var(--text); }
.board-list { display: grid; gap: 8px; min-height: 60px; }
.board-list:not(:has(.task-card))::after {
  content: "Sin tareas";
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 18px 0;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.board-note { margin: 10px 4px 0; }
.task-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}
.task-card[draggable="true"] { cursor: grab; }
.task-card.is-dragging { opacity: .5; }
.task-card.priority-high { border-left-color: var(--danger); }
.task-card.priority-medium { border-left-color: var(--accent); }
.task-card.priority-low { border-left-color: var(--ok); }
[data-column="done"] .task-card { opacity: .7; }
[data-column="done"] .task-title { text-decoration: line-through; }
.task-title { color: var(--text); font-weight: 500; text-decoration: none; line-height: 1.35; }
.task-title:hover { color: var(--accent); }
.task-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.task-client { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.task-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.task-foot svg { vertical-align: -2px; }
.badge-priority-high { border-color: var(--danger); color: var(--danger); }
.badge-priority-medium { border-color: var(--accent); color: var(--accent); }
.badge-priority-low { border-color: var(--ok); color: var(--ok); }

/* Detalle de tarea */
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.detail-main { display: grid; gap: 16px; }
.detail-card { padding: 18px 20px; }
.detail-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.status-switch { justify-self: start; }
.status-switch .segment { border: 0; background: none; font: inherit; font-size: 14px; cursor: pointer; }
.status-switch .segment.is-active { background: var(--surface-2); color: var(--text); cursor: default; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; margin: 0; }
.facts dt { color: var(--text-muted); font-size: 13px; }
.facts dd { margin: 0; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.photo { margin: 0; display: grid; gap: 4px; }
.photo img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  background: var(--bg);
}
.upload-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; border-top: 1px solid var(--border); padding-top: 14px; }
.upload-form p { flex-basis: 100%; margin: 0; }
.upload-form input[type="file"] { color: var(--text-muted); font: inherit; font-size: 14px; max-width: 100%; }

@media (max-width: 900px) {
  .board { grid-template-columns: 1fr; }
  .board-column { min-height: 0; }
  .detail-layout { grid-template-columns: 1fr; }
}

/* Tipos de vencimiento */
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kind-new { margin-bottom: 16px; grid-template-columns: 1fr auto; align-items: end; }
.kind-rename { display: flex; gap: 8px; align-items: center; }
.kind-rename input {
  flex: 1;
  min-width: 0;
  max-width: 320px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.kind-rename input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
@media (max-width: 760px) {
  .kind-new { grid-template-columns: 1fr; }
}

/* Tableros: pestañas, completar con un clic y agregar rápido */
.board-tabs { margin-bottom: 12px; }
.task-head { display: flex; gap: 10px; align-items: flex-start; }
.task-check-form { margin: 0; flex-shrink: 0; }
.task-check {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  background: none;
  color: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.task-check:hover { border-color: var(--accent); color: var(--accent); }
.task-check.is-checked { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.task-check:disabled { opacity: .5; cursor: wait; }
.task-board {
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
}
.quick-add { display: grid; gap: 6px; margin-top: 10px; }
.quick-add-row { display: flex; gap: 6px; }
.quick-add input[type="text"], .quick-add select, .inline-select {
  min-width: 0;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.quick-add input[type="text"] { flex: 1; border-style: dashed; }
.quick-add input[type="text"]:focus, .quick-add select:focus, .inline-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-style: solid;
}
.inline-select { max-width: 220px; }

/* Calendario de pagos y cobros: montos en pesos */
.amount { font-family: var(--font-mono); white-space: nowrap; }
.amount-collection { color: var(--ok); }
.amount-payment { color: var(--text); }
.num { text-align: right; }
.badge-direction-collection { border-color: var(--ok); color: var(--ok); }
.badge-direction-payment { border-color: var(--text-muted); color: var(--text); }
.month-totals { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--text-muted); }
.month-totals strong { margin-left: 4px; font-weight: 500; }
.calendar .chip { display: grid; gap: 1px; white-space: normal; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-amount { font-family: var(--font-mono); font-size: 11px; white-space: nowrap; }
.chip-paid .chip-amount { color: inherit; }

/* Formulario: Pago o Cobro y monto */
.direction-choice { border: 0; padding: 0; margin: 0; min-width: 0; }
.direction-choice legend { font-size: 13px; color: var(--text-muted); padding: 0; margin-bottom: 6px; }
.radio-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radio-card {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.radio-card input { accent-color: var(--accent); }
.amount-field { position: relative; display: block; font-size: inherit; color: inherit; }
.field > .amount-field { font-size: inherit; color: inherit; }
.amount-prefix {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.amount-field input { padding-left: 26px; font-family: var(--font-mono); }
@media (max-width: 760px) {
  .radio-group { grid-template-columns: 1fr; }
}
