:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf3f9;
  --text: #172333;
  --muted: #667789;
  --line: #d8e2ec;
  --red: #d71920;
  --blue: #003a70;
  --blue-2: #0b5cab;
  --green: #167a5b;
  --yellow: #a86f00;
  --ink-red: #8b1a1f;
  --radius: 12px;
  --shadow: 0 18px 45px rgba(0, 35, 70, 0.12);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(11, 92, 171, 0.08), transparent 34rem),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 32rem);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 36px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 26px rgba(0, 35, 70, 0.06);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 180px;
  height: auto;
  flex: 0 0 auto;
}

.brand-divider {
  width: 1px;
  min-height: 48px;
  align-self: stretch;
  background: var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue-2);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: var(--blue);
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

h2 {
  font-size: 1.05rem;
}

.header-actions,
.dialog-actions,
.records-toolbar,
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button,
.view-button,
.segment {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 10px 18px rgba(0, 58, 112, 0.14);
}

.secondary-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--blue);
}

.ghost-button {
  background: transparent;
  color: var(--blue-2);
}

.danger-button {
  background: #fff2f2;
  color: var(--ink-red);
  border-color: #f2c6c6;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  padding: 0;
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
  font-size: 1.25rem;
}
.sync-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.sync-badge[data-tone="ok"] {
  background: #e2f6ee;
  border-color: #b6e2d0;
  color: #155f47;
}

.sync-badge[data-tone="warn"] {
  background: #fff4d8;
  border-color: #ebce8b;
  color: #7a5000;
}

.app-shell {
  width: min(1420px, calc(100% - 40px));
  margin: 26px auto 44px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  display: grid;
  gap: 10px;
  min-height: 110px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0, 35, 70, 0.05);
}

.metric span {
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  font-size: 2rem;
  line-height: 1;
}

.metric-red {
  border-top: 4px solid var(--red);
}

.metric-blue {
  border-top: 4px solid var(--blue);
}

.metric-yellow {
  border-top: 4px solid var(--yellow);
}

.metric-green {
  border-top: 4px solid var(--green);
}

.workbench {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.filters-panel,
.records-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 34px rgba(0, 35, 70, 0.06);
}

.filters-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  position: sticky;
  top: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 58, 112, 0.12);
}

.quick-views {
  display: grid;
  gap: 8px;
}

.view-button {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
}

.view-button.active {
  background: #e8f2fb;
  color: var(--blue);
  border-color: #bad4ec;
}

.records-panel {
  overflow: hidden;
}

.records-toolbar {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.records-toolbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #f5f8fb;
}

td {
  font-size: 0.92rem;
}

tr:hover td {
  background: #f7fbff;
}

.supplier-cell {
  display: grid;
  gap: 3px;
}

.supplier-cell small {
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.pill.compras {
  background: #fef0f0;
  color: var(--ink-red);
}

.pill.contabil {
  background: #e8f2fb;
  color: var(--blue);
}

.pill.divergencia {
  background: #fff4d8;
  color: #7a5000;
}

.pill.ok {
  background: #e2f6ee;
  color: #155f47;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
}

dialog {
  width: min(860px, calc(100% - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(10, 18, 28, 0.42);
}

#recordForm {
  padding: 22px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 5px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 18px;
}

.segment {
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: #ffffff;
  color: var(--red);
  box-shadow: 0 1px 4px rgba(23, 35, 48, 0.12);
}
.field-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.workflow-hint {
  margin: 14px 0 0;
  padding: 12px 14px;
  border: 1px solid #d9e7ff;
  border-radius: 14px;
  background: #f3f8ff;
  color: #26547c;
  font-size: 0.92rem;
  line-height: 1.45;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-contabil {
  background: var(--blue);
}

.dot-compras {
  background: var(--red);
}

.dot-shared {
  background: #79828c;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.label-row small {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  white-space: nowrap;
}

.field-owner-contabil .label-row small {
  background: #e8f0ff;
  color: #1646a0;
}

.field-owner-compras .label-row small {
  background: #ffe9e9;
  color: var(--ink-red);
}

.field-owner-shared .label-row small {
  background: #edf0f3;
  color: #43505c;
}

.field-owner-contabil input,
.field-owner-contabil select,
.field-owner-contabil textarea {
  border-left: 4px solid var(--blue);
}

.field-owner-compras input,
.field-owner-compras select,
.field-owner-compras textarea {
  border-left: 4px solid var(--red);
}

.field-owner-shared input,
.field-owner-shared select,
.field-owner-shared textarea {
  border-left: 4px solid #79828c;
}

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

.full-span {
  grid-column: 1 / -1;
}

.dialog-actions {
  margin-top: 20px;
}

.dialog-actions > div {
  display: flex;
  gap: 10px;
}

.empty-state {
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 920px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 24px 20px;
  }

  .brand-lockup {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .brand-logo {
    width: 160px;
  }

  .brand-divider {
    display: none;
  }

  .summary-grid,
  .workbench,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .filters-panel {
    position: static;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: #edf0f3;
  color: #43505c;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

#notificationCount {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.72rem;
}

.hidden-field {
  display: none !important;
}

.auth-dialog {
  width: min(560px, calc(100% - 28px));
}

.auth-message,
.hint-text {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.right-only {
  justify-content: flex-end;
}

.comments-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.comments-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.comments-list,
.notifications-list,
.admin-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
}

.comment-item,
.notification-item,
.admin-user {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.notification-item.read {
  opacity: 0.72;
}

.comment-item p {
  margin: 0;
  color: var(--text);
}

.comment-item small,
.notification-item small,
.admin-user small {
  color: var(--muted);
}

.comment-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 12px;
  align-items: end;
}

.admin-user {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.admin-user > div:last-child {
  display: flex;
  gap: 8px;
}

.admin-user-controls {
  align-items: end;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-user-controls label {
  display: grid;
  gap: 4px;
  min-width: 150px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.admin-user-controls select {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .comment-box,
  .admin-user {
    grid-template-columns: 1fr;
  }

  .admin-user-controls {
    justify-content: flex-start;
  }
}
body.auth-required {
  background: #f4f7fb;
}

body.auth-required .app-header,
body.auth-required .app-shell {
  display: none;
}

body.auth-required::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 18%, rgba(0, 58, 112, 0.18), transparent 24rem),
    radial-gradient(circle at 78% 72%, rgba(215, 25, 32, 0.08), transparent 22rem),
    #f4f7fb;
  z-index: 0;
}

.auth-dialog {
  width: min(620px, calc(100% - 28px));
  border-radius: 18px;
}

.auth-dialog::backdrop {
  background: transparent;
}

body.auth-required .auth-dialog {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
}

.auth-dialog #authForm {
  padding: 32px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-logo {
  width: 190px;
  height: auto;
  display: block;
}

.auth-dialog .dialog-header {
  margin-bottom: 22px;
}

.auth-dialog .eyebrow {
  color: var(--blue-2);
}

.auth-dialog h2 {
  font-size: 1.55rem;
  margin-bottom: 8px;
}

.auth-subtitle {
  max-width: 460px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.auth-dialog .segmented-control {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  margin-bottom: 20px;
  background: #eef2f6;
}

.auth-dialog .segment {
  border-radius: 8px;
  min-height: 46px;
  border: 0;
}

.auth-dialog .segment.active {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(0, 58, 112, 0.2);
}

.auth-dialog .form-grid {
  gap: 16px;
}

.auth-dialog label {
  color: #526273;
}

.auth-dialog input,
.auth-dialog select {
  min-height: 46px;
  border-radius: 8px;
  background: #fff;
}

.auth-message {
  min-height: 22px;
  margin: 16px 0 0;
  color: var(--ink-red);
}

.auth-footnote {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.auth-dialog .dialog-actions {
  margin-top: 22px;
}

.auth-dialog .primary-button {
  min-width: 150px;
}

.notifications-list {
  margin-top: 4px;
}

.notification-item {
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  padding: 14px 14px 14px 18px;
  border-left: 4px solid var(--red);
  box-shadow: 0 6px 18px rgba(23, 35, 48, 0.06);
}

.notification-item strong {
  font-size: 0.95rem;
  line-height: 1.35;
}

.notification-item small {
  display: block;
  margin-top: 4px;
}

.notification-item.read {
  border-left-color: #9aa5b1;
  background: #f8fafc;
}

.notification-item.team-task {
  border-left-color: var(--blue);
  background: #f7fbff;
}

#notificationsDialog {
  width: min(620px, calc(100% - 28px));
}

#notificationsDialog form,
#adminDialog form {
  padding: 24px;
}

.admin-user {
  border-left: 4px solid var(--blue);
}
.notification-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  color: var(--text);
  font-size: 0;
  font-weight: 900;
}

.notification-button span {
  position: relative;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 9px 9px 7px 7px;
  border-bottom-width: 3px;
}

.notification-button span::before {
  content: "";
  position: absolute;
  left: 5px;
  top: -6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.notification-button span::after {
  content: "";
  position: absolute;
  left: 5px;
  bottom: -7px;
  width: 5px;
  height: 3px;
  border-radius: 0 0 5px 5px;
  background: currentColor;
}

.notification-button #notificationCount {
  position: absolute;
  top: -4px;
  right: -4px;
  margin: 0;
  min-width: 20px;
  height: 20px;
  border: 2px solid #fff;
  font-size: 0.7rem;
}

.notification-button:hover {
  border-color: var(--red);
  color: var(--red);
}

.admin-user.pending {
  border-left-color: var(--yellow);
}

.admin-user strong {
  font-size: 0.98rem;
}

.admin-user small {
  display: block;
  margin-top: 4px;
}
.auth-dialog {
  display: none;
}

body.auth-required .auth-dialog {
  display: block;
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(620px, calc(100% - 28px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  transform: translate(-50%, -50%);
  z-index: 30;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 26px 70px rgba(23, 35, 48, 0.24);
}

body:not(.auth-required) .auth-dialog {
  display: none !important;
}

body.auth-required .auth-dialog #authForm {
  padding: 30px;
}
