:root {
  --forest: #2E7D6A;
  --blue: #205E78;
  --gold: #D3A57D;
  --paper: #FAFAFA;
  --ink: #333333;
  --mist: #E4E6E8;
  --coral: #FF6F61;
  --reference: #68747C;
  --surface: #FFFFFF;
  --line: #DDE2E4;
  --muted: #6B777D;
  --danger: #A44747;
  --warning: #A96F26;
  --shadow: 0 14px 36px rgba(36, 51, 58, .11);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #F1F3F4;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; filter: grayscale(.25); }
.is-hidden { display: none !important; }

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(211,165,125,.28), transparent 34%),
    radial-gradient(circle at 85% 78%, rgba(46,125,106,.18), transparent 34%),
    #F1F3F4;
}
.auth-card {
  width: min(440px, 100%);
  padding: 38px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.auth-brand {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: var(--blue);
  font: 800 24px Georgia, serif;
}
.auth-card h1 { margin: 0; color: var(--blue); font: 700 29px/1.15 Georgia, serif; }
.auth-card p { margin: 14px 0 24px; color: var(--muted); line-height: 1.5; }
.auth-card small { display: block; margin-top: 18px; color: var(--muted); }
.google-sign-in {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border: 1px solid #CBD3D7;
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}
.google-sign-in:hover { border-color: var(--blue); color: var(--blue); }
.google-mark { color: #4285F4; font-size: 20px; font-weight: 900; }
.auth-sign-out { margin-top: 10px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 235px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
}
.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 310px minmax(340px, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 10px 22px;
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand-block, .identity-chip, .project-switcher { display: flex; align-items: center; }
.brand-block { gap: 12px; }
.brand-block strong { display: block; font-family: Georgia, serif; color: var(--blue); font-size: 16px; }
.brand-block span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px;
  color: var(--paper); background: var(--blue); border-radius: 13px;
  font-family: Georgia, serif; font-weight: 800; box-shadow: 0 7px 18px rgba(32,94,120,.22);
}
.project-switcher { justify-content: center; gap: 9px; }
.project-switcher label { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.project-switcher select { min-width: 300px; max-width: 520px; }
.project-switcher select, .filter-control, .form-field input, .form-field select, .form-field textarea {
  border: 1px solid #CBD3D7; border-radius: 10px; background: #fff; color: var(--ink); padding: 9px 11px;
}
.secondary-button, .primary-button, .quiet-button, .danger-button {
  border-radius: 10px; padding: 9px 12px; font-weight: 750; border: 1px solid #C8D0D4; background: #fff; color: #405159;
}
.primary-button { background: var(--blue); border-color: var(--blue); color: #fff; }
.primary-button.green { background: var(--forest); border-color: var(--forest); }
.quiet-button { border-color: transparent; background: #F1F4F5; }
.danger-button { color: var(--danger); border-color: #E4BABA; background: #FFF8F8; }
.secondary-button:hover, .quiet-button:hover { border-color: var(--blue); color: var(--blue); }
.identity-chip { gap: 9px; border: 0; border-left: 1px solid var(--line); padding: 4px 0 4px 18px; background: transparent; text-align: left; }
.identity-chip strong, .identity-chip small { display: block; }
.identity-chip strong { font-size: 12px; }
.identity-chip small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--gold); color: #4A3D33; font-family: Georgia, serif; font-weight: 800; }

.sidebar {
  grid-row: 2; background: #23343C; color: #EFF3F4; display: flex; flex-direction: column;
  padding: 18px 12px; min-height: calc(100vh - 72px); position: sticky; top: 72px; z-index: 20;
}
.sidebar nav { display: flex; flex-direction: column; gap: 5px; }
.nav-item {
  display: grid; grid-template-columns: 25px 1fr auto; align-items: center; text-align: left; gap: 7px;
  width: 100%; padding: 11px 12px; border: 0; border-radius: 10px; background: transparent; color: #D6DEE1;
}
.nav-item span { font-weight: 900; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: #fff; color: var(--blue); font-weight: 800; box-shadow: 0 7px 20px rgba(0,0,0,.16); }
.nav-count { min-width: 21px; text-align: center; border-radius: 20px; padding: 2px 6px; font-size: 10px; background: var(--coral); color: #333; }
.sidebar-note { margin-top: auto; display: flex; gap: 9px; align-items: flex-start; border-top: 1px solid rgba(255,255,255,.1); padding: 16px 8px 4px; }
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note strong { font-size: 11px; }
.sidebar-note small { font-size: 9px; color: #AEBBC0; line-height: 1.35; margin-top: 3px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #74C6A9; margin-top: 3px; box-shadow: 0 0 0 4px rgba(116,198,169,.12); }

.main-content { min-width: 0; padding: 28px clamp(18px, 3vw, 42px) 50px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .16s ease; }
@keyframes fadeIn { from { opacity: .55; transform: translateY(3px); } }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 22px; }
.page-heading h1 { margin: 0; color: var(--blue); font-family: Georgia, serif; font-size: clamp(25px, 3vw, 34px); }
.page-heading p { margin: 7px 0 0; color: var(--muted); max-width: 780px; line-height: 1.45; }
.heading-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric-card { background: #fff; border: 1px solid var(--line); border-radius: 15px; padding: 17px; box-shadow: 0 5px 18px rgba(43,55,61,.05); }
.metric-card .metric-label { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.metric-value { display: flex; align-items: baseline; gap: 7px; margin-top: 7px; }
.metric-value strong { font-family: Georgia, serif; font-size: 30px; color: var(--blue); }
.metric-value span { font-size: 11px; color: var(--muted); }
.metric-card.alert strong { color: var(--coral); }
.metric-card.good strong { color: var(--forest); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 18px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: 0 6px 20px rgba(43,55,61,.055); }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.panel-head h2, .panel-head h3 { margin: 0; font-family: Georgia, serif; color: var(--blue); }
.panel-head h2 { font-size: 19px; }
.panel-head h3 { font-size: 16px; }
.link-button { border: 0; background: transparent; color: var(--blue); font-weight: 800; padding: 4px; }
.progress-track { height: 9px; border-radius: 10px; background: #E8ECEE; overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--forest)); }
.progress-caption { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 7px; }

.work-list, .review-list, .history-list { display: flex; flex-direction: column; gap: 8px; }
.work-item, .review-item, .history-item { display: grid; align-items: center; gap: 10px; border: 1px solid #E0E5E7; border-radius: 11px; padding: 11px 12px; background: #FCFDFD; }
.work-item { grid-template-columns: 10px 1fr auto; cursor: pointer; }
.work-item:hover, .review-item:hover { border-color: #9CB7C2; }
.work-dot { width: 8px; height: 38px; border-radius: 8px; }
.item-title { font-size: 12px; font-weight: 800; }
.item-meta { color: var(--muted); font-size: 10px; margin-top: 3px; }
.status-pill, .type-pill, .priority-pill, .alert-pill { display: inline-flex; align-items: center; border-radius: 20px; padding: 4px 8px; font-size: 9px; font-weight: 850; white-space: nowrap; }
.status-pill.ready { color: #216655; background: #E4F2ED; }
.status-pill.blocked { color: #8A4747; background: #F6E9E9; }
.status-pill.complete { color: #2E5E7A; background: #E6EFF3; }
.alert-pill { color: #743F1D; background: #F7E1CB; }
.alert-pill.indirect { background: #F5EBD8; color: #785C25; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; padding: 13px; margin-bottom: 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.toolbar .search { flex: 1; min-width: 240px; }
.filter-control { min-width: 145px; }
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 15px; }
.document-table { width: 100%; border-collapse: collapse; min-width: 960px; }
.document-table th { position: sticky; top: 0; z-index: 2; padding: 11px 12px; background: #F5F7F7; color: #66757C; font-size: 9px; text-align: left; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--line); }
.document-table td { padding: 10px 12px; border-bottom: 1px solid #EDF0F1; font-size: 11px; vertical-align: middle; }
.document-table tbody tr { cursor: pointer; }
.document-table tbody tr:hover { background: #F8FBFC; }
.document-name { display: flex; align-items: center; gap: 10px; max-width: 450px; }
.document-swatch { width: 11px; height: 38px; border-radius: 8px; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.08); }
.document-name strong { display: block; font-size: 11.5px; }
.document-name small { color: var(--muted); display: block; margin-top: 3px; }

.graph-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.graph-relation-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: -2px 0 12px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; color: var(--muted); font-size: 9px; }
.graph-relation-legend span { display: inline-flex; align-items: center; gap: 6px; }
.relation-line { display: inline-block; width: 27px; border-top: 3px solid var(--relation-color); }
.graph-viewport { position: relative; height: calc(100vh - 210px); min-height: 540px; overflow: auto; border: 1px solid var(--line); border-radius: 15px; background-color: #F8FAFA; background-image: linear-gradient(rgba(32,94,120,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(32,94,120,.04) 1px, transparent 1px); background-size: 30px 30px; }
.graph-world { position: relative; transform-origin: 0 0; }
.graph-edges { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.graph-edge { fill: none; stroke: var(--relation-color, #8A989F); stroke-width: 1.4; opacity: .12; }
.graph-edge.active { opacity: .94; stroke-width: 2.8; filter: drop-shadow(0 1px 1px rgba(30,42,48,.2)); }
.relation-depende { --relation-color: #52636C; }
.relation-integra { --relation-color: #7C8790; }
.relation-alimenta { --relation-color: #6F8FA0; }
.relation-gobierna { --relation-color: #D3A57D; }
.relation-actualiza { --relation-color: #2E7D6A; }
.relation-genera { --relation-color: #FF6F61; }
.relation-referencia { --relation-color: #68747C; }
.graph-edge.relation-integra { stroke-width: 2.1; stroke-dasharray: 4 3; }
.graph-edge.relation-alimenta { stroke-dasharray: 8 6; }
.graph-edge.relation-gobierna { stroke-width: 2; }
.graph-edge.relation-actualiza { stroke-dasharray: 3 6; }
.graph-edge.relation-genera { stroke-dasharray: 10 4; }
.graph-edge.relation-referencia { stroke-dasharray: 2 5; }
.relation-line.relation-integra, .relation-line.relation-actualiza, .relation-line.relation-referencia { border-top-style: dotted; }
.relation-line.relation-alimenta, .relation-line.relation-genera { border-top-style: dashed; }
.graph-phase { position: absolute; top: 16px; height: 35px; padding: 9px 12px; border-radius: 9px; background: rgba(255,255,255,.95); border: 1px solid #D9E0E3; color: var(--blue); font-family: Georgia, serif; font-weight: 700; font-size: 12px; }
.graph-node { position: absolute; width: 270px; min-height: 86px; padding: 9px 10px; border-radius: 11px; border: 2px solid rgba(255,255,255,.8); box-shadow: 0 5px 14px rgba(31,46,54,.14); cursor: pointer; transition: transform .12s, box-shadow .12s; }
.graph-node:hover, .graph-node.selected { transform: translateY(-2px); box-shadow: 0 9px 22px rgba(31,46,54,.24); outline: 3px solid #243840; }
.graph-node-head { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.graph-node-id { font-size: 9px; font-weight: 900; background: rgba(255,255,255,.52); color: #333; border-radius: 4px; padding: 2px 5px; }
.graph-node-alert { margin-left: auto; width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center; background: #FFF1E0; color: #8A4F20; font-weight: 900; }
.graph-node-title { font-family: Georgia, serif; font-size: 11.5px; font-weight: 750; line-height: 1.2; }
.graph-node-meta { margin-top: 6px; font-size: 9px; opacity: .82; }

.review-banner { border: 1px solid #E5B986; background: #FFF8ED; color: #6A4924; border-radius: 13px; padding: 13px; line-height: 1.45; font-size: 11px; }
.review-item { grid-template-columns: 1fr auto; }
.review-path { margin-top: 6px; color: #71512C; background: #FFF8ED; border-radius: 7px; padding: 6px 8px; font-size: 10px; }

.members-table { width: 100%; border-collapse: collapse; }
.members-table th, .members-table td { text-align: left; padding: 10px; border-bottom: 1px solid #E7EBED; font-size: 11px; }
.role-card-grid { display: grid; grid-template-columns: repeat(5, minmax(145px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 3px; }
.role-card { min-width: 145px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.role-card h4 { margin: 0 0 7px; color: var(--blue); }
.role-card ul { padding-left: 16px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.45; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.department-list { display: flex; flex-direction: column; gap: 8px; }
.department-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 9px; padding: 9px; border: 1px solid #E0E5E7; border-radius: 9px; }
.color-block { width: 28px; height: 28px; border-radius: 8px; border: 1px solid rgba(0,0,0,.09); }
.legend-demo { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.legend-card { min-height: 70px; border-radius: 10px; padding: 10px; border: 2px solid rgba(255,255,255,.7); box-shadow: 0 3px 10px rgba(0,0,0,.08); font-size: 10px; font-weight: 800; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(24,35,41,.38); z-index: 49; opacity: 0; pointer-events: none; transition: opacity .18s; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.document-drawer { position: fixed; z-index: 50; right: 0; top: 0; bottom: 0; width: min(520px, 96vw); background: #fff; box-shadow: -16px 0 40px rgba(28,42,49,.2); transform: translateX(102%); transition: transform .2s ease; display: flex; flex-direction: column; }
.document-drawer.open { transform: translateX(0); }
.drawer-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.drawer-head-top { display: flex; align-items: center; gap: 8px; }
.drawer-head h2 { margin: 10px 0 0; font-family: Georgia, serif; color: var(--blue); font-size: 21px; line-height: 1.25; }
.close-button { margin-left: auto; border: 0; background: transparent; font-size: 24px; color: var(--muted); }
.drawer-body { padding: 16px 20px 34px; overflow: auto; }
.drawer-section { margin-bottom: 18px; }
.drawer-section h3 { font-family: Georgia, serif; color: var(--blue); font-size: 15px; margin: 0 0 9px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-field { margin-bottom: 10px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { display: block; color: var(--muted); font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea { width: 100%; }
.form-field > small { display: block; color: var(--muted); font-size: 9px; line-height: 1.35; margin-top: 4px; }
.form-field textarea { min-height: 82px; resize: vertical; }
.dependency-list { display: flex; flex-direction: column; gap: 6px; }
.dependency-item { display: grid; grid-template-columns: 19px 1fr auto; gap: 7px; align-items: center; border: 1px solid #E0E5E7; border-radius: 8px; padding: 8px; font-size: 10px; }
.dependency-item.ok > span:first-child { color: var(--forest); }
.dependency-item.missing > span:first-child { color: var(--danger); }
.relation-chip { border-left: 4px solid var(--relation-color); background: #F3F5F6; border-radius: 5px; padding: 4px 6px; color: #46565E; font-weight: 800; }
.version-list { display: flex; flex-direction: column; gap: 7px; }
.version-item { border-left: 3px solid var(--blue); background: #F4F7F8; border-radius: 0 8px 8px 0; padding: 8px 10px; font-size: 10px; }
.version-item strong { display: block; }
.version-item small { color: var(--muted); }
.version-actions { display: flex; gap: 7px; margin-top: 7px; }
.version-actions a { display: inline-flex; padding: 5px 8px; border-radius: 7px; background: #fff; border: 1px solid #CAD5D9; color: var(--blue); font-weight: 800; text-decoration: none; }
.version-actions a:hover { border-color: var(--blue); }
.drive-choice { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 9px; margin: 10px 0 18px; padding: 12px; border: 1px dashed #BAC7CC; border-radius: 11px; background: #F8FAFA; }
.drive-choice > span { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--mist); color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; }
.drive-choice .item-meta { grid-column: 2; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.modal-root { position: fixed; inset: 0; z-index: 80; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(24,35,41,.52); }
.modal-root.open { display: flex; }
.modal { width: min(560px, 96vw); max-height: 90vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: Georgia, serif; color: var(--blue); font-size: 20px; }
.modal-body { padding: 17px 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px 17px; }
.radio-stack { display: flex; flex-direction: column; gap: 8px; }
.radio-option { display: grid; grid-template-columns: 20px 1fr; gap: 8px; align-items: start; padding: 10px; border: 1px solid #DCE2E5; border-radius: 10px; }
.radio-option small { display: block; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.toast-root { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.toast { max-width: 360px; border-radius: 11px; padding: 11px 13px; color: #fff; background: #2C414A; box-shadow: var(--shadow); font-size: 11px; animation: toastIn .2s ease; }
.toast.success { background: var(--forest); }
.toast.warning { background: #8B5A29; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }
.empty-state { text-align: center; padding: 35px 18px; color: var(--muted); }
.empty-state strong { display: block; font-family: Georgia, serif; color: var(--blue); font-size: 17px; margin-bottom: 6px; }
.mobile-only { display: none; }
.icon-button { border: 0; background: transparent; font-size: 22px; }

@media (max-width: 1050px) {
  .topbar { grid-template-columns: 1fr auto; }
  .project-switcher { grid-row: 2; grid-column: 1 / -1; justify-content: flex-start; }
  .topbar { grid-template-rows: auto auto; }
  .app-shell { grid-template-rows: 118px 1fr; }
  .sidebar { top: 118px; min-height: calc(100vh - 118px); }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .role-card-grid { grid-template-columns: repeat(5, 170px); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .topbar { position: sticky; grid-template-columns: auto 1fr; gap: 10px; padding: 9px 12px; }
  .brand-block strong { font-size: 13px; }
  .brand-mark { display: none; }
  .identity-chip { display: none; }
  .project-switcher { grid-column: 1 / -1; }
  .project-switcher label { display: none; }
  .project-switcher select { min-width: 0; flex: 1; }
  .mobile-only { display: inline-grid; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 245px; min-height: 100%; transform: translateX(-105%); transition: transform .2s; z-index: 70; }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 20px 12px 40px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { padding: 12px; }
  .metric-value strong { font-size: 25px; }
  .settings-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.full { grid-column: auto; }
}
