/* Misma base visual que Facturación (App Facturas/public/css/app.css): colores, barra lateral, tarjetas,
   botones, formularios, tablas, etiquetas, ventanas y avisos. Al final, lo propio de las tareas. */
:root {
  --bg: #f3f7f4;
  --surface: #ffffff;
  --surface-2: #f7faf8;
  --border: #dce5e0;
  --text: #17202c;
  --muted: #627080;
  /* Verdes de Mantejardin: los mismos del portal y de Facturación */
  --accent: #123d30;
  --accent-soft: #e5f4de;
  --accent-on: #ffffff;
  --accent-lime: #97df70;
  --ok: #157a4a;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #b4232f;
  --danger-soft: #fbe6e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
  --sidebar: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1a15;
    --surface: #13241d;
    --surface-2: #172b23;
    --border: #20362c;
    --text: #e6ebf1;
    --muted: #94a1b2;
    --accent: #97df70;
    --accent-soft: #1c3a2d;
    --accent-on: #123d30;
    --ok: #4cc38a;
    --ok-soft: #15301f;
    --warn: #f0b34e;
    --warn-soft: #33270f;
    --danger: #f2727b;
    --danger-soft: #3a1a1e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* Layout */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; font-weight: 700; }
.brand img { width: 30px; height: 30px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
.company-switch { margin: 0 4px 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: .78rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav a.active .count { color: inherit; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.sidebar .user-box { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); font-size: .85rem; }
.main { padding: 24px 28px 80px; min-width: 0; max-width: 1040px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-title h2 { margin: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  min-height: 38px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px; font-size: 1.1rem; line-height: 1; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: .3; cursor: default; background: transparent; color: var(--muted); }
.icon-btn svg { width: 16px; height: 16px; display: block; }

/* Forms */
label { display: block; font-size: .83rem; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; min-height: 38px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; font-weight: 400; margin: 0; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid > * { grid-column: span 12; }
.span-4 { grid-column: span 4 !important; }
.span-6 { grid-column: span 6 !important; }
.span-8 { grid-column: span 8 !important; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.hint svg { width: 13px; height: 13px; vertical-align: -2px; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 4px 0 -2px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { width: auto; flex: 0 1 auto; }
.filters input[type=search] { flex: 1 1 220px; min-width: 160px; }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: .88rem; }
.notice.info { background: var(--accent-soft); color: var(--accent); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 440px; padding: 28px; }
.auth h1 { text-align: center; }
.auth .brand { justify-content: center; font-size: 1.1rem; }

/* Modal & toasts */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.lg { max-width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; font-size: .9rem; }
.toast.error { background: var(--danger); color: #fff; }
.fab { display: none; }
.drawer-bg { display: none; }

/* ---------- Tareas ---------- */
.task-card { padding: 8px 10px; }
.task-card + .task-card { margin-top: 10px; }
ul.tree, ul.subtasks { list-style: none; margin: 0; padding: 0; }
/* Cada nivel de subtareas se sangra y lleva una guía vertical */
ul.subtasks { margin-left: 14px; padding-left: 10px; border-left: 1px solid var(--border); }
.task-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px; border-radius: 8px; }
.task-row:hover { background: var(--surface-2); }
.tw { width: 20px; height: 24px; flex: none; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; display: grid; place-items: center; border-radius: 4px; }
button.tw:hover { color: var(--accent); background: var(--accent-soft); }
.tw svg { width: 14px; height: 14px; transition: transform .15s; }
.tw[aria-expanded=true] svg { transform: rotate(90deg); }
.task-row input[type=checkbox] { width: 18px; height: 18px; margin: 3px 0 0; flex: none; cursor: pointer; }
.task-body { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.root > .task-row .task-title { font-weight: 600; font-size: 1.03rem; }
.task.done > .task-row .task-title { text-decoration: line-through; color: var(--muted); }
.task-notes {
  color: var(--muted); font-size: .88rem; white-space: pre-line; overflow-wrap: anywhere; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.task-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.task-meta:empty { display: none; }
.task-actions { display: flex; gap: 0; flex: none; }
@media (hover: hover) {
  .task-actions { opacity: 0; }
  .task-row:hover .task-actions, .task-row:focus-within .task-actions { opacity: 1; }
}
.quick { display: flex; gap: 6px; align-items: center; padding: 6px 6px 6px 34px; }
.quick input { flex: 1; min-width: 0; }
.share-users { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.task-info { font-size: .8rem; color: var(--muted); margin-top: 12px; }
textarea.notes { min-height: 150px; }

/* Responsive */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 40; height: 100%;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.drawer-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.drawer-open .drawer-bg { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .topbar .title { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar button { border: 0; background: transparent; color: var(--text); padding: 6px; cursor: pointer; }
  .topbar svg { width: 24px; height: 24px; }
  .main { padding: 16px 12px 96px; }
  .form-grid > [class*=span-] { grid-column: span 12 !important; }
  .page-head h1 { font-size: 1.25rem; }
  .page-head .actions .btn.primary[data-new] { display: none; }
  .fab {
    display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
    width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-on); font-size: 28px;
    box-shadow: 0 6px 18px rgba(18, 61, 48, .4); z-index: 20; border: 0; cursor: pointer;
  }
  /* Tablas como tarjetas */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 8px 12px; background: var(--surface); }
  table.responsive td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
  table.responsive td.primary { font-weight: 600; font-size: 1rem; text-align: left; }
  table.responsive td.primary::before { display: none; }
  .card.flat-mobile { background: transparent; border: 0; box-shadow: none; padding: 0; }
  #toasts { left: 16px; right: 16px; bottom: 86px; }
  .modal { padding: 16px; }
  ul.subtasks { margin-left: 9px; padding-left: 6px; }
  .task-row { gap: 6px; padding: 6px 2px; }
  .task-actions [data-up], .task-actions [data-down] { display: none; }
  .quick { padding-left: 28px; }
}

@media print {
  .sidebar, .topbar, .fab, .actions, .filters, .task-actions { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
}

/* ---------- Tarjetas por cliente ---------- */
.main.wide { max-width: none; }
/* Varias tarjetas a la vez en pantallas anchas; en el móvil, una debajo de otra */
#list { columns: 380px; column-gap: 14px; }
#list > .card { break-inside: avoid; margin: 0 0 14px; }
.task-card.root > .task-row { padding-bottom: 8px; }
.task-card.root > .task-row .task-actions { opacity: 1; }
ul.subtasks.first { margin-left: 0; padding-left: 0; border-left: 0; border-top: 1px solid var(--border); padding-top: 4px; }
.quick.add-task { padding: 6px 6px 4px 6px; }
.quick.add-task input { border-style: dashed; background: transparent; }
.quick.add-task input:focus { border-style: solid; background: var(--surface); }
a.badge:hover { text-decoration: underline; }
.client-picker { margin-top: 6px; min-height: 150px; padding: 4px; }
.client-picker option { padding: 5px 8px; border-radius: 6px; }
.kind-options { display: flex; gap: 22px; flex-wrap: wrap; }
.kind-options input, .bill-list input { width: auto; min-height: 0; accent-color: var(--accent); }
.bill-list { display: grid; gap: 8px; max-height: 44vh; overflow-y: auto; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.bill-list .check { align-items: flex-start; }
.bill-list .check input { margin-top: 3px; }
.bill-list .done-text { text-decoration: line-through; color: var(--muted); }
.notice a { color: inherit; text-decoration: underline; }
