/* Portal de Obras — hoja de estilos única, sin dependencias */
:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1d2125;
  --ink-2: #4a5158;
  --muted: #78808a;
  --line: #e4e0d8;
  --line-2: #efece6;
  --accent: #d9822b;          /* ámbar de obra */
  --accent-ink: #8a4a0c;
  --accent-soft: #fbefe2;
  --primary: #23292f;
  --primary-ink: #ffffff;
  --ok: #2f7a4f;    --ok-soft: #e5f3ea;
  --warn: #9a6a00;  --warn-soft: #fbf2d9;
  --err: #b4352b;   --err-soft: #fbe7e5;
  --info: #2c5f8a;  --info-soft: #e6eff7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(29, 33, 37, .05), 0 1px 1px rgba(29, 33, 37, .03);
  --sidebar: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181b; --surface: #1d2125; --surface-2: #22272b; --ink: #eceae6; --ink-2: #c4c7cb; --muted: #8f969d;
    --line: #2f353a; --line-2: #272c31; --accent: #e8954a; --accent-ink: #f3b47a; --accent-soft: #3a2a1b;
    --primary: #eceae6; --primary-ink: #15181b;
    --ok: #6cc391; --ok-soft: #1d3326; --warn: #e2b44c; --warn-soft: #362d14; --err: #ef8277; --err-soft: #3c1f1c;
    --info: #86b6e0; --info-soft: #1c2c3a; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.08rem; }
h3 { font-size: .98rem; }
p { margin: 0 0 .8em; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.wrap { white-space: normal; word-break: break-word; }
.grow { flex: 1; min-width: 0; }
small { display: block; }
.badge small, td small { display: block; }

/* ---------- Estructura ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: 0 0 var(--sidebar); background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: var(--primary-ink); font-size: .8rem; letter-spacing: .02em;
  box-shadow: inset 0 -3px 0 var(--accent);
}
.brand-mark.lg { width: 48px; height: 48px; font-size: 1.05rem; border-radius: 12px; box-shadow: inset 0 -4px 0 var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 16px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-link .ico { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 99px; font-size: .72rem; padding: 0 7px; }
.as-button { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.me:hover, .me.is-active { background: var(--surface-2); text-decoration: none; }
.me-text { min-width: 0; }
.me-text strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.me-text small { color: var(--muted); font-size: .78rem; }

.avatar {
  display: inline-grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-size: .78rem; font-weight: 600;
}
.avatar.lg { width: 60px; height: 60px; flex-basis: 60px; font-size: 1.2rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 28px clamp(16px, 3vw, 40px) 48px; max-width: 1240px; width: 100%; }
.content > * + * { margin-top: 20px; }

/* ---------- Encabezados de página ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head .muted { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.section-head, .card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2, .card-head h2 { margin: 0; }
.desc { color: var(--ink-2); max-width: 75ch; white-space: pre-line; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 760px; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat { color: var(--ink); padding: 16px 18px; }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat small { color: var(--muted); font-size: .8rem; }
.stat strong { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.stat-alert { border-color: var(--accent); background: var(--accent-soft); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.project-card { color: var(--ink); display: flex; flex-direction: column; gap: 4px; transition: border-color .15s; }
.project-card:hover { text-decoration: none; border-color: var(--accent); }
.project-card h3 { margin: 4px 0 0; font-size: 1.02rem; }
.project-card p { margin: 0; }
.pc-top { display: flex; justify-content: space-between; align-items: center; }
.pc-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line-2); padding-top: 10px; margin-top: 10px; flex-wrap: wrap; }
.code { font: 600 .75rem ui-monospace, Menlo, Consolas, monospace; color: var(--muted); letter-spacing: .03em; }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.list-row:first-child { border-top: 0; padding-top: 0; }
.list-row small { color: var(--muted); }
.list.compact li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line-2); font-size: .9rem; }
.list.compact li:first-child { border-top: 0; }
.file-ext {
  display: inline-grid; place-items: center; min-width: 42px; height: 26px; padding: 0 6px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line); font: 700 .66rem ui-monospace, Menlo, monospace; color: var(--ink-2);
}
.empty { text-align: center; padding: 28px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); }
.empty p { margin: 0 0 10px; }
.empty p:last-child { margin: 0; }

/* ---------- Insignias y chips ---------- */
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.rol-admin { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.rol-jefe { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.rol-trabajador { background: var(--info-soft); color: var(--info); border-color: transparent; }
.rol-lector { background: var(--surface-2); color: var(--muted); }
.est-activo { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.est-pendiente, .est-pausado { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.est-suspendido { background: var(--err-soft); color: var(--err); border-color: transparent; }
.est-cerrado { background: var(--surface-2); color: var(--muted); }
.act-login, .act-logout { background: var(--surface-2); }
.act-archivo { background: var(--info-soft); color: var(--info); border-color: transparent; }
.act-usuario, .act-miembro { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.act-proyecto, .act-carpeta { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chips, .perm-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { font-size: .78rem; padding: 2px 9px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }
.chip-strong { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.inline-dl { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 6px 0 0; }
.inline-dl dt { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.inline-dl dd { margin: 0; font-size: .92rem; }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px 20px; margin: 14px 0; }
.dl dt { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.dl dd { margin: 2px 0 0; }
.profile { display: flex; align-items: center; gap: 14px; }
.profile h1, .profile h2 { margin: 0; }
.profile p { margin: 2px 0; }
.person { display: flex; align-items: center; gap: 10px; }
.person small { color: var(--muted); }

/* ---------- Formularios ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: .86rem; font-weight: 600; color: var(--ink-2); }
.form label small { font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
input[type=checkbox] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); flex: 0 0 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.inline-form { flex-direction: row; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form label { flex: 1; min-width: 160px; }
.switch { flex-direction: row !important; align-items: flex-start; gap: 10px !important; font-weight: 500 !important; color: var(--ink) !important; }
.switch input { margin-top: 3px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 260px; width: auto; }
.toolbar select { width: auto; flex: 0 1 200px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .9rem;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.3;
}
.btn:hover { border-color: var(--ink-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { filter: brightness(.92); border-color: var(--err); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-block { width: 100%; padding: 11px; }
.danger-text { color: var(--err) !important; }
.danger-zone { border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
.danger-zone h2 { color: var(--err); }
.danger-zone form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.danger-zone label { display: flex; flex-direction: column; gap: 5px; font-size: .86rem; font-weight: 600; width: 100%; max-width: 420px; }

/* ---------- Mensajes ---------- */
.flashes { display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; border: 1px solid transparent; font-size: .92rem; }
.flash ul { margin: 0; padding-left: 18px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--err-soft); color: var(--err); }
.flash-aviso { background: var(--warn-soft); color: var(--warn); }
.flash-info { background: var(--info-soft); color: var(--info); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.is-active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Archivos ---------- */
.files-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 20px; align-items: start; }
.files-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.folders { padding: 14px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
.folders h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 2px 6px 8px; }
.folder { display: flex; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 7px; color: var(--ink-2); font-size: .9rem; }
.folder span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder b { font-weight: 500; color: var(--muted); font-size: .8rem; }
.folder:hover { background: var(--surface-2); text-decoration: none; }
.folder.is-active { background: var(--accent-soft); color: var(--accent-ink); }
.folder-new { display: flex; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-2); }
.folder-new input { padding: 6px 8px; font-size: .85rem; }
.folders form .btn-ghost { margin-top: 6px; width: 100%; }
.upload { padding: 0; }
.upload summary { padding: 14px 20px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
.upload summary::before { content: "+"; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 700; }
.upload[open] summary::before { content: "–"; }
.upload summary::-webkit-details-marker { display: none; }
.upload form { padding: 0 20px 20px; }
.drop {
  position: relative; border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center;
  background: var(--surface-2); cursor: pointer; font-weight: 500 !important; color: var(--ink-2) !important;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-cell { display: flex; align-items: flex-start; gap: 10px; min-width: 240px; }
.file-cell a { word-break: break-word; font-weight: 500; }

/* ---------- Tablas ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table small { color: var(--muted); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; }
.members td { vertical-align: middle; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; }
.perm-check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; font-size: .85rem !important; color: var(--ink) !important; cursor: pointer; }
.perm-check.is-disabled { opacity: .45; cursor: not-allowed; }
.members .perm-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
.roles-help { font-size: .88rem; color: var(--ink-2); }
.roles-help summary { cursor: pointer; color: var(--accent-ink); font-weight: 600; }
.roles-help ul { margin: 8px 0 0; padding-left: 18px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; }
.request { display: flex; flex-direction: column; gap: 12px; }
.request-actions { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line-2); padding-top: 12px; }
.request-actions .inline-form label { min-width: 180px; flex: 0 1 220px; }

.credentials { display: flex; flex-direction: column; gap: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 12px; }
.credentials dt { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.credentials dd { margin: 2px 0 0; word-break: break-all; }
code.big { font-size: 1.15rem; padding: 3px 8px; user-select: all; }

/* ---------- Acceso ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 12px;
  background: radial-gradient(circle at 20% 0%, var(--accent-soft), transparent 45%), var(--bg); }
.auth-wrap .flashes { width: 100%; max-width: 420px; }
.auth-card { width: 100%; max-width: 420px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; }
.auth-card.wide { max-width: 640px; }
.auth-card p { margin: 0; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-brand h1 { font-size: 1.3rem; margin: 0; }

.error-box { max-width: 520px; margin: 8vh auto; text-align: center; }
.error-code { font: 700 3rem ui-monospace, Menlo, monospace; color: var(--accent); margin: 0; }

/* ---------- Control de avance ---------- */
.tabs .tab-avance { margin-left: auto; color: var(--accent-ink); }
.tabs .tab-avance b { font-weight: 700; }
.tabs .tab-avance:hover { color: var(--accent-ink); text-decoration: underline; }
.pc-avance { margin-top: 8px; }
.pc-avance-top { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.pc-avance-top strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 99px; background: var(--line-2); overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.avance-sel { min-width: 170px; padding: 6px 8px; font-size: .85rem; }
.inline-label { flex-direction: row !important; align-items: center; gap: 10px !important; flex-wrap: wrap; }
.inline-label select { width: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid-main, .files-layout { grid-template-columns: 1fr; }
  .folders { position: static; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 30; left: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.nav-open .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .menu-btn { font-size: 1.3rem; background: none; border: 0; color: var(--ink); cursor: pointer; padding: 2px 6px; }
  .topbar-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 20px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .members .perm-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.3rem; }
}
