:root {
  --bg: #eef4fb;
  --surface: #ffffff;
  --surface-soft: #f7fbff;
  --line: #d7e4f2;
  --line-strong: #b9d1ef;
  --text: #09245a;
  --text-soft: #334767;
  --muted: #697990;
  --blue: #1558df;
  --blue-2: #2f7df4;
  --blue-3: #69b7ff;
  --cyan: #20c7f7;
  --green: #0fae72;
  --red: #e2455b;
  --amber: #f0b429;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(21, 88, 223, 0.10);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1720px, calc(100% - 36px));
  margin: 0 auto;
  padding: 20px 0 34px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 0 18px;
}

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

.brand-mark,
.metric-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #ffffff;
  background: linear-gradient(145deg, #1b61e7, #2c98ff);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 12px 22px rgba(21, 88, 223, 0.24);
}

.brand-mark {
  width: 62px;
  height: 62px;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
}

.brand-mark img {
  display: block;
  width: 62px;
  height: 62px;
}

.brand h1 {
  margin: 0;
  color: var(--text);
  font-size: 34px;
  line-height: 1.05;
  text-transform: uppercase;
}

.brand p {
  margin: 6px 0 0;
  color: var(--text-soft);
  font-size: 16px;
}

.header-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
}

.generated,
.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text-soft);
  white-space: nowrap;
}

.generated svg {
  width: 19px;
  height: 19px;
  color: var(--blue);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(240, 180, 41, 0.16);
}

.connection-pill.online .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(15, 174, 114, 0.16);
}

.connection-pill.error .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(226, 69, 91, 0.14);
}

.action-bar,
.filters-panel,
.metric-card,
.panel,
.table-panel,
.modal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  margin-bottom: 14px;
}

.quick-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.quiet-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 8px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-button {
  padding: 0 15px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(21, 88, 223, 0.20);
  font-weight: 800;
}

.ghost-button,
.quiet-button,
.icon-button {
  border: 1px solid var(--line);
  background: #f8fbff;
  color: var(--text);
}

.ghost-button,
.quiet-button {
  padding: 0 13px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.primary-button:hover,
.ghost-button:hover,
.quiet-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.inline-search {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(360px, 100%);
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.inline-search svg {
  width: 18px;
  height: 18px;
  color: var(--blue);
}

.inline-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.filters-panel {
  display: grid;
  grid-template-columns: repeat(8, minmax(120px, 1fr));
  gap: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span,
.table-controls span {
  color: #17315c;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #ffffff;
  color: var(--text);
  min-height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 92px;
  padding-top: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue-2);
  box-shadow: 0 0 0 3px rgba(47, 125, 244, 0.16);
}

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

.metric-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 112px;
  padding: 18px;
  overflow: hidden;
}

.metric-icon {
  width: 58px;
  height: 58px;
  border-radius: 8px;
}

.metric-icon.success {
  background: linear-gradient(145deg, #0f9f68, #31d38a);
}

.metric-icon.danger {
  background: linear-gradient(145deg, #cc304c, #ff697c);
}

.metric-icon.warning {
  background: linear-gradient(145deg, #d39217, #ffd05b);
}

.metric-icon svg {
  width: 28px;
  height: 28px;
}

.metric-card span {
  display: block;
  color: #17315c;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  max-width: 100%;
  margin: 3px 0;
  color: var(--blue);
  font-size: 32px;
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-card small,
.panel-heading span,
.table-header p,
.modal-heading p {
  color: var(--muted);
}

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

.panel {
  min-width: 0;
  padding: 16px;
}

.panel:nth-child(1),
.panel:nth-child(2),
.panel:nth-child(7),
.panel:nth-child(8) {
  grid-column: span 2;
}

.panel-heading,
.table-header,
.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2,
.table-header h2,
.modal-heading h2 {
  margin: 0;
  color: var(--blue);
  font-size: 18px;
  line-height: 1.25;
}

.panel-heading span {
  font-size: 13px;
  white-space: nowrap;
}

.panel canvas {
  width: 100% !important;
  height: 276px !important;
}

.table-panel {
  padding: 16px;
}

.table-header {
  align-items: center;
}

.table-header p {
  margin: 5px 0 0;
}

.table-controls {
  display: flex;
  align-items: end;
  gap: 10px;
}

.table-controls label {
  width: 110px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 12px 11px;
  border-bottom: 1px solid #e5eef8;
  vertical-align: middle;
  text-align: left;
}

th {
  background: #f5f9ff;
  color: var(--blue);
  font-size: 12px;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  color: #16243b;
  font-size: 14px;
}

tbody tr:hover {
  background: #f3f8ff;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: 900;
  text-transform: inherit;
}

.sort-button.active::after {
  content: "↓";
  color: var(--blue-2);
}

.sort-button.active.asc::after {
  content: "↑";
}

.cell-ellipsis {
  display: block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feedback-cell {
  display: inline-grid;
  grid-template-columns: 44px 44px 44px;
  gap: 5px;
}

.feedback-cell button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbff;
  color: #5a6a83;
  font-weight: 900;
}

.feedback-cell button.active-v {
  border-color: rgba(15, 174, 114, 0.55);
  background: #eafaf2;
  color: #07764c;
}

.feedback-cell button.active-x {
  border-color: rgba(226, 69, 91, 0.55);
  background: #fff0f2;
  color: #b72c43;
}

.feedback-cell button.active-blank {
  border-color: rgba(47, 125, 244, 0.55);
  background: #edf5ff;
  color: var(--blue);
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 12px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 36, 90, 0.20);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  max-height: min(820px, calc(100vh - 40px));
  overflow: auto;
  padding: 18px;
}

.modal-card.compact {
  width: min(640px, 100%);
}

.modal-heading {
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.modal-heading p {
  margin: 5px 0 0;
}

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

.form-grid .full,
.form-actions.full {
  grid-column: 1 / -1;
}

.lookup-result,
.summary-box {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--muted);
  background: var(--surface-soft);
}

.lookup-result.found {
  color: #07764c;
  border-color: rgba(15, 174, 114, 0.40);
  background: #eafaf2;
}

.lookup-result.not-found,
.summary-box.error {
  color: #b72c43;
  border-color: rgba(226, 69, 91, 0.38);
  background: #fff0f2;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.import-box {
  display: grid;
  gap: 12px;
}

.summary-box {
  white-space: pre-line;
  line-height: 1.5;
}

.details-list {
  display: grid;
  gap: 8px;
}

.detail-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #e5eef8;
}

.detail-row span {
  color: var(--blue);
  font-weight: 900;
}

.detail-row strong {
  color: var(--text);
  font-weight: 600;
  word-break: break-word;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 36px));
}

.toast {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue-2);
  border-radius: 8px;
  padding: 12px 14px;
  background: #ffffff;
  color: var(--text);
  box-shadow: var(--shadow);
}

.toast.success {
  border-left-color: var(--green);
}

.toast.error {
  border-left-color: var(--red);
}

.empty-row td {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1320px) {
  .filters-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric-grid,
  .charts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel:nth-child(n) {
    grid-column: span 1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 12px;
  }

  .app-header,
  .action-bar,
  .table-header {
    align-items: stretch;
    flex-direction: column;
  }

  .brand h1 {
    font-size: 26px;
  }

  .header-meta,
  .quick-actions {
    justify-content: flex-start;
  }

  .inline-search {
    width: 100%;
  }

  .filters-panel,
  .metric-grid,
  .charts-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 104px;
  }

  .panel canvas {
    height: 260px !important;
  }

  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .primary-button,
  .ghost-button,
  .quiet-button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
  }

  .quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .quick-actions .icon-button {
    width: 100%;
  }

  .generated,
  .connection-pill {
    width: 100%;
    white-space: normal;
  }

  .metric-card strong {
    white-space: normal;
  }

  .panel-heading {
    flex-direction: column;
  }

  .detail-row {
    grid-template-columns: 1fr;
  }
}
