:root{
  --bg:#f6f8fb;
  --panel:#ffffff;
  --panel2:#f2f5fa;
  --grid:#ffffff;
  --line:#d6dde8;
  --line2:#c7d1e0;
  --text:#0f172a;
  --muted:#4b5563;
  --accent:#2563eb;
  --accentSoft: rgba(37,99,235,.10);
  --warn:#b45309;

  --rowH:24px;
  --colW:110px;
  --rowHeadW:56px;
  --colHeadH:28px;

  --font: 13px/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}
*{box-sizing:border-box}
body{
  margin:0;
  font:var(--font);
  background:var(--bg);
  color:var(--text);
  height:100vh;
  overflow:hidden;
}
.app{ height:100vh; display:flex; flex-direction:column; }

.topbar{
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px 12px;
  background:linear-gradient(180deg, var(--panel), var(--panel2));
  border-bottom:1px solid var(--line2);
}
.brand{
  font-weight:900;
  letter-spacing:.2px;
  white-space:nowrap;
  display:flex;
  gap:10px;
  align-items:baseline;
}
.brand a{ text-decoration:none; color:inherit; }
.brand .sub{ color:var(--muted); font-weight:700; }

.group{
  display:flex;
  gap:8px;
  align-items:center;
  padding:6px 8px;
  border:1px solid var(--line2);
  border-radius:10px;
  background:rgba(15,23,42,.02);
}

.label{ color:var(--muted); font-weight:700; font-size:12px; }
.namebox{ width:90px; text-transform:uppercase; }
.formula{ width:min(520px, 38vw); }

button, input{
  background:#ffffff;
  color:var(--text);
  border:1px solid var(--line2);
  border-radius:8px;
  padding:7px 10px;
  outline:none;
}
button{ cursor:pointer; }
button:hover{ border-color:#9fb2cf; }
button:active{ transform: translateY(1px); }
button.primary{
  border-color:rgba(37,99,235,.55);
  box-shadow: 0 0 0 3px var(--accentSoft) inset;
}
button[disabled], input[disabled]{ opacity:.55; cursor:not-allowed; }

.status{ margin-left:auto; display:flex; gap:8px; align-items:center; }
.badge{
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--line2);
  background:#fff;
  color:var(--muted);
  white-space:nowrap;
}
.badge.ro{
  border-color: rgba(180,83,9,.35);
  background: rgba(180,83,9,.08);
  color: var(--warn);
  font-weight:800;
}

.workspace{ flex:1; display:flex; flex-direction:column; min-height:0; background:var(--grid); }
.headers-row{ display:flex; flex:0 0 auto; }
.corner{
  width:var(--rowHeadW); height:var(--colHeadH);
  background:#f3f6fb;
  border-right:1px solid var(--line2);
  border-bottom:1px solid var(--line2);
  flex:0 0 auto;
}
.col-headers{
  height:var(--colHeadH);
  flex:1;
  position:relative;
  overflow:hidden;
  background:#f3f6fb;
  border-bottom:1px solid var(--line2);
}
.grid-wrap{
  position:relative;
  flex:1;
  min-height:0;
  display:flex;
  overflow:hidden;
}
.row-headers{
  width:var(--rowHeadW);
  flex:0 0 auto;
  position:relative;
  overflow:hidden;
  background:#f3f6fb;
  border-right:1px solid var(--line2);
}
.sheet{
  flex:1;
  min-width:0;
  min-height:0;
  position:relative;
  overflow:auto;
  background:var(--grid);
}
.col-header-cell, .row-header-cell{
  position:absolute;
  display:flex;
  align-items:center;
  justify-content:center;
  color:var(--muted);
  border-right:1px solid var(--line2);
  border-bottom:1px solid var(--line2);
  user-select:none;
  background:#f3f6fb;
  font-weight:800;
}
.col-header-cell{ height:var(--colHeadH); top:0; }
.row-header-cell{ width:var(--rowHeadW); left:0; }
.col-header-cell.active, .row-header-cell.active{
  color:var(--text);
  background:#eaf1ff;
  border-bottom-color:#9fb2cf;
  border-right-color:#9fb2cf;
}

.cells-layer{
  position:relative;
  width:calc(var(--colW) * 200);
  height:calc(var(--rowH) * 1000);
}
.cell{
  position:absolute;
  width:var(--colW);
  height:var(--rowH);
  padding:2px 6px;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  border-right:1px solid var(--line2);
  border-bottom:1px solid var(--line2);
  background:rgba(255,255,255,1);
  color:var(--text);
  display:flex;
  align-items:center;
  user-select:none;
}
.cell.selected{
  outline:2px solid rgba(37,99,235,.95);
  outline-offset:-2px;
  z-index:2;
}
.cell.in-range{ background: rgba(37,99,235,.08); }

.editor{
  position:absolute;
  z-index:5;
  display:none;
  background:#ffffff;
  border:2px solid rgba(37,99,235,.95);
  border-radius:8px;
  box-shadow: 0 12px 30px rgba(2,6,23,.18);
}
.editor textarea{
  width:100%;
  height:100%;
  resize:none;
  padding:6px 8px;
  border:0;
  outline:none;
  background:transparent;
  color:var(--text);
  font:var(--font);
}

.sheets{
  display:flex;
  gap:8px;
  align-items:center;
  padding:8px 10px;
  border-top:1px solid var(--line2);
  background:linear-gradient(180deg, #f6f8fb, #f2f5fa);
}
.tabs{
  display:flex;
  gap:6px;
  align-items:center;
  overflow:auto;
  flex:1;
  min-width:0;
}
.tab{
  padding:7px 10px;
  border:1px solid var(--line2);
  border-radius:999px;
  color:var(--muted);
  cursor:pointer;
  user-select:none;
  white-space:nowrap;
  background:#fff;
}
.tab.active{
  color:var(--text);
  border-color:rgba(37,99,235,.55);
  box-shadow: 0 0 0 3px var(--accentSoft) inset;
}
.hint{ color:var(--muted); font-size:12px; white-space:nowrap; }
.hint a{ color:inherit; font-weight:900; text-decoration:none; }

.modal{
  position:fixed;
  inset:0;
  background: rgba(2,6,23,.55);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:20;
}
.modal .box{
  width:min(720px, 92vw);
  background:#ffffff;
  border:1px solid var(--line2);
  border-radius:14px;
  padding:14px;
  box-shadow:0 20px 50px rgba(2,6,23,.28);
}
.modal .msg{
  color:#111827;
  background:#f8fafc;
  border:1px solid var(--line2);
  border-radius:12px;
  padding:12px;
  line-height:1.45;
  margin:10px 0;
}
.modal .actions{ display:flex; justify-content:flex-end; }
