:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e7;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --ok: #15803d;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1d2027;
    --surface-2: #262a33;
    --border: #333844;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --primary: #818cf8;
    --primary-text: #0f1020;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0.2rem 0 1rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.pre-line { white-space: pre-line; margin: 0; }
.danger { color: var(--danger) !important; }
.vencida { color: var(--danger); font-weight: 600; }

/* --- Layout --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topnav { display: flex; gap: 0.25rem; flex: 1; overflow-x: auto; }
.topnav a { padding: 0.4rem 0.7rem; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.topnav a:hover { background: var(--surface-2); text-decoration: none; }
.topnav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; }
.topbar-user a { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.container.wide { max-width: none; }

.page-header, .project-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header .actions { display: flex; gap: 0.5rem; }
.breadcrumb { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.breadcrumb a { color: var(--muted); }

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  overflow-x: auto;
}
.tabs a {
  padding: 0.55rem 0.9rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.panel-header h3 { margin: 0; }
.panel-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.danger-row { display: flex; justify-content: space-between; align-items: center; gap: 1.5rem; padding: 0.75rem 0; flex-wrap: wrap; }
.danger-row + .danger-row { border-top: 1px solid var(--border); }
.danger-row p { margin: 0.2rem 0 0; }

.collapsible > summary { cursor: pointer; font-weight: 600; }
.collapsible[open] > summary { margin-bottom: 1rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* --- Formularios --- */
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.stack > label, .stack label:not(.check):not(.tag-option) { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 500; font-size: 0.9rem; }
.inline-form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inline-form label { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 0.4rem; font-weight: normal; }

input[type="text"], input[type="password"], input[type="email"], input[type="search"],
input[type="number"], input[type="date"], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
textarea { resize: vertical; width: 100%; }
input[disabled] { opacity: 0.6; }
input[type="color"] { width: 2.2rem; height: 2.2rem; padding: 0.15rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; }
.input-sm { width: 5rem; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 500; font-size: 0.9rem; margin-bottom: 0.4rem; padding: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font: inherit;
  font-weight: 500;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 85%, black); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, black); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.btn-icon { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0.15rem 0.35rem; border-radius: 4px; font-size: 0.8rem; }
.btn-icon:hover:not([disabled]) { background: var(--surface-2); color: var(--text); }
.btn-icon[disabled] { opacity: 0.3; cursor: default; }
summary.btn, summary.btn-link { list-style: none; }
summary::-webkit-details-marker { display: none; }

.flash { padding: 0.65rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.flash-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* --- Badges / avatares --- */
.badge, .tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
  vertical-align: middle;
}
.badge-outline { border: 1px solid; background: transparent; }
.badge-muted { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.tag { border-radius: 4px; font-weight: 500; }
.row-badges { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.25rem; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 0.65rem; }

/* --- Proyectos --- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.project-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.project-card:hover { border-color: var(--primary); text-decoration: none; }
.project-card h3 { margin-bottom: 0.35rem; }
.project-card p { margin: 0 0 0.75rem; font-size: 0.9rem; }
.project-stats { display: flex; gap: 1rem; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }

.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[type="search"] { flex: 1; min-width: 200px; max-width: 360px; }

/* --- Tablero --- */
.board {
  display: flex;
  gap: 0.9rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  align-items: flex-start;
}
.column {
  flex: 0 0 280px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 230px);
}
.column-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.2rem 0.3rem 0.6rem; }
.column-header h3 { margin: 0; font-size: 0.95rem; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.count { font-size: 0.8rem; color: var(--muted); background: var(--surface); padding: 0 0.5rem; border-radius: 999px; }
.column-list { list-style: none; margin: 0; padding: 0; min-height: 40px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.column-more { font-size: 0.8rem; padding: 0.5rem 0.3rem 0; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  cursor: grab;
  box-shadow: var(--shadow);
}
.card:active { cursor: grabbing; }
.card-ghost { opacity: 0.4; }
.card-title { display: block; color: var(--text); font-weight: 500; line-height: 1.35; word-break: break-word; }
.card-badges { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.4rem; }
.card-meta { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.45rem; font-size: 0.78rem; color: var(--muted); flex-wrap: wrap; }
.card-meta:empty { display: none; }

.quick-add { margin-top: 0.5rem; }
.quick-add summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; padding: 0.3rem; border-radius: 4px; list-style: none; }
.quick-add summary:hover { background: var(--surface); color: var(--text); }
.quick-add form { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.4rem; }

/* --- Tablas --- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }

/* --- Tarea --- */
.task-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.task-layout .panel { margin-bottom: 0; }
.task-layout > .stack { gap: 1rem; }
.task-title h1 { margin-bottom: 0.4rem; word-break: break-word; }
.task-title { margin-bottom: 1rem; }
.edit-toggle { margin-top: 1rem; }
.edit-toggle[open] > summary { margin-bottom: 0.75rem; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag-picker legend { width: 100%; }
.tag-option { display: flex; align-items: center; gap: 0.25rem; cursor: pointer; }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 0.75rem; }
.progress > div { height: 100%; background: var(--ok); transition: width 0.2s; }
.checklist { list-style: none; margin: 0 0 0.75rem; padding: 0; }
.checklist li { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.checklist label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; flex: 1; }
.checklist li.hecho span { text-decoration: line-through; color: var(--muted); }
.checklist .inline-form input[type="text"], .inline-form input[type="text"] { flex: 1; min-width: 160px; }

.comments { list-style: none; margin: 0 0 1rem; padding: 0; }
.comments > li { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.comment-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.push-right { margin-left: auto; }

/* --- Archivos --- */
.upload { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; padding: 0.75rem; border: 1px dashed var(--border); border-radius: var(--radius); }
.files { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; }
.file { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.file-preview { display: flex; align-items: center; justify-content: center; height: 130px; background: var(--surface-2); }
.file-preview img { width: 100%; height: 100%; object-fit: cover; }
.file-ext { font-weight: 700; color: var(--muted); font-size: 1.2rem; }
.file-info { padding: 0.5rem 0.65rem; font-size: 0.9rem; }
.file-name { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 0.75rem; margin-top: 0.3rem; }

/* --- Listas varias --- */
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.link-list li:last-child { border-bottom: 0; }
.settings-list, .catalog { list-style: none; margin: 0 0 1rem; padding: 0; }
.settings-list li, .catalog li { display: flex; align-items: center; gap: 0.75rem; padding: 0.45rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.settings-list li > span:not(.avatar) { flex: 1; }
.catalog-order { display: flex; flex-direction: column; }
.catalog-delete { margin-left: auto; }
.catalog-delete[open] { flex-basis: 100%; padding: 0.5rem 0; }
.catalog-delete summary { cursor: pointer; list-style: none; display: inline; }
.catalog-delete form { margin-top: 0.5rem; }
.info-list { margin: 0.75rem 0 0; padding-left: 1.1rem; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 0.65rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.pager { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }

/* --- Markdown --- */
.markdown { word-wrap: break-word; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown img { max-width: 100%; border-radius: 6px; }
.markdown pre { background: var(--surface-2); padding: 0.75rem 1rem; border-radius: 6px; overflow-x: auto; }
.markdown code { background: var(--surface-2); padding: 0.1rem 0.3rem; border-radius: 4px; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--border); color: var(--muted); }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 0.35rem 0.6rem; }
.markdown ul:has(input[type="checkbox"]) { list-style: none; padding-left: 0.5rem; }

/* --- Login --- */
.login { max-width: 360px; margin: 12vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }
.login h1 { text-align: center; }

@media (max-width: 800px) {
  .task-layout { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .topbar { gap: 0.75rem; padding: 0 0.75rem; }
  .container { padding: 1rem 0.75rem 3rem; }
  .column { flex-basis: 85vw; max-height: none; }
}
