:root {
  --bg: #f4f8fc;
  --panel: #ffffff;
  --panel-2: #eef5fb;
  --line: rgba(34, 71, 111, 0.16);
  --text: #12263a;
  --muted: #5b7085;
  --teal: #0e9f8d;
  --cyan: #0b75d1;
  --amber: #f59e0b;
  --danger: #dc4d64;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "IBM Plex Sans", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

.bg-grid,
.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -2;
}

.bg-grid {
  background-image: linear-gradient(rgba(34,71,111,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(34,71,111,0.05) 1px, transparent 1px);
  background-size: 30px 30px;
  opacity: 0.5;
}

.bg-gradient {
  z-index: -1;
  background: radial-gradient(circle at 15% 20%, rgba(11, 117, 209, 0.15), transparent 45%), radial-gradient(circle at 80% 10%, rgba(14, 159, 141, 0.14), transparent 38%), radial-gradient(circle at 60% 80%, rgba(245, 158, 11, 0.12), transparent 34%);
}

.hidden { display: none !important; }

.eyebrow {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--cyan);
  margin: 0;
  font-size: 11px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(460px, 92vw);
  background: linear-gradient(180deg, #ffffff, #f5f9fd);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 18px 45px rgba(20, 52, 86, 0.15);
}

.login-card h1 {
  margin: 8px 0;
  font-family: "Sora", sans-serif;
}

.muted { color: var(--muted); }

.form { display: grid; gap: 12px; margin-top: 16px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }

input,
select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  width: 100%;
  resize: vertical;
  min-height: 90px;
}

input:focus,
select:focus,
textarea:focus { border-color: var(--cyan); }

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
  line-height: 1.15;
}

.btn.primary {
  background: linear-gradient(135deg, var(--cyan), var(--teal));
  color: #ffffff;
}

.btn.ghost {
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
}

.error { min-height: 20px; color: var(--danger); }

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  background: rgba(255, 255, 255, 0.88);
  border-right: 1px solid var(--line);
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 16px;
}

.brand h2 {
  margin: 6px 0 0;
  font-family: "Sora", sans-serif;
}

.sidebar-brand-logo {
  width: 70px;
  height: auto;
  display: block;
}

.instance-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip.active {
  background: linear-gradient(135deg, var(--cyan), var(--teal));
  color: #ffffff;
  border-color: transparent;
  font-weight: 700;
}

.nav-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.module-nav {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 280px);
  overflow: auto;
  padding-right: 4px;
}

.module-btn {
  position: relative;
  text-align: left;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
}

.module-btn-title {
  display: inline-block;
  margin-right: 6px;
}

.module-btn small {
  display: block;
  color: var(--muted);
}

.module-btn.active {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px rgba(11,117,209,0.3);
}

.module-task-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.module-task-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
}

.module-task-badge.baja {
  background: #e8edf3;
  color: #4b5d72;
  border-color: #cbd7e4;
}

.module-task-badge.media {
  background: #fff6d8;
  color: #8e6a00;
  border-color: #efd79a;
}

.module-task-badge.alta {
  background: #ffe9d9;
  color: #a84f00;
  border-color: #f2c39c;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.workspace {
  padding: 18px;
  overflow: visible;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fx-box {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  min-width: 220px;
}

.fx-box label {
  font-size: 11px;
  color: var(--muted);
}

.fx-box select {
  padding: 7px 9px;
  border-radius: 10px;
}

.fx-box small {
  color: var(--muted);
  font-size: 11px;
}

.instance-label {
  margin: 0;
  color: var(--teal);
  font-size: 13px;
}

.topbar h1 {
  margin: 6px 0 0;
  font-family: "Sora", sans-serif;
  font-size: 28px;
}

.module-content {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.audit-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card {
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.card h3 { margin: 0 0 10px; font-family: "Sora", sans-serif; }

.grid {
  display: grid;
  gap: 12px;
}

.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.metric {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.metric b {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  font-family: "Sora", sans-serif;
}

.table-wrap {
  overflow: auto;
  max-height: min(68vh, 760px);
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-fixed {
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid rgba(34, 71, 111, 0.1);
  padding: 9px;
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}

td .btn {
  margin: 2px 4px 2px 0;
}

.items-grid td,
.items-grid th {
  overflow: hidden;
  text-overflow: ellipsis;
}

.items-grid th.col-name,
.items-grid td.col-name {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

th {
  background: #edf4fb;
  color: #2c4b69;
  position: sticky;
  top: 0;
  z-index: 2;
}

.erp-hr-sched-row.is-highlighted td {
  background: #e7f4ff;
}

.erp-fin-income-row.is-highlighted td {
  background: #e7f4ff;
}

.erp-fin-daily-docs-open {
  margin-left: 6px;
  padding: 8px 10px;
}

.daily-doc-icon {
  display: inline-flex;
  color: #c81e1e;
  vertical-align: middle;
}

.erp-ops-group-program td {
  background: #edf4fb;
}

.erp-ops-group-person td {
  background: #f6fbff;
}

.erp-ops-group-person .btn {
  margin-left: 18px;
}

.erp-ops-assignment-leaf td:first-child {
  padding-left: 26px;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.table-toolbar .meta {
  color: var(--muted);
  font-size: 12px;
}

.table-search {
  width: min(360px, 100%);
}

.form-inline {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-inline.clients {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.logo-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--line);
}

.notice {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 14px;
  color: var(--muted);
  background: #f8fcff;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(13, 29, 46, 0.25);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}

.modal-card {
  width: min(980px, 96vw);
  max-height: 92vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 18px 46px rgba(20,52,86,0.2);
  min-width: 0;
}

.client-modal-card {
  width: min(1120px, 96vw);
  max-height: 96vh;
}

.client-form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.modal-head h3 {
  margin: 0;
  font-family: "Sora", sans-serif;
}

.modal-preview {
  margin-top: 10px;
}

.status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.status-dot.on {
  background: #31c36b;
  border-color: #1f9c52;
}

.status-dot.off {
  background: #d7dde8;
  border-color: #b9c5d6;
}

.program-modal-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(1280px, 98vw);
  max-height: 94vh;
}

#program-edit-compose {
  min-height: 0;
  margin-top: 18px;
}

#program-edit-form {
  row-gap: 14px;
}

#program-edit-compose .form-inline.clients {
  margin-top: 16px !important;
}

#program-edit-compose .table-wrap {
  margin-top: 14px !important;
}

#program-edit-compose .metric b {
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
}

#program-edit-compose .items-grid th.col-calculated,
#program-edit-compose .items-grid td.col-calculated {
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.program-modal-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #ffffff 46%);
}

.viatico-map {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 320px;
  height: 40vh;
  max-height: 460px;
  overflow: hidden;
}

.erp-commercial-programs {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.erp-commercial-client {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.erp-commercial-check-col {
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  text-align: center;
  padding-left: 6px;
  padding-right: 6px;
}

.erp-commercial-check-col input[type="checkbox"] {
  transform: scale(0.95);
}

.erp-commercial-country-col {
  width: 64px;
  min-width: 64px;
  max-width: 64px;
  text-align: center;
}

.erp-commercial-created-col {
  text-align: center;
}

.erp-commercial-filters,
.erp-commercial-actions {
  align-items: center;
}

.ops-pending-duration-row td {
  background: #fff9db;
}

.erp-fin-wrap {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.items-country-group td {
  background: #edf4fb;
  color: #2c4b69;
  font-weight: 700;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.summary-card h4 {
  margin: 0 0 8px;
  font-family: "Sora", sans-serif;
}

.summary-card b {
  display: block;
  font-size: 24px;
  margin-bottom: 8px;
  font-family: "Sora", sans-serif;
}

.summary-card.income {
  background: #ecfff3;
  border-color: rgba(35, 143, 87, 0.25);
}

.summary-card.expense {
  background: #fff9dd;
  border-color: rgba(201, 146, 35, 0.3);
}

.summary-lines {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: #2d3f52;
}

.money-positive {
  color: #137546;
}

.money-negative {
  color: #b91c1c;
}

.margin-diff-green {
  color: #137546;
}

.margin-diff-yellow {
  color: #a16207;
}

.margin-diff-red {
  color: #b91c1c;
}

.summary-month-detail {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  background: #ffffff;
}

.role-pill.active {
  color: #116e40;
  border-color: rgba(17, 110, 64, 0.3);
  background: #e9fff3;
}

.role-pill.inactive {
  color: #8f1d3e;
  border-color: rgba(143, 29, 62, 0.3);
  background: #fff0f4;
}

.stacked-panel {
  display: grid;
  gap: 10px;
}

.stack-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 10px;
}

.stack-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.stack-head b {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.stack-bar {
  height: 14px;
  width: 100%;
  overflow: hidden;
  display: flex;
  border-radius: 999px;
  background: #edf4fb;
  border: 1px solid var(--line);
}

.stack-seg {
  display: inline-flex;
  height: 100%;
}

.stack-legend {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stack-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.stack-legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dashboard-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.panel-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 12px;
}

.panel-box h4 {
  margin: 0 0 8px;
  font-family: "Sora", sans-serif;
}

.panel-kpi {
  display: grid;
  gap: 3px;
  margin-bottom: 8px;
}

.panel-kpi span {
  color: var(--muted);
  font-size: 12px;
}

.panel-kpi b {
  font-size: 28px;
  font-family: "Sora", sans-serif;
}

.panel-list {
  display: grid;
  gap: 4px;
  font-size: 13px;
}

.gm-task-due {
  min-width: 116px;
}

.gm-collab-cell {
  display: grid;
  gap: 6px;
  min-width: 180px;
}

.task-progress-wrap {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.task-progress {
  height: 6px;
  border-radius: 999px;
  border: 1px solid #bfddf5;
  background: #e9f5ff;
  overflow: hidden;
}

.task-progress span {
  display: block;
  height: 100%;
  background: #2f9bf0;
}

.task-progress.done {
  border-color: #92d8b4;
  background: #eafaf0;
}

.task-progress.done span {
  background: #1f9c52;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .module-nav { max-height: 220px; }
  .topbar h1 { font-size: 24px; }
  .fx-box { min-width: 180px; }
  .form-inline { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: 1fr; }
  .summary-cards { grid-template-columns: 1fr; }
  .dashboard-panels { grid-template-columns: 1fr; }
  .table-wrap { max-height: 56vh; }
  .program-modal-card { width: min(1260px, 99vw); max-height: 95vh; }
}

@media (max-width: 640px) {
  .workspace { padding: 12px; }
  .sidebar { padding: 12px; }
  .topbar h1 { font-size: 21px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .fx-box { min-width: 0; width: 100%; }
  .form-inline { grid-template-columns: 1fr; }
  .client-form-grid { grid-template-columns: 1fr; }
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .table-wrap table { min-width: 680px; }
  .table-wrap .btn {
    padding: 8px 10px;
    font-size: 12px;
  }
  .table-wrap td .btn {
    display: block;
    width: 100%;
    margin: 4px 0;
  }
  .table-toolbar .btn {
    width: 100%;
  }
  .card > .table-toolbar > div {
    width: 100%;
  }
  .modal { padding: 10px; }
  .modal-card,
  .client-modal-card,
  .program-modal-card {
    width: calc(100vw - 10px);
    max-height: 94vh;
    border-radius: 12px;
    padding: 12px;
  }
  .metric b { font-size: 18px; }
  .table-search {
    width: 100%;
  }
  .table-wrap { max-height: 52vh; }
}
