:root {
  --excel-green: #0f7f3a;
  --grid-line: #d9d9d9;
  --panel-line: #cfcfcf;
  --sheet-bg: #ffffff;
  --ribbon-bg: #f3f3f3;
  --text: #1f2933;
  --muted: #5f6b76;
  --blue: #5b9bd5;
  --green: #a9d18e;
  --yellow: #fff2cc;
  --red: #ff6f79;
  --gold: #ffd966;
  --cyan: #9dc3e6;
  --gray: #d9e2ea;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: #111;
  font-size: 13px;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid #b8c6d5;
  background: linear-gradient(#ffffff, #edf4fb);
  color: #17456d;
  min-height: 28px;
  padding: 4px 10px;
  line-height: 1.15;
  cursor: pointer;
}

button:hover {
  background: #dceefa;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

input {
  border: 1px solid #aebdcc;
  background: #fff;
  min-height: 28px;
  min-width: 0;
  width: 100%;
  padding: 4px 6px;
}

a {
  color: #1f4e79;
}

.app-shell {
  min-height: 100vh;
  background: #f8f8f8;
  display: flex;
  flex-direction: column;
  padding-bottom: 46px;
}

.excel-topbar {
  background: var(--ribbon-bg);
  border-bottom: 1px solid var(--panel-line);
}

.title-strip {
  min-height: 32px;
  background: #f7f7f7;
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #d4d4d4;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 10px;
  min-width: 260px;
  border-right: 1px solid #d4d4d4;
  background: #fff;
}

.brand-logo {
  width: 26px;
  height: 24px;
  border: 1px solid #0f7f3a;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 2px;
  padding: 3px;
  background: #f7fff9;
}

.brand-logo i {
  display: block;
  background: var(--excel-green);
}

.brand-logo i:nth-child(1) {
  height: 8px;
}

.brand-logo i:nth-child(2) {
  height: 14px;
}

.brand-logo i:nth-child(3) {
  height: 18px;
  background: #2f9de0;
}

.brand-text {
  font-size: 12px;
  font-weight: 700;
  color: #17324d;
  white-space: nowrap;
}

.file-tab {
  width: 62px;
  min-height: 32px;
  color: #fff;
  background: var(--excel-green);
  border: 0;
  text-transform: uppercase;
  font-weight: 700;
}

.menu-tabs {
  display: flex;
  gap: 2px;
  align-items: stretch;
  overflow-x: auto;
}

.menu-tabs button {
  border: 0;
  background: transparent;
  color: #111827;
  padding: 0 14px;
  min-height: 28px;
  text-transform: uppercase;
  font-size: 11px;
}

.menu-tabs button:hover {
  background: #e2e8f0;
}

.menu-tabs button.is-active {
  background: linear-gradient(#f5fff7, #dff6e7);
  box-shadow:
    inset 0 -3px 0 #39b86d,
    0 0 0 1px rgba(15, 127, 58, .14),
    0 8px 18px rgba(15, 127, 58, .08);
  color: #0f5132;
}

.menu-tabs button:focus-visible,
.file-tab:focus-visible {
  outline: 2px solid #2f9de0;
  outline-offset: -2px;
}

.file-tab.is-active {
  background: #0a6b31;
}

.user-name {
  margin-left: auto;
  padding: 6px 18px 0;
  font-size: 15px;
  font-weight: 700;
  color: #17324d;
  white-space: nowrap;
}

.ribbon {
  display: grid;
  grid-template-columns: minmax(260px, .9fr) minmax(520px, 2.8fr) minmax(180px, .7fr);
  gap: 10px;
  padding: 8px;
  min-height: 98px;
  align-items: stretch;
}

.ribbon-group {
  border: 1px solid #d3d7dc;
  background: #f8f8f8;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.ribbon-group > label {
  color: #52606d;
  font-size: 12px;
}

.ribbon-group > span {
  margin-top: auto;
  text-align: center;
  color: #64748b;
  font-size: 11px;
}

.inline-controls {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 120px;
  gap: 6px;
  min-width: 0;
}

.primary-action {
  color: #fff;
  background: #2f9de0;
  border-color: #1977af;
}

.primary-action:hover {
  background: #238ed0;
}

.risk-toggle-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 6px;
}

.risk-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 6px;
  border: 1px solid #d5dce3;
  background: #fff;
  color: #253858;
  font-size: 11px;
}

.risk-toggle input {
  width: 14px;
  min-height: 14px;
  margin: 0;
}

.request-badge {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--panel-line);
  background: #fff;
  color: #1f4e79;
  font-weight: 700;
  text-align: center;
}

.request-badge.error {
  background: #f8d7da;
  color: #842029;
}

.request-badge.ok {
  background: #d1e7dd;
  color: #0f5132;
}

.source-box {
  display: grid;
  gap: 5px;
  min-height: 34px;
  border: 1px solid var(--panel-line);
  background: #fff;
  padding: 6px 8px;
}

.source-box strong {
  color: #1f4e79;
}

.source-status.error {
  color: #842029;
}

.source-status.ok {
  color: #0f5132;
}

.formula-row {
  display: grid;
  grid-template-columns: 90px 34px 1fr;
  align-items: center;
  height: 26px;
  border-top: 1px solid #e4e7eb;
  background: #fbfbfb;
}

.name-box,
.fx,
.formula-box {
  height: 100%;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--panel-line);
  padding: 0 8px;
}

.fx {
  justify-content: center;
  font-style: italic;
  color: #1f4e79;
}

.formula-box {
  color: #425466;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(330px, 34vw);
  gap: 8px;
  padding: 0 8px 8px;
  overflow: hidden;
}

.sheet-area,
.dashboard {
  background-color: var(--sheet-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 24px;
  border: 1px solid var(--panel-line);
  min-height: 480px;
}

.sheet-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px 6px;
}

.note-title {
  margin: 0 0 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-style: italic;
  color: #111827;
}

.note-text {
  margin: 0;
  color: #1f4e79;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--panel-line);
  font-size: 11px;
}

.legend-color {
  width: 14px;
  height: 10px;
  border: 1px solid rgba(0, 0, 0, .12);
}

.legend-color.ok {
  background: #c6efce;
}

.legend-color.warn {
  background: #f4b6c2;
}

.legend-color.muted {
  background: var(--gray);
}

.company-card {
  margin: 8px 14px 14px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, .92);
}

.company-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--grid-line);
  background: #f8fafc;
}

.company-head h1 {
  margin: 0 0 6px;
  font-size: 21px;
  line-height: 1.2;
  color: #17324d;
}

.company-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 116px;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid #8abf9b;
  background: #c6efce;
  color: #21562d;
  font-weight: 700;
  text-align: center;
}

.status-pill.inactive {
  border-color: #e4a7b1;
  background: #f4b6c2;
  color: #7c1d2a;
}

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

.details-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.details-table th,
.details-table td {
  border: 1px solid var(--grid-line);
  min-height: 28px;
  padding: 7px 8px;
  vertical-align: top;
}

.details-table th {
  width: 190px;
  background: #f6f8fa;
  text-align: left;
  color: #253858;
}

.details-table td {
  background: rgba(255, 255, 255, .88);
  line-height: 1.4;
}

.empty-state {
  margin: 22px 14px;
  border: 1px dashed #aebdcc;
  background: rgba(255, 255, 255, .88);
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: #17324d;
  font-size: 18px;
}

.dashboard {
  padding: 14px;
  overflow: auto;
}

.dashboard h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-align: center;
}

.risk-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.risk-item {
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, .92);
  padding: 8px;
}

.risk-item strong {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: #17324d;
}

.risk-state {
  min-width: 74px;
  padding: 2px 5px;
  text-align: center;
  border: 1px solid #aac4ad;
  background: #c6efce;
  font-size: 11px;
  color: #21562d;
}

.risk-item.active .risk-state {
  border-color: #e4a7b1;
  background: #f4b6c2;
  color: #7c1d2a;
}

.risk-item.unknown .risk-state {
  border-color: #bdc8d4;
  background: var(--gray);
  color: #425466;
}

.risk-item span:last-child {
  color: var(--muted);
  line-height: 1.35;
}

.chart-box,
.category-panel {
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--panel-line);
  padding: 12px;
  margin-bottom: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, .86);
}

.stat-cell {
  min-height: 70px;
  border: 1px solid var(--grid-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.stat-cell strong {
  font-size: 22px;
  color: #1f4e79;
  text-align: center;
}

.stat-cell span {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.source-main {
  margin: 0 0 8px;
  color: #17324d;
  text-align: center;
}

.source-note {
  margin: 0;
  color: #667085;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}

.result-glow,
.result-glow-fill,
.company-card.result-glow-card,
.risk-item.result-glow-card {
  box-shadow:
    0 0 0 2px rgba(57, 184, 109, .28),
    0 0 18px rgba(76, 222, 128, .34);
  outline: 1px solid rgba(57, 184, 109, .28);
}

.result-glow-fill,
.company-card.result-glow-card,
.risk-item.result-glow-card {
  background:
    linear-gradient(rgba(245, 255, 247, .94), rgba(223, 246, 231, .94)),
    rgba(255, 255, 255, .92);
}

.error-state {
  padding: 18px;
  background: #fff6f6;
  border: 1px solid #f0a6a6;
  color: #7f1d1d;
}

.bottom-bar {
  min-height: 46px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  background: #f8f8f8;
  border-top: 1px solid var(--panel-line);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
}

.source-footer {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  padding: 5px 12px;
  color: #17324d;
  font-size: 11px;
}

.source-footer span {
  margin-right: 10px;
}

.source-footer small {
  color: #667085;
}

.status-ready {
  color: #fff;
  background: var(--excel-green);
  padding: 4px 12px;
  text-transform: uppercase;
}

.zoom {
  min-width: 90px;
  color: #fff;
  background: var(--excel-green);
  padding: 4px 12px;
  text-align: right;
}

@media (max-width: 1080px) {
  .ribbon {
    grid-template-columns: 1fr 1fr;
  }

  .ribbon-group.wide {
    grid-column: 1 / -1;
    order: 3;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 12px;
  }

  .title-strip {
    height: auto;
    flex-wrap: wrap;
  }

  .brand-mark {
    min-width: 100%;
    min-height: 38px;
    border-bottom: 1px solid #d4d4d4;
  }

  .brand-text {
    white-space: normal;
  }

  .menu-tabs {
    order: 3;
    width: 100%;
  }

  .menu-tabs button {
    min-width: 92px;
  }

  .ribbon,
  .inline-controls,
  .risk-toggle-grid {
    grid-template-columns: 1fr;
  }

  .formula-row {
    grid-template-columns: 72px 28px minmax(180px, 1fr);
    overflow-x: auto;
  }

  .workspace {
    padding: 0 4px 8px;
  }

  .sheet-toolbar,
  .company-head {
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }

  .dashboard {
    padding: 10px;
  }

  .bottom-bar {
    grid-template-columns: 1fr;
  }

  .source-footer {
    padding: 0 4px;
  }

  .status-ready,
  .zoom {
    display: none;
  }
}

@media print {
  .excel-topbar,
  .bottom-bar,
  .risk-toggle-grid,
  .source-footer {
    display: none !important;
  }

  .app-shell,
  body {
    background: #fff;
  }

  .workspace {
    display: block;
    padding: 0;
    overflow: visible;
  }

  .sheet-area,
  .dashboard {
    border: 0;
    min-height: auto;
    background-image: none;
  }
}
