/* ==================================================================
   Gestor de Proyectos — hoja de estilos única
   ================================================================== */

:root {
  --bg:            #f4f6f9;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --surface-sunk:  #eef1f6;
  --text:          #131720;
  --text-muted:    #667085;
  --text-faint:    #98a2b3;
  --border:        #e3e7ee;
  --border-strong: #cfd6e2;
  --accent:        #2563eb;
  --accent-soft:   #e5edff;
  --accent-text:   #1d4ed8;
  --danger:        #dc2626;
  --danger-soft:   #fee2e2;
  --warn:          #b45309;
  --warn-soft:     #fef3c7;
  --ok:            #047857;
  --ok-soft:       #d1fae5;
  --shadow-sm:     0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-md:     0 4px 12px rgba(16, 24, 40, .08);
  --shadow-lg:     0 18px 48px rgba(16, 24, 40, .22);
  --radius:        10px;
  --sidebar-w:     272px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0d1016;
    --surface:       #161a22;
    --surface-2:     #1b2029;
    --surface-sunk:  #11151c;
    --text:          #e6e9ef;
    --text-muted:    #97a0b0;
    --text-faint:    #6b7484;
    --border:        #262c38;
    --border-strong: #333b4a;
    --accent:        #4f86f7;
    --accent-soft:   #1a2740;
    --accent-text:   #8ab0ff;
    --danger:        #f26d6d;
    --danger-soft:   #3a1d1d;
    --warn:          #e0a34a;
    --warn-soft:     #392b16;
    --ok:            #4ec994;
    --ok-soft:       #14332a;
    --shadow-sm:     0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md:     0 4px 14px rgba(0, 0, 0, .45);
    --shadow-lg:     0 18px 48px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Inter", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.app-root { height: 100%; }
.boot { display: grid; place-items: center; height: 100%; color: var(--text-muted); }

/* ------------------------------------------------------------------
   Controles base
   ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-text); border-color: var(--accent-text); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-sunk); border-color: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
.select { appearance: none; padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------
   Login
   ------------------------------------------------------------------ */

.login-screen {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 65%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 30px 28px;
}
.login-card h1 { margin: 14px 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }
.login-logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 17px;
}
.login-error {
  margin-top: 12px; padding: 9px 11px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* ------------------------------------------------------------------
   Estructura
   ------------------------------------------------------------------ */

.shell { display: grid; grid-template-rows: 54px 1fr; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
}
.identity {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 5px 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.identity .select { border: none; background: transparent; padding: 2px 22px 2px 4px; height: 26px; }
.identity .select:focus { box-shadow: none; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}

.sidebar {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.sidebar-head { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 9px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 0 8px 10px; }
.sidebar-foot { padding: 9px 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

.sidebar-label {
  padding: 12px 6px 5px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint);
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  color: var(--text);
  transition: background .1s;
}
.nav-item:hover { background: var(--surface-sunk); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count {
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--text-faint); background: var(--surface-sunk);
  padding: 1px 6px; border-radius: 999px;
}
.nav-item.active .count { background: var(--surface); color: var(--accent-text); }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.page-head {
  padding: 16px 22px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.page-title { display: flex; align-items: flex-start; gap: 12px; }
.page-title h1 { margin: 0; font-size: 19px; letter-spacing: -.015em; }
.page-title .sub { margin: 3px 0 0; font-size: 13px; color: var(--text-muted); }

.tabs { display: flex; gap: 2px; margin-top: 14px; }
.tab {
  padding: 8px 12px;
  border: none; background: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13px; font-weight: 550;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

.page-body { flex: 1; min-height: 0; overflow: auto; }
.page-pad { padding: 20px 22px 40px; }

.toolbar {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 11px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.toolbar .input { padding: 5px 9px; font-size: 13px; }
/* Se conserva el hueco derecho para que la flecha no pise el texto. */
.toolbar .select { padding: 5px 26px 5px 9px; font-size: 13px; }
.toolbar .search { width: 210px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.check input { accent-color: var(--accent); }

/* ------------------------------------------------------------------
   Badges
   ------------------------------------------------------------------ */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--surface-sunk); color: var(--text-muted);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-ok     { background: var(--ok-soft);     color: var(--ok); }
.badge-warn   { background: var(--warn-soft);   color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700; color: #fff;
  flex: none; letter-spacing: .02em;
}
.avatar-lg { width: 28px; height: 28px; font-size: 12px; }

.prio { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.prio-alta  { background: var(--danger); }
.prio-media { background: var(--warn); }
.prio-baja  { background: var(--text-faint); }

.progress { height: 5px; border-radius: 999px; background: var(--surface-sunk); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .25s; }

/* ------------------------------------------------------------------
   Tablero kanban
   ------------------------------------------------------------------ */

.board {
  display: flex; gap: 13px;
  padding: 16px 22px 22px;
  height: 100%;
  align-items: stretch;
  overflow-x: auto;
}
.column {
  flex: 1 1 275px;
  min-width: 258px; max-width: 420px;
  display: flex; flex-direction: column;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 0;
}
.column.drop-target { border-color: var(--accent); background: var(--accent-soft); }
.column-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 8px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
}
.column-head .marker { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.column-head .count { margin-left: auto; font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.column-body {
  flex: 1; min-height: 40px;
  overflow-y: auto;
  padding: 0 9px 9px;
  display: flex; flex-direction: column; gap: 8px;
}
.column-foot { padding: 0 9px 9px; }
.column-empty {
  padding: 16px 8px; text-align: center;
  font-size: 12px; color: var(--text-faint);
  border: 1px dashed var(--border-strong); border-radius: 9px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px 8px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  /* "manipulation" deja pasar el scroll vertical del dedo; el arrastre táctil
     se activa con pulsación larga y bloquea el scroll desde JS. */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.card-top { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.card-project { font-size: 11px; font-weight: 600; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { font-size: 13.5px; font-weight: 550; line-height: 1.4; overflow-wrap: anywhere; }
.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.card.done .card-title { color: var(--text-muted); text-decoration: line-through; text-decoration-color: var(--text-faint); }

.card.dragging { opacity: .35; }
.card-ghost {
  position: fixed; z-index: 900;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  transform: rotate(1.5deg) scale(1.02);
  cursor: grabbing;
  opacity: .97;
}
.card-placeholder {
  border: 1.5px dashed var(--accent);
  border-radius: 9px;
  background: var(--accent-soft);
  flex: none;
}
body.is-dragging { cursor: grabbing; }
body.is-dragging * { cursor: grabbing !important; }

/* ------------------------------------------------------------------
   Resumen / tarjetas de proyecto
   ------------------------------------------------------------------ */

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 13px 15px;
}
.stat .k { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.stat .v { font-size: 25px; font-weight: 680; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat.alert .v { color: var(--danger); }

.section-title {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 11px; font-size: 14px; font-weight: 650;
}

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 13px; }
.project-card {
  display: flex; flex-direction: column; gap: 9px;
  padding: 14px 15px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; text-align: left;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.project-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.project-card h3 { margin: 0; font-size: 14.5px; font-weight: 620; letter-spacing: -.01em; }
.project-card .client { font-size: 12px; color: var(--text-muted); }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.detail-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; }
.detail-item .k { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.detail-item .v { margin-top: 4px; font-size: 14px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }

.empty-state {
  display: grid; place-items: center; gap: 10px;
  padding: 56px 20px; text-align: center; color: var(--text-muted);
}
.empty-state h2 { margin: 0; font-size: 16px; color: var(--text); }
.empty-state p { margin: 0; max-width: 380px; font-size: 13px; }

/* ------------------------------------------------------------------
   Bitácora
   ------------------------------------------------------------------ */

.note-composer { display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.note-list { display: flex; flex-direction: column; gap: 10px; }
.note {
  display: grid; grid-template-columns: auto 1fr; gap: 11px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
}
.note-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.note-author { font-weight: 620; font-size: 13px; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13.5px; }

/* ------------------------------------------------------------------
   Modales
   ------------------------------------------------------------------ */

.backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(10, 14, 22, .48);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 20px;
  overflow-y: auto;
}
.modal {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: pop .13s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15.5px; font-weight: 650; }
.modal-body { padding: 17px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 13px; }
.modal-foot {
  display: flex; align-items: center; gap: 9px;
  padding: 13px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 14px 14px;
}
.modal-error { padding: 8px 11px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

.member-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.member-row:last-of-type { border-bottom: none; }
.color-input { width: 34px; height: 32px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer; }

/* ------------------------------------------------------------------
   Toasts
   ------------------------------------------------------------------ */

.toast-root {
  position: fixed; z-index: 800; bottom: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  padding: 9px 14px; border-radius: 9px;
  background: #1f2733; color: #f4f6fa;
  font-size: 13px; box-shadow: var(--shadow-lg);
  animation: pop .13s ease-out;
  max-width: 340px;
}
.toast.error { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------ */

.menu-toggle { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 54px; bottom: 0; left: 0; width: var(--sidebar-w);
    z-index: 30; box-shadow: var(--shadow-lg);
    transform: translateX(-100%); transition: transform .16s ease-out;
  }
  .sidebar.open { transform: none; }
  .sidebar-scrim { position: fixed; inset: 54px 0 0; z-index: 25; background: rgba(10, 14, 22, .4); }
  .page-pad, .toolbar, .page-head { padding-left: 14px; padding-right: 14px; }
  .board { padding-left: 14px; padding-right: 14px; }
  .brand .brand-text { display: none; }
}

@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  .toolbar .search { width: 100%; }
  .column { min-width: 84vw; }
}
