/* ---------- Identidad Royal: magenta #f10143, rosa de marca, Gabarito + Roboto Condensed ExtraBold ---------- */
@font-face { font-family: "Gabarito"; src: url("fonts/gabarito-400.ttf") format("truetype"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Gabarito"; src: url("fonts/gabarito-700.ttf") format("truetype"); font-weight: 700 900; font-display: swap; }
@font-face { font-family: "Roboto Condensed"; src: url("fonts/roboto-condensed-800.ttf") format("truetype"); font-weight: 800; font-display: swap; }

:root {
  --brand: #f10143;
  --brand-pink: #f6cbdb;
  --bg: #f7f5f6;
  --surface: #ffffff;
  --surface-2: #f4f1f2;
  --border: #e9e3e5;
  --text: #202124;
  --muted: #666666;
  --accent: #f10143;
  --accent-soft: #fde5ec;
  --bar: #3a3a3d;          /* barras de datos: negro Royal, para no confundirlas con «excedido» */
  --ok: #1f9d6a;
  --ok-soft: #e3f5ec;
  --warn: #c98a0a;
  --warn-soft: #fbf1dc;
  --over: #b4231b;
  --over-soft: #fbe3e1;
  --none: #b3abae;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(32, 33, 36, .06), 0 1px 1px rgba(32, 33, 36, .04);
  --font: "Gabarito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-head: "Roboto Condensed", "Arial Narrow", "Gabarito", sans-serif;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #ff2a62;
    --brand-pink: #4a1f2c;
    --bg: #141214;
    --surface: #1d1a1c;
    --surface-2: #272326;
    --border: #363033;
    --text: #efeaec;
    --muted: #a69da1;
    --accent: #ff2a62;
    --accent-soft: #3a1a24;
    --bar: #cfc8cb;
    --ok: #3cc28b;
    --ok-soft: #173327;
    --warn: #e6a92b;
    --warn-soft: #3a2f15;
    --over: #f0685e;
    --over-soft: #3d1f1d;
    --none: #5f585b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-family: var(--font-head); font-weight: 800; text-transform: uppercase; letter-spacing: .01em; }
h1 { font-size: 26px; line-height: 1.1; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.error { color: var(--over); }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { height: 28px; width: auto; display: block; }
.brand .wordmark { font-family: var(--font); font-weight: 700; font-size: 24px; letter-spacing: -.02em; line-height: 1; }
.brand .app-name {
  font-family: var(--font-head); font-weight: 800; text-transform: uppercase; font-size: 12px; letter-spacing: .04em;
  color: var(--muted); padding-left: 10px; margin-left: 2px; border-left: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a {
  display: flex; align-items: center; padding: 0 14px; color: var(--muted);
  font-family: var(--font-head); font-weight: 800; text-transform: uppercase; letter-spacing: .03em; font-size: 14px;
  border-bottom: 3px solid transparent; margin-bottom: -3px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.sync { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn.primary:hover { background: #d20039; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], textarea, select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; user-select: none; }

/* ---------- Layout ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .section + .section { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { padding: 14px 16px; border-top: 4px solid var(--brand-pink); }
.kpi .label { font-family: var(--font-head); font-weight: 800; text-transform: uppercase; letter-spacing: .03em; font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.ok { border-top-color: var(--ok); }
.kpi.warn { border-top-color: var(--warn); }
.kpi.over { border-top-color: var(--over); }
.kpi.ok .value { color: var(--ok); }
.kpi.warn .value { color: var(--warn); }
.kpi.over .value { color: var(--over); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-family: var(--font-head); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
tr.sub td { background: var(--surface-2); font-size: 12px; }
table.proj { table-layout: fixed; min-width: 760px; }
table.proj th:nth-child(1) { width: auto; }
table.proj th:nth-child(2), table.proj th:nth-child(3) { width: 110px; }
table.proj th:nth-child(4) { width: 200px; }
table.proj th:nth-child(5) { width: 100px; }
table.proj th:nth-child(6) { width: 130px; }
td.name { font-weight: 500; }
td.name .meta { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 2px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---------- Grupos de proyectos ---------- */
.space-title { margin: 28px 0 10px; font-size: 15px; letter-spacing: .04em; color: var(--brand); }
.space-title:first-of-type { margin-top: 0; }
details.folder { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
details.folder > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 16px;
}
details.folder > summary::-webkit-details-marker { display: none; }
details.folder > summary::before { content: '▸'; color: var(--brand); transition: transform .15s; }
details.folder[open] > summary::before { transform: rotate(90deg); }
details.folder[open] > summary { border-bottom: 1px solid var(--border); }
details.folder .folder-name { font-family: var(--font-head); font-weight: 800; text-transform: uppercase; font-size: 15px; letter-spacing: .02em; }
details.folder .folder-stats { margin-left: auto; display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--muted); }
details.folder .folder-stats .bar { width: 120px; }

/* ---------- Barras de progreso ---------- */
.progress { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.bar { position: relative; flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--none); }
.bar.ok > span { background: var(--ok); }
.bar.warn > span { background: var(--warn); }
.bar.over > span { background: var(--over); }
.bar.big { height: 14px; }
.pct { font-variant-numeric: tabular-nums; font-size: 12px; min-width: 44px; text-align: right; }
.pct.ok { color: var(--ok); }
.pct.warn { color: var(--warn); }
.pct.over { color: var(--over); font-weight: 600; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.over { background: var(--over-soft); color: var(--over); }
.pill.live { background: var(--over-soft); color: var(--over); }
.pill.live::before { content: '●'; margin-right: 4px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; text-transform: capitalize; white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 2px; background: var(--none); display: inline-block; }

/* ---------- Horas contratadas editables ---------- */
.budget-cell { cursor: pointer; border-radius: 6px; padding: 3px 6px; margin: -3px -6px; display: inline-block; }
.budget-cell:hover { background: var(--accent-soft); }
.budget-cell.unset { color: var(--accent); font-size: 12px; }
.budget-input { width: 90px; text-align: right; padding: 4px 6px; }

/* ---------- Avatares ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%; font-size: 11px; font-weight: 600; color: #fff;
  background: var(--none); overflow: hidden; vertical-align: middle;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatars { display: inline-flex; }
.avatars .avatar { width: 24px; height: 24px; font-size: 10px; border: 2px solid var(--surface); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }
.person { display: flex; align-items: center; gap: 10px; }

/* ---------- Gráficos sencillos ---------- */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 18px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .col .b { width: 100%; max-width: 36px; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.chart .col .b.weekend { background: var(--none); }
.chart .col .v { font-size: 10px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.chart .col .l { font-size: 10px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hbars .row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr 60px; gap: 10px; align-items: center; padding: 6px 0; }
.hbars .row .bar > span { background: var(--bar); }

/* ---------- Pestañas internas ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--brand); color: #fff; box-shadow: var(--shadow); }

/* ---------- Edición de presupuesto en detalle ---------- */
.budget-form { display: grid; gap: 10px; }
.budget-form .row { display: flex; gap: 8px; align-items: center; }
.budget-form textarea { width: 100%; min-height: 60px; resize: vertical; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
  max-width: 90vw;
}
.toast.error { background: var(--brand); color: #fff; }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; position: relative; overflow: hidden; }
/* banda rosa inclinada, como el pie de los documentos de Royal */
.login-page::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 34vh; z-index: -1;
  background: var(--brand-pink); clip-path: polygon(0 0, 91% 20%, 100% 100%, 0 100%);
}
.login-card { width: 100%; max-width: 360px; display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--brand); border-radius: 14px; padding: 28px; box-shadow: 0 10px 30px rgba(32, 33, 36, .08); }
.login-card .brand { margin-bottom: 14px; }
.login-card .brand img { height: 36px; }
.login-card .brand .wordmark { font-size: 32px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0 0 10px; }
.login-foot { position: absolute; bottom: 16px; left: 24px; font-size: 13px; font-weight: 700; color: var(--brand); }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card .btn { justify-content: center; margin-top: 6px; }

@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 12px; }
  .brand .app-name, #sync-info { display: none; }
  main { padding: 16px; }
  .tabs a { padding: 0 8px; }
  .sync { gap: 4px; }
  .sync .btn { padding: 6px 8px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  details.folder > summary { flex-wrap: wrap; }
  details.folder .folder-stats > span, details.folder .folder-stats .bar { display: none; }
  .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .brand .wordmark { display: none; }
}
