@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

:root {
  --ink: #111c35;
  --muted: #536785;
  --line: #dce5f3;
  --blue: #2563eb;
  --pale: #f4f7fc;
  --height: 100vh
}

* {
  box-sizing: border-box
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif
}

body {
  height: var(--height);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right)
}

[hidden] {
  display: none !important
}

.backBtn {
  display: none;
}

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

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent
}

button {
  cursor: pointer;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 13px;
  touch-action: manipulation
}

button:disabled {
  opacity: .42;
  cursor: default
}

button:hover:not(:disabled) {
  background: #edf3ff
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  min-width: 0;
  padding: 9px
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #a7c4ff;
  outline-offset: -1px
}

svg {
  width: 24px;
  height: 24px;
  flex: none;
  vertical-align: middle
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 9px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-decoration: none
}

.primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  font-weight: 600
}

.primary:hover:not(:disabled) {
  background: #154fcb
}

.home-header {
  height: 50px;
  min-height: 50px;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.home-header .backBtn,
.home-header > .icon-button:first-child {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  border: none;
  color: inherit;
  cursor: pointer;
}

.home-header h1 {
  font-size: 1.2rem;
  font-weight: 400;
  font-style: normal;
  letter-spacing: normal;
  font-family: "Roboto", sans-serif;
  color: #000;
  margin: 0 auto;
  text-align: center;
}

.home-header .icon-button[data-action="help"] {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.home-header .icon-button {
  color: #50678e;
  width: 34px;
  height: 34px;
}

.home-header svg {
  width: 24px;
  height: 24px;
}

.home-main {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 22px
}

.home-cards {
  display: flex;
  flex-direction: column;
  gap: 34px;
  width: 100%;
  max-width: 860px;
  margin-top: -30px
}

.home-card {
  display: flex;
  align-items: center;
  gap: 36px;
  padding: 20px 40px;
  border: 2px solid #d9e5fa;
  border-radius: 25px;
  min-height: 146px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 2px 6px #17366b07
}

.home-card:hover {
  background: #fafcff
}

.card-icon {
  width: 102px;
  height: 102px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0
}

.card-icon svg {
  width: 54px;
  height: 54px
}

.blue {
  background: #e0ecff;
  color: #2162f4
}

.green {
  background: #dcf9e7;
  color: #10a453
}

.purple {
  background: #ebe4ff;
  color: #6b32ef
}

.orange {
  background: #fff0dc;
  color: #e85e00
}

.card-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 9px
}

.card-copy strong {
  font-size: 29px
}

.card-copy>span {
  font-size: 21px;
  color: #49678f;
  line-height: 1.35
}

.chevron {
  color: #5b6e90
}

.chevron svg {
  width: 26px;
  height: 26px
}

.app-header {
  min-height: 50px;
  height: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
}

.app-header .back {
  width: 34px !important;
  height: 34px !important;
  border-radius: 8px !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header .back svg {
  width: 24px !important;
  height: 24px !important;
  stroke-width: 2.5 !important;
}

.app-header h1 {
  font-size: 1.2rem !important;
  font-weight: 400 !important;
  font-style: normal !important;
  letter-spacing: normal !important;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 20px;
  text-align: left;
}

.history-buttons {
  display: flex;
  gap: 14px
}

.download-excel {
  border-radius: 28px;
  padding: 12px 28px;
  white-space: nowrap
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  flex-shrink: 0;
  padding: 12px 20px 10px;
  border-bottom: 1px solid var(--line)
}

.tool-group {
  min-width: 0;
  flex: 1
}

.text-tools {
  flex-basis: 590px
}

.insert-tools {
  flex-basis: 470px
}

.group-label {
  font-size: 10px;
  font-weight: 700;
  display: block;
  margin-bottom: 5px;
  color: #435671
}

.tool-controls {
  display: flex;
  align-items: center;
  gap: 5px
}

.text-tools .tool-controls {
  display: grid;
  grid-template-columns: minmax(78px, 1.6fr) minmax(64px, .9fr) repeat(10, minmax(30px, .7fr))
}

.text-tools select {
  width: 100%;
  height: 44px;
  padding: 5px 8px;
  font-size: 14px
}

.format-button {
  font-size: 19px;
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  background: transparent
}

.format-button svg {
  width: 23px;
  height: 23px
}

.format-button[aria-pressed=true] {
  background: #dceaff;
  color: #1c5eff
}

.color-control {
  position: relative;
  height: 44px;
  min-width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer
}

.color-control i {
  width: 20px;
  height: 4px;
  background: #d80019;
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%)
}

.fill-control i {
  background: #ffe859
}

.color-control input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  padding: 0;
  cursor: pointer
}

.insert-tools .tool-controls {
  display: grid;
  grid-template-columns: repeat(10, minmax(36px, 1fr));
  gap: 5px;
  align-items: start
}

.insert-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  padding: 0;
  min-width: 0;
  font-size: 10px;
  white-space: nowrap
}

.insert-symbol {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px
}

.insert-symbol svg {
  width: 22px;
  height: 22px
}

.fx {
  font-style: italic;
  font-weight: 700;
  color: #2162f4
}

.insert-symbol .fx {
  color: inherit;
  font-size: 20px
}

.mobile-tools {
  display: none
}

.formula-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  min-height: 52px
}

.formula-bar #cellAddress {
  width: 90px;
  text-align: center;
  font-weight: 600
}

.formula-bar #formulaInput {
  flex: 1
}

.formula-bar input {
  height: 36px;
  font-size: 16px
}

.formula-bar .fx {
  margin-left: 3px
}

.work-area {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: white
}

#grid {
  height: 100%;
  width: 100%;
  overflow: hidden
}

.jexcel_container {
  width: 100% !important;
  height: 100% !important;
  padding: 0 !important;
  display: block !important
}

.jexcel_content {
  width: 100% !important;
  max-height: none !important;
  height: 100% !important;
  box-shadow: none !important;
  border: 0 !important;
  overflow: auto !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch
}

.jexcel {
  font-family: Calibri, Arial, sans-serif !important;
  font-size: 14px !important;
  border: 0 !important;
  table-layout: fixed
}

.jexcel>thead>tr>td {
  background: #f1f5fa !important;
  color: #435671 !important;
  height: 26px !important;
  border-color: var(--line) !important;
  font-weight: 600;
  top: 0 !important;
  position: sticky !important;
  z-index: 3 !important
}

.jexcel>tbody>tr>td {
  border-color: #e1e8f2 !important;
  padding: 5px 9px !important;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #fff;
  line-height: 1.25
}

.jexcel>tbody>tr>td:first-child {
  background: #f1f5fa !important;
  font-weight: 600;
  color: #435671 !important;
  position: sticky !important;
  left: 0 !important;
  z-index: 2 !important;
  min-width: 40px
}

.jexcel>thead>tr>td:first-child {
  z-index: 5 !important;
  left: 0 !important
}

.jexcel>tbody>tr>td.highlight {
  background-color: #eef4ff
}

.jexcel td.editor {
  padding: 0 !important;
  overflow: visible !important
}

.jexcel td.editor input,
.jexcel td.editor textarea {
  font-size: 16px !important;
  background: #fff !important
}

.jexcel_about {
  display: none
}

.jexcel_corner {
  z-index: 6 !important
}

.jexcel td.has-note:after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  border-top: 7px solid #e68a00;
  border-left: 7px solid transparent
}

.jexcel td.has-note {
  position: relative
}

.jexcel td.search-hit {
  background: #fff09b !important;
  box-shadow: inset 0 0 0 1px #ebc331
}

.jexcel td.search-current {
  background: #ffca64 !important;
  box-shadow: inset 0 0 0 2px #a25300
}

.jexcel td.formula-error {
  color: #bd2c36 !important
}

.sheet-bar {
  min-height: 40px;
  display: flex;
  gap: 6px;
  align-items: center;
  background: #f7f9fc;
  border-top: 1px solid var(--line);
  padding: 4px 12px;
  flex-shrink: 0;
  min-width: 0
}

.sheet-bar button {
  padding: 6px 13px;
  font-size: 13px
}

.sheet-bar #sheetTabs {
  display: flex;
  overflow: auto;
  gap: 4px;
  max-width: 65%;
  scrollbar-width: thin
}

.sheet-bar [role=tab] {
  white-space: nowrap;
  border: 0;
  background: transparent
}

.sheet-bar [aria-selected=true] {
  color: #1c5bef;
  background: #e2edff;
  border-radius: 6px;
  font-weight: 600
}

.sheet-plus {
  font-size: 22px !important;
  line-height: 1;
  padding: 4px 10px !important
}

#sheetSelect {
  display: none;
  font-size: 14px;
  padding: 5px;
  max-width: 45%
}

#status {
  flex: 1;
  text-align: right;
  font-size: 11px;
  color: #536785;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.sheet-navigation {
  display: flex;
  align-items: center;
  gap: 10px
}

.sheet-navigation .icon-button {
  background: #eaf0fb;
  border-radius: 10px
}

.sheet-navigation span {
  font-size: 20px;
  padding: 8px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  white-space: nowrap
}

.empty-state {
  position: absolute;
  inset: 22px 8%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 2px 10px #12345807;
  padding: 18px
}

.empty-state>svg {
  width: 95px;
  height: 110px;
  color: #d5e1f6
}

.empty-state h2 {
  font-size: 22px;
  margin: 12px 0 0
}

.empty-state p {
  color: #536785;
  font-size: 14px
}

.empty-state .privacy-copy {
  font-size: 12px
}

.empty-state .primary {
  min-width: 150px
}

.viewer-actions {
  display: flex;
  flex-shrink: 0;
  background: #f8faff;
  border-top: 1px solid var(--line);
  padding: 14px 0
}

.viewer-actions button {
  flex: 1;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  font-size: 20px;
  color: #172752;
  padding: 4px
}

.viewer-actions button:last-child {
  border-right: 0
}

.viewer-actions svg {
  width: 32px;
  height: 32px
}

.search-panel {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding: 7px 14px;
  border-top: 1px solid var(--line);
  background: white
}

.search-panel input {
  flex: 1;
  font-size: 16px;
  height: 36px
}

.search-panel>span {
  font-size: 12px;
  white-space: nowrap
}

.search-panel .icon-button {
  width: 32px;
  height: 34px;
  padding: 6px
}

.drawing-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden
}

.drawing {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  object-fit: fill;
  box-shadow: 0 1px 3px #142a501a
}

.drawing:hover {
  outline: 2px solid #638fef
}

body[data-mode=view] .drawing {
  pointer-events: none
}

.modal-shade {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #10214166;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px
}

.dialog {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 80px #12295655;
  max-width: 480px;
  width: 100%;
  max-height: 92%;
  overflow: auto;
  padding: 24px
}

.dialog h2 {
  font-size: 21px;
  margin: 0 0 15px
}

.dialog p,
.dialog li {
  font-size: 14px;
  line-height: 1.5;
  color: #405674
}

.dialog ul {
  padding-left: 20px
}

.dialog label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 13px 0;
  font-size: 13px;
  font-weight: 600
}

.dialog input,
.dialog select,
.dialog textarea {
  font-size: 16px;
  font-weight: 400;
  width: 100%
}

.dialog textarea {
  min-height: 84px;
  resize: vertical
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px
}

.field-error {
  color: #b52332 !important;
  margin: 8px 0 0 !important
}

.toast {
  position: fixed;
  z-index: 20000;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  border-radius: 9px;
  background: #14243a;
  color: #fff;
  max-width: 92%;
  padding: 13px 20px;
  font-size: 14px;
  box-shadow: 0 4px 20px #0a244d33
}

.busy {
  position: fixed;
  inset: 0;
  background: #fffffff2;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px
}

.busy span {
  background: #f0f5ff;
  border: 1px solid var(--line);
  padding: 20px;
  border-radius: 12px
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px
}

.choice-list button {
  text-align: left;
  padding: 12px
}

.small-note {
  font-size: 12px !important
}

.inline-fields {
  display: flex;
  gap: 12px
}

.inline-fields>* {
  flex: 1;
  min-width: 0
}

@media(min-width:1400px) {
  .text-tools {
    flex: 1.2
  }

  .insert-tools {
    flex: 1
  }

  .app-header {
    min-height: 80px
  }

  .toolbar {
    padding-top: 18px;
    padding-bottom: 13px
  }

  .insert-symbol {
    width: 46px;
    height: 44px
  }
}

@media(max-width:760px) {
  .home-header {
    height: 65px;
    padding: 0 12px
  }

  .home-header h1 {
    font-size: 1.2rem;
    font-weight: 400;
  }

  .home-header .icon-button {
    width: 40px;
    height: 40px
  }

  .home-header svg {
    width: 28px;
    height: 28px
  }

  .home-main {
    padding: 20px
  }

  .home-cards {
    gap: 18px;
    margin-top: 0;
    max-width: 540px
  }

  .home-card {
    gap: 18px;
    min-height: 105px;
    border-radius: 18px;
    padding: 18px
  }

  .card-icon {
    width: 68px;
    height: 68px;
    border-radius: 16px
  }

  .card-icon svg {
    width: 37px;
    height: 37px
  }

  .card-copy strong {
    font-size: 21px
  }

  .card-copy>span {
    font-size: 15px;
    line-height: 1.3
  }

  .chevron svg {
    width: 18px
  }

  .app-header {
    min-height: 56px;
    padding: 7px 10px;
    gap: 8px
  }

  .app-header .icon-button {
    width: 36px;
    height: 36px;
    padding: 7px
  }

  .app-header h1 {
    font-size: 18px
  }

  .history-buttons {
    gap: 0
  }

  .download-excel {
    font-size: 12px;
    padding: 9px 12px
  }

  .toolbar {
    padding: 5px 10px 7px;
    display: block
  }

  .mobile-tools {
    display: flex;
    gap: 6px;
    margin-bottom: 5px
  }

  .mobile-tools button {
    border: 0;
    background: #f0f4fa;
    padding: 5px 18px;
    font-size: 12px
  }

  .mobile-tools button.active {
    background: #deebff;
    color: #145adb
  }

  .group-label {
    display: none
  }

  .tool-group {
    width: 100%
  }

  .insert-tools {
    display: none
  }

  .toolbar.show-insert .insert-tools {
    display: block
  }

  .toolbar.show-insert .text-tools {
    display: none
  }

  .text-tools .tool-controls {
    grid-template-columns: minmax(76px, 1.6fr) 62px repeat(4, minmax(31px, 1fr));
    gap: 3px
  }

  .format-button,
  .color-control,
  .text-tools select {
    height: 34px
  }

  .text-tools select {
    font-size: 12px;
    padding: 4px
  }

  .format-button {
    font-size: 17px
  }

  .format-button svg {
    height: 20px;
    width: 20px
  }

  .insert-tools .tool-controls {
    grid-template-columns: repeat(10, minmax(28px, 1fr));
    gap: 3px
  }

  .insert-symbol {
    width: 36px;
    height: 36px
  }

  .insert-button {
    font-size: 9px;
    gap: 3px
  }

  .formula-bar {
    padding: 5px 10px;
    gap: 7px;
    min-height: 41px
  }

  .formula-bar input {
    height: 31px;
    padding: 4px 7px
  }

  .formula-bar #cellAddress {
    width: 72px;
    font-size: 13px
  }

  .sheet-bar {
    min-height: 36px;
    padding: 3px 8px
  }

  .sheet-bar #sheetTabs {
    display: none
  }

  #sheetSelect {
    display: block
  }

  #status {
    font-size: 10px
  }

  .sheet-bar .choose-small {
    font-size: 11px;
    padding: 5px
  }

  .sheet-navigation {
    gap: 3px
  }

  .sheet-navigation span {
    font-size: 12px;
    padding: 8px
  }

  .sheet-navigation .icon-button {
    width: 30px;
    height: 32px
  }

  .viewer-actions {
    padding: 8px 0
  }

  .viewer-actions button {
    font-size: 15px;
    gap: 2px
  }

  .viewer-actions svg {
    width: 26px;
    height: 26px
  }

  .empty-state {
    inset: 14px
  }

  .empty-state>svg {
    height: 72px;
    width: 62px
  }

  .empty-state h2 {
    font-size: 19px
  }

  .dialog {
    padding: 18px
  }

  .search-panel {
    padding: 5px 8px;
    gap: 2px
  }

  .search-panel>span {
    max-width: 80px;
    white-space: normal
  }

  .search-panel .icon-button {
    width: 29px
  }

  .jexcel>tbody>tr>td {
    font-size: 13px
  }
}

@media(max-width:450px) {
  .home-main {
    padding: 16px
  }

  .home-card {
    padding: 15px;
    gap: 14px;
    min-height: 100px
  }

  .card-icon {
    width: 55px;
    height: 60px;
    border-radius: 13px
  }

  .card-icon svg {
    width: 31px
  }

  .card-copy strong {
    font-size: 18px
  }

  .card-copy>span {
    font-size: 13px
  }

  .card-copy {
    gap: 6px
  }

  .home-header h1 {
    font-size: 1.2rem;
    font-weight: 400;
  }

  .app-header {
    gap: 5px;
    padding: 6px
  }

  .app-header h1 {
    font-size: 15px
  }

  .app-header .icon-button {
    width: 31px;
    height: 34px;
    padding: 6px
  }

  .download-excel {
    font-size: 11px;
    padding: 8px 10px
  }

  .insert-tools .tool-controls {
    grid-template-columns: repeat(5, 1fr);
    row-gap: 5px
  }

  .insert-symbol {
    height: 30px;
    width: 34px
  }

  .insert-symbol svg {
    height: 20px
  }

  .insert-button {
    font-size: 9px;
    gap: 2px
  }

  .formula-bar {
    padding-left: 6px;
    padding-right: 6px
  }

  .formula-bar #cellAddress {
    width: 64px
  }

  .toolbar {
    padding-left: 8px;
    padding-right: 8px
  }

  #status {
    max-width: 140px
  }

  .sheet-navigation span {
    padding: 6px;
    font-size: 11px
  }
}

.jexcel>thead>tr>td {
  text-align: center !important
}

.jexcel .highlight-top {
  border-top: 2px solid #2563eb !important
}

.jexcel .highlight-bottom {
  border-bottom: 2px solid #2563eb !important
}

.jexcel .highlight-left {
  border-left: 2px solid #2563eb !important
}

.jexcel .highlight-right {
  border-right: 2px solid #2563eb !important
}

.jexcel_corner {
  background: #2563eb !important;
  border-color: #2563eb !important
}

.drawing-layer,
.modal-shade,
.busy {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0
}

@media(max-height:500px) and (orientation:landscape) {
  .home-header {
    height: 50px
  }

  .home-header h1 {
    font-size: 1.2rem;
    font-weight: 400;
  }

  .home-main {
    padding: 14px
  }

  .home-cards {
    flex-direction: row;
    gap: 14px;
    max-width: 960px;
    margin: 0
  }

  .home-card {
    flex: 1;
    min-width: 0;
    flex-direction: column;
    gap: 10px;
    padding: 15px 12px;
    text-align: center;
    min-height: 0;
    border-radius: 16px
  }

  .card-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px
  }

  .card-icon svg {
    width: 30px;
    height: 30px
  }

  .card-copy strong {
    font-size: 17px
  }

  .card-copy>span {
    font-size: 13px
  }

  .chevron {
    display: none
  }

  .app-header {
    min-height: 45px;
    height: 45px;
    padding: 4px 10px
  }

  .app-header h1 {
    font-size: 18px
  }

  .app-header .icon-button {
    height: 32px;
    width: 32px
  }

  .download-excel {
    padding: 7px 16px
  }

  .toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 4px 8px
  }

  .mobile-tools {
    flex-direction: column;
    gap: 2px;
    margin: 0;
    flex: none
  }

  .mobile-tools button {
    padding: 3px 10px
  }

  .tool-group {
    flex: 1
  }

  .text-tools .tool-controls {
    grid-template-columns: minmax(66px, 1.4fr) 62px repeat(10, minmax(27px, 1fr))
  }

  .tool-controls {
    gap: 2px
  }

  .insert-symbol {
    height: 30px;
    width: 32px
  }

  .insert-button {
    font-size: 9px;
    gap: 2px
  }

  .insert-tools .tool-controls {
    grid-template-columns: repeat(10, 1fr)
  }

  .formula-bar {
    min-height: 36px;
    padding-top: 3px;
    padding-bottom: 3px
  }

  .formula-bar input {
    height: 28px
  }

  .viewer-actions {
    padding: 5px 0
  }

  .viewer-actions button {
    flex-direction: row;
    justify-content: center;
    font-size: 14px;
    gap: 8px
  }

  .viewer-actions svg {
    width: 22px;
    height: 22px
  }

  .sheet-bar {
    min-height: 30px
  }

  .empty-state {
    inset: 10px
  }

  .empty-state>svg,
  .empty-state .privacy-copy {
    display: none
  }

  .empty-state h2 {
    margin: 0;
    font-size: 18px
  }

  .empty-state p {
    margin: 6px 0
  }

  .empty-state .primary {
    padding: 7px 20px
  }
}

/* ===== Compact responsive sizing (scales with viewport width and height) ===== */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%
}

button {
  padding: 6px 11px;
  font-size: 13px;
  border-radius: 7px
}

input,
select,
textarea {
  padding: 6px 8px;
  font-size: 13px
}

svg {
  width: 20px;
  height: 20px
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 6px
}

.home-header {
  height: clamp(44px, 8vh, 60px);
  padding: 0 clamp(10px, 2.4vw, 22px)
}

.home-header h1 {
  font-size: 1.2rem;
  font-weight: 400;
}

.home-header .icon-button {
  width: clamp(32px, 5.5vh, 40px);
  height: clamp(32px, 5.5vh, 40px)
}

.home-header svg {
  width: clamp(20px, 3.6vh, 26px);
  height: clamp(20px, 3.6vh, 26px)
}

.home-main {
  padding: clamp(10px, 2.4vh, 20px) clamp(12px, 3vw, 22px)
}

.home-cards {
  gap: clamp(10px, 2.4vh, 18px);
  max-width: 720px;
  margin-top: 0
}

.home-card {
  gap: clamp(10px, 2.4vw, 20px);
  padding: clamp(10px, 2vh, 16px) clamp(12px, 3vw, 26px);
  min-height: 0;
  border-radius: clamp(12px, 2.4vw, 18px);
  border-width: 1.5px
}

.card-icon {
  width: clamp(38px, min(11vw, 8.5vh), 60px);
  height: clamp(38px, min(11vw, 8.5vh), 60px);
  border-radius: clamp(10px, 2vw, 14px)
}

.card-icon svg {
  width: 52%;
  height: 52%
}

.card-copy {
  gap: 3px
}

.card-copy strong {
  font-size: clamp(14px, min(4vw, 2.8vh), 20px)
}

.card-copy>span {
  font-size: clamp(11px, min(3vw, 2.1vh), 14px);
  line-height: 1.3
}

.chevron svg {
  width: 16px;
  height: 16px
}

.app-header {
  min-height: clamp(40px, 7.5vh, 50px);
  padding: 4px clamp(8px, 1.8vw, 16px);
  gap: clamp(6px, 1.4vw, 12px)
}

.app-header h1 {
  font-size: clamp(14px, min(3.6vw, 3vh), 18px)
}

.app-header .icon-button {
  width: clamp(30px, 5.2vh, 34px);
  height: clamp(30px, 5.2vh, 34px);
  padding: 6px
}

.history-buttons {
  gap: 2px
}

.download-excel {
  padding: 6px clamp(10px, 2vw, 18px);
  font-size: clamp(11px, min(3vw, 2.2vh), 13px);
  border-radius: 18px
}

.sheet-navigation {
  gap: 4px
}

.sheet-navigation span {
  font-size: clamp(11px, min(3vw, 2.2vh), 13px);
  padding: 5px clamp(6px, 1.4vw, 12px);
  border-radius: 8px
}

.sheet-navigation .icon-button {
  width: clamp(28px, 4.8vh, 32px);
  height: clamp(28px, 4.8vh, 32px);
  border-radius: 8px;
  padding: 5px
}

.toolbar {
  gap: 6px 14px;
  padding: 6px clamp(8px, 1.6vw, 16px)
}

.text-tools {
  flex-basis: 480px
}

.insert-tools {
  flex-basis: 400px
}

.group-label {
  font-size: 9px;
  margin-bottom: 3px
}

.text-tools select {
  height: 32px;
  font-size: 12px;
  padding: 3px 6px
}

.format-button {
  height: 32px;
  font-size: 15px;
  padding: 3px;
  border-radius: 7px
}

.format-button svg {
  width: 18px;
  height: 18px
}

.color-control {
  height: 32px;
  font-size: 16px
}

.color-control i {
  height: 3px;
  width: 16px;
  bottom: 4px
}

.insert-symbol {
  width: 32px;
  height: 32px;
  border-radius: 8px
}

.insert-symbol svg {
  width: 18px;
  height: 18px
}

.insert-symbol .fx {
  font-size: 16px
}

.insert-button {
  font-size: 9px;
  gap: 2px
}

.mobile-tools button {
  padding: 4px 14px;
  font-size: 11px
}

.formula-bar {
  padding: 4px clamp(8px, 1.6vw, 14px);
  gap: 6px;
  min-height: 0
}

.formula-bar #cellAddress {
  width: clamp(56px, 10vw, 80px);
  font-size: 13px
}

.formula-bar input {
  height: 28px;
  font-size: 13px;
  padding: 3px 6px
}

.jexcel {
  font-size: 13px !important
}

.jexcel>thead>tr>td {
  font-size: 12px
}

.jexcel>tbody>tr>td {
  padding: 3px 7px !important;
  font-size: 13px
}

.jexcel>tbody>tr:not([height]) {
  height: 24px
}

.jexcel>tbody>tr>td.jexcel_row {
  cursor: default
}

.sheet-bar {
  min-height: 30px;
  padding: 3px clamp(8px, 1.6vw, 12px)
}

.sheet-bar button {
  padding: 4px 10px;
  font-size: 12px
}

.sheet-bar .sheet-plus {
  font-size: 18px !important;
  padding: 2px 9px !important
}

#sheetSelect {
  font-size: 12px;
  padding: 3px
}

#status {
  font-size: 10px
}

.viewer-actions {
  padding: 6px 0
}

.viewer-actions button {
  font-size: clamp(11px, min(3.2vw, 2.4vh), 14px);
  gap: 2px;
  padding: 2px;
  border-radius: 0
}

.viewer-actions svg {
  width: clamp(18px, 3.6vh, 24px);
  height: clamp(18px, 3.6vh, 24px)
}

.search-panel {
  padding: 5px clamp(8px, 1.6vw, 14px);
  gap: 4px
}

.search-panel input {
  height: 30px;
  font-size: 13px
}

.search-panel>span {
  font-size: 11px
}

.search-panel .icon-button {
  width: 30px;
  height: 30px;
  padding: 5px
}

.empty-state {
  inset: clamp(10px, 3vh, 20px) clamp(10px, 8%, 60px);
  padding: 12px
}

.empty-state>svg {
  width: clamp(44px, 9vh, 70px);
  height: clamp(52px, 10vh, 80px)
}

.empty-state h2 {
  font-size: clamp(15px, 2.8vh, 19px);
  margin: 8px 0 0
}

.empty-state p {
  font-size: 13px;
  margin: 6px 0
}

.empty-state .privacy-copy {
  font-size: 11px
}

.empty-state .primary {
  min-width: 130px
}

.dialog {
  padding: 16px 18px;
  border-radius: 12px;
  max-width: 440px
}

.dialog h2 {
  font-size: 17px;
  margin: 0 0 10px
}

.dialog p,
.dialog li {
  font-size: 13px;
  line-height: 1.45
}

.dialog label {
  margin: 9px 0;
  font-size: 12px
}

.dialog input,
.dialog select,
.dialog textarea {
  font-size: 13px
}

.dialog textarea {
  min-height: 64px
}

.dialog-actions {
  margin-top: 12px;
  gap: 6px
}

.choice-list {
  gap: 6px
}

.choice-list button {
  padding: 9px 11px
}

.toast {
  font-size: 13px;
  padding: 9px 14px;
  bottom: clamp(50px, 9vh, 70px)
}

.busy span {
  padding: 14px;
  font-size: 13px
}

/* keep 16px text in inputs on touch screens so iOS does not zoom when focusing */
@media(pointer:coarse) {

  input,
  textarea,
  .formula-bar input,
  .formula-bar #cellAddress,
  .search-panel input,
  .dialog input,
  .dialog select,
  .dialog textarea {
    font-size: 16px
  }
}

@media(max-height:500px) and (orientation:landscape) {
  .home-cards {
    max-width: 900px
  }

  .home-card {
    padding: 10px 10px
  }
}

@media(max-height:520px) {

  .text-tools select,
  .format-button,
  .color-control {
    height: 28px
  }

  .insert-symbol {
    width: 28px;
    height: 28px
  }

  .group-label {
    display: none
  }

  .formula-bar input {
    height: 26px
  }

  .viewer-actions {
    padding: 3px 0
  }

  .app-header {
    min-height: 36px
  }

  .dialog {
    padding: 12px 14px
  }

  .dialog label {
    margin: 6px 0
  }

  .toolbar {
    padding-top: 3px;
    padding-bottom: 3px
  }
}

@media(max-width:360px) {
  .app-header {
    gap: 3px;
    padding: 4px 5px
  }

  .app-header h1 {
    font-size: 13px
  }

  .download-excel {
    padding: 5px 8px;
    font-size: 11px
  }

  .sheet-navigation {
    gap: 2px
  }

  .sheet-navigation span {
    padding: 4px 5px;
    font-size: 10.5px
  }

  .sheet-navigation .icon-button {
    width: 24px
  }

  .insert-symbol {
    width: 28px;
    height: 28px
  }

  .dialog {
    padding: 12px
  }

  .formula-bar #cellAddress {
    width: 54px
  }
}

/* ===== Loading progress popup ===== */
.progress-shade {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9500;
  background: #10214155;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px
}

.progress-card {
  width: min(340px, 100%);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 14px 50px #12295644;
  padding: 16px 18px;
  text-align: center
}

.progress-card strong {
  display: block;
  font-size: 15px;
  margin-bottom: 12px
}

.progress-track {
  height: 10px;
  border-radius: 6px;
  background: #e4ecf9;
  overflow: hidden
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--blue);
  border-radius: 6px;
  transition: width .18s ease-out
}

.progress-pct {
  display: block;
  margin-top: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--blue)
}

.progress-note {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  min-height: 16px
}

/* ===== Worksheet objects: selection, resize handles, link chip, range picker ===== */
.drawing-layer {
  z-index: 7
}

.drawing {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none
}

.sel-box {
  position: absolute;
  border: 1.5px solid #2563eb;
  pointer-events: none;
  box-sizing: border-box;
  z-index: 8;
  --hs: 14px
}

.sel-handle {
  position: absolute;
  width: var(--hs);
  height: var(--hs);
  background: #fff;
  border: 2px solid #2563eb;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  box-sizing: border-box
}

.sel-handle.nw {
  left: calc(var(--hs)/-2);
  top: calc(var(--hs)/-2);
  cursor: nwse-resize
}

.sel-handle.n {
  left: calc(50% - var(--hs)/2);
  top: calc(var(--hs)/-2);
  cursor: ns-resize
}

.sel-handle.ne {
  right: calc(var(--hs)/-2);
  top: calc(var(--hs)/-2);
  cursor: nesw-resize
}

.sel-handle.e {
  right: calc(var(--hs)/-2);
  top: calc(50% - var(--hs)/2);
  cursor: ew-resize
}

.sel-handle.se {
  right: calc(var(--hs)/-2);
  bottom: calc(var(--hs)/-2);
  cursor: nwse-resize
}

.sel-handle.s {
  left: calc(50% - var(--hs)/2);
  bottom: calc(var(--hs)/-2);
  cursor: ns-resize
}

.sel-handle.sw {
  left: calc(var(--hs)/-2);
  bottom: calc(var(--hs)/-2);
  cursor: nesw-resize
}

.sel-handle.w {
  left: calc(var(--hs)/-2);
  top: calc(50% - var(--hs)/2);
  cursor: ew-resize
}

@media(pointer:coarse) {
  .sel-box {
    --hs: 22px
  }
}

.sel-bar {
  position: absolute;
  left: 0;
  display: flex;
  gap: 4px;
  pointer-events: auto;
  white-space: nowrap
}

.sel-bar button {
  padding: 3px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 6px #0a244d33
}

.link-chip {
  position: absolute;
  z-index: 9;
  padding: 3px 10px;
  font-size: 12px;
  border-radius: 14px;
  background: #14243a;
  color: #fff;
  border: 0;
  box-shadow: 0 2px 8px #0a244d44;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.link-chip:hover:not(:disabled) {
  background: #1f3a60
}

.pick-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 8px 30px #12295655;
  max-width: 94%;
  font-size: 13px
}

.dialog .range-row {
  display: flex;
  gap: 6px;
  align-items: stretch
}

.dialog .range-row input {
  flex: 1
}

.dialog .range-row button {
  white-space: nowrap
}

/* ===== Home page only: medium-size text and controls ===== */
body[data-mode="home"] .home-header {
  height: 50px;
  min-height: 50px;
  padding: 0 16px;
}

body[data-mode="home"] .home-header h1 {
  font-size: 1.2rem;
  font-weight: 400;
  font-style: normal;
  letter-spacing: normal;
  font-family: "Roboto", sans-serif;
  color: #000;
}

body[data-mode="home"] .home-header .icon-button {
  width: 34px;
  height: 34px;
}

body[data-mode="home"] .home-header svg {
  width: 24px;
  height: 24px;
}

body[data-mode="home"] .home-main {
  padding: clamp(12px, 3vh, 26px) clamp(14px, 3.4vw, 26px)
}

body[data-mode="home"] .home-cards {
  gap: clamp(12px, 2.8vh, 22px);
  max-width: 820px
}

body[data-mode="home"] .home-card {
  gap: clamp(12px, 2.8vw, 24px);
  padding: clamp(12px, 2.4vh, 20px) clamp(14px, 3.4vw, 30px);
  border-radius: clamp(14px, 2.6vw, 20px)
}

body[data-mode="home"] .card-icon {
  width: clamp(46px, min(13vw, 10.5vh), 80px);
  height: clamp(46px, min(13vw, 10.5vh), 80px);
  border-radius: clamp(12px, 2.4vw, 18px)
}

body[data-mode="home"] .card-copy {
  gap: 4px
}

body[data-mode="home"] .card-copy strong {
  font-size: clamp(16px, min(4.6vw, 3.4vh), 25px)
}

body[data-mode="home"] .card-copy>span {
  font-size: clamp(12.5px, min(3.6vw, 2.6vh), 17px)
}

body[data-mode="home"] .chevron svg {
  width: 20px;
  height: 20px
}

@media(max-height:500px) and (orientation:landscape) {
  body[data-mode="home"] .home-cards {
    max-width: 940px
  }
}

/* Keep inserted objects above cells but below the worksheet scrollbars and headers. */
#grid {
  position: relative;
  z-index: 1
}

#grid .jexcel_content {
  position: relative;
  z-index: 2
}

.drawing-layer {
  z-index: 3;
  pointer-events: none;
  right: 16px;
  bottom: 16px
}

.drawing-layer img,
.drawing-layer .sel-box,
.drawing-layer .link-chip {
  pointer-events: auto
}

.app-header .download-excel {
  padding: 10px 16px
}

@media(max-width:720px) {
  .app-header {
    gap: 8px;
    padding: 8px 10px
  }

  .app-header h1 {
    font-size: 18px
  }

  .app-header .download-excel {
    padding: 8px 10px;
    font-size: 12px
  }
}

/* Focused touch-screen fixes: discoverable tool names, worksheet tabs, and resize handles. */
@media (hover:none) and (max-width:760px) {

  #toolbar button[title],
  #toolbar label[title] {
    position: relative;
  }

  #toolbar button[title]:active::after,
  #toolbar button[title]:focus-visible::after,
  #toolbar label[title]:active::after,
  #toolbar label[title]:focus-visible::after {
    content: attr(title);
    position: absolute;
    left: 50%;
    top: calc(100% + 5px);
    transform: translateX(-50%);
    z-index: 12000;
    background: #17243a;
    color: #fff;
    border-radius: 5px;
    padding: 5px 7px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 8px #0003;
  }

  .sheet-bar #sheetTabs {
    display: flex !important;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: thin;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }

  #sheetSelect {
    display: none !important;
  }

  .sheet-bar #sheetTabs button {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 5px 10px;
  }

  #status {
    flex: 0 1 25%;
    max-width: 25%;
  }

  .jexcel>thead>tr>td {
    touch-action: pan-x;
  }

  .jexcel>thead>tr>td:not(:first-child) {
    position: relative;
  }

  .jexcel>thead>tr>td:not(:first-child)::after {
    content: "";
    position: absolute;
    right: -5px;
    top: 0;
    width: 12px;
    height: 100%;
    z-index: 8;
    touch-action: none;
  }

  .jexcel>thead>tr>td:first-child {
    touch-action: pan-x pan-y;
  }
}

/* Landscape phones are wider than 760px, so give them the same touch tooltips (feature names) that portrait has. */
@media (hover:none) and (orientation:landscape) and (min-width:761px) and (max-height:500px) {

  #toolbar button[title],
  #toolbar label[title] {
    position: relative;
  }

  #toolbar button[title]:active::after,
  #toolbar button[title]:focus-visible::after,
  #toolbar label[title]:active::after,
  #toolbar label[title]:focus-visible::after {
    content: attr(title);
    position: absolute;
    left: 50%;
    top: calc(100% + 5px);
    transform: translateX(-50%);
    z-index: 12000;
    background: #17243a;
    color: #fff;
    border-radius: 5px;
    padding: 5px 7px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 8px #0003;
  }
}

@media(min-width:761px) {
  .text-tools {
    border-right: 1px solid var(--line);
    padding-right: 12px;
    margin-right: 4px;
  }

  .insert-tools {
    padding-left: 8px;
  }
}

/* Keep worksheet objects within the visible sheet viewport and below its fixed headers. */
.drawing-layer {
  z-index: 1;
  clip-path: inset(0);
}

.jexcel_container,
.jexcel_content {
  position: relative;
  z-index: 2;
}

.jexcel>thead {
  position: relative;
  z-index: 4;
}

/* Scoped interaction fixes: retain the established controls and worksheet design. */
.jexcel td.editor {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  z-index: 3
}

.jexcel td.editor input,
.jexcel td.editor textarea {
  font-family: inherit !important;
  font-size: inherit !important;
  font-weight: inherit !important;
  font-style: inherit !important;
  color: inherit !important;
  background: inherit !important;
  line-height: inherit !important;
  border: 0;
  outline: 0;
  padding: 4px 8px;
  box-sizing: border-box
}

.jexcel>thead>tr>td,
.jexcel>tbody>tr>td.jexcel_row {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none
}

.jexcel>thead>tr>td:not(:first-child)::after {
  pointer-events: none
}

.drawing-layer {
  z-index: 7;
  right: 0;
  bottom: 0
}

.drawing,
.sel-box {
  touch-action: none
}

.sel-box {
  pointer-events: auto;
  cursor: move
}

.sel-bar {
  z-index: 12
}

.sel-bar button {
  min-height: 32px;
  padding: 5px 12px;
  font-weight: 600;
  color: #fff;
  border: 1px solid transparent;
  box-shadow: 0 2px 6px #10214140
}

.sel-bar .object-edit,
.sel-bar .object-edit:hover {
  background: #1d5fe8;
  color: #fff
}

.sel-bar .object-delete,
.sel-bar .object-delete:hover {
  background: #b42332;
  color: #fff
}

.sheet-bar #sheetTabs {
  display: flex !important;
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch
}

.sheet-bar #sheetTabs button {
  flex: 0 0 auto;
  min-height: 30px
}

#sheetSelect {
  display: none !important
}

.sheet-bar #status {
  flex: 0 1 22%;
  max-width: 22%
}

.formula-bar #formulaInput,
.search-panel input,
.dialog .range-row input {
  min-width: 0
}

.dialog {
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  max-height: calc(var(--height, 100dvh) - 24px)
}

.dialog-actions {
  position: sticky;
  bottom: -1px;
  background: #fff;
  padding-top: 6px;
  z-index: 1;
  flex-wrap: wrap
}

.dialog .range-row {
  flex-wrap: wrap
}

.dialog .range-row input {
  flex: 1 1 160px
}

@media(min-width:761px) and (min-height:501px) {
  .toolbar {
    flex-direction: column;
    gap: 8px
  }

  .text-tools,
  .insert-tools {
    flex: none;
    width: 100%;
    border-right: 0;
    margin-right: 0;
    padding-right: 0;
    padding-left: 0
  }

  .insert-tools {
    border-top: 1px solid var(--line);
    padding-top: 8px
  }
}

@media(max-height:500px) and (orientation:landscape) {
  .toolbar {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px
  }

  .mobile-tools {
    display: flex;
    flex-direction: column;
    flex: none
  }

  .tool-group {
    min-width: 0;
    border: 0;
    padding: 0;
    margin: 0
  }

  .text-tools {
    display: block;
    flex: 1
  }

  .insert-tools {
    display: none;
    flex: 1
  }

  .toolbar.show-insert .insert-tools {
    display: block
  }

  .toolbar.show-insert .text-tools {
    display: none
  }

  .text-tools .tool-controls {
    grid-template-columns: minmax(60px, 1.3fr) 62px repeat(10, minmax(24px, 1fr));
    gap: 2px
  }

  .insert-tools .tool-controls {
    grid-template-columns: repeat(10, minmax(26px, 1fr))
  }
}

@media(max-width:400px) {
  .app-header {
    gap: 4px;
    padding: 5px 6px
  }

  .app-header h1 {
    font-size: 14px
  }

  .app-header .download-excel {
    font-size: 11px;
    padding: 7px 8px
  }

  .sheet-bar #status {
    display: none
  }
}


/* ===== Round 2 fixes ===== */
/* Follow the visible area above the on-screen keyboard (search box, rename and link popups stay visible). */
body {
  position: fixed;
  top: var(--vv-top, 0px);
  left: 0;
  right: 0
}

.modal-shade {
  top: var(--vv-top, 0px);
  bottom: auto;
  height: var(--height, 100%)
}

body[data-mode=create] #filename,
body[data-mode=edit] #filename {
  cursor: pointer
}

.dialog textarea {
  word-break: break-all
}

/* Worksheet tabs: + sits right next to the last tab; tabs can be dragged sideways to reorder. */
body[data-mode=create] .sheet-bar #sheetTabs,
body[data-mode=edit] .sheet-bar #sheetTabs {
  flex: 0 1 auto
}

body[data-mode=create] .sheet-bar #status,
body[data-mode=edit] .sheet-bar #status {
  margin-left: auto
}

.sheet-bar #sheetTabs button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none
}

.sheet-bar #sheetTabs button.dragging {
  position: relative;
  z-index: 5;
  background: #cfe0ff;
  box-shadow: 0 2px 8px #0a244d44;
  touch-action: none
}

.sheet-bar #sheetTabs button.drop-before {
  box-shadow: inset 3px 0 0 #2563eb
}

.sheet-bar #sheetTabs button.drop-after {
  box-shadow: inset -3px 0 0 #2563eb
}

/* Landscape phones: Text and Insert tabs sit side by side. */
@media(max-height:500px) and (orientation:landscape) {
  .mobile-tools {
    flex-direction: row;
    gap: 4px;
    align-items: center
  }

  .mobile-tools button {
    padding: 4px 12px
  }
}

/* Touch screens: no long-press / row-selection context menu under the sheet. */
@media(pointer:coarse) {
  .jcontextmenu {
    display: none !important
  }
}

/* Touch color picker */
/* Color picker (same as the GPS camera project): colour area, hue bar, R/G/B boxes, Cancel / Set. */
.cp-shade {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30000;
  background: transparent
}

.color-picker {
  position: fixed;
  display: block;
  box-sizing: border-box;
  width: min(350px, calc(100vw - 20px));
  max-height: calc(100vh - 20px);
  overflow: auto;
  background: #fff;
  color: #111;
  border: 1px solid #cfd5df;
  border-radius: 10px;
  box-shadow: 0 14px 40px #0003;
  font-family: inherit
}

.cp-title {
  padding: 10px 12px;
  font-weight: 600;
  border-bottom: 1px solid #e5e7eb
}

.cp-area {
  position: relative;
  height: 180px;
  margin: 10px;
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  background: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, rgba(255, 255, 255, 0))
}

.cp-area:before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: var(--cp-hue, #f00);
  mix-blend-mode: multiply
}

.cp-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #0008;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-sizing: border-box
}

.cp-hue {
  position: relative;
  height: 18px;
  margin: 0 10px 10px;
  border-radius: 5px;
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)
}

.cp-hue-handle {
  position: absolute;
  top: 0;
  width: 5px;
  height: 18px;
  border: 1px solid #fff;
  box-shadow: 0 0 0 1px #0008;
  transform: translateX(-50%);
  pointer-events: none;
  box-sizing: border-box
}

.cp-bottom {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid #e5e7eb
}

.cp-preview {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #cfd5df;
  box-sizing: border-box
}

.cp-rgb {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px
}

.cp-rgb label {
  font-size: 10px;
  color: #5b6475;
  text-align: center;
  margin: 0
}

.cp-rgb input {
  width: 100%;
  height: 32px;
  border: 1px solid #cfd5df;
  border-radius: 5px;
  text-align: center;
  font: inherit;
  font-size: 16px;
  color: #111;
  background: #fff;
  box-sizing: border-box;
  padding: 0
}

.cp-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 10px 10px
}

.cp-actions button {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid #cfd5df;
  background: #fff;
  color: #111;
  font: inherit;
  cursor: pointer
}

.cp-actions .cp-set {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff
}

@media(max-width:560px) {
  .cp-area {
    height: min(180px, 42vw)
  }
}

@media(max-height:460px) {
  .cp-area {
    height: min(120px, 28vh)
  }
}

@media(pointer:coarse) {
  .jexcel_corner {
    touch-action: none
  }

  .jexcel_corner::after {
    content: '';
    position: absolute;
    left: -16px;
    top: -16px;
    right: -16px;
    bottom: -16px
  }
}

/* Laptops/desktops: Text and Insert on one line, separated by a vertical line. */
@media(min-width:1000px) and (min-height:501px) {
  .toolbar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 0 12px
  }

  .text-tools,
  .insert-tools {
    width: auto;
    min-width: 0
  }

  .text-tools {
    flex: 1.15 1 0;
    border-right: 1px solid var(--line);
    padding-right: 12px;
    margin-right: 0
  }

  .insert-tools {
    flex: 1 1 0;
    border-top: 0;
    padding-top: 0;
    padding-left: 4px
  }
}

/* Resize arrow (line with arrows) shown only while a column is being dragged. */
.jexcel>thead>tr>td.col-resizing {
  position: sticky !important
}

.jexcel>thead>tr>td.col-resizing::before {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  width: 18px;
  height: 16px;
  margin-top: -8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='16' viewBox='0 0 18 16'%3E%3Cpath d='M9 1v14M1 8h16M1 8l3-3M1 8l3 3M17 8l-3-3M17 8l-3 3' fill='none' stroke='%23566f9c' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
  pointer-events: none;
  z-index: 9
}

/* Laptops/mouse: resize arrow cursor is set on column header edges by app.js. */

/* Phone copy / cut / paste menu (long-press a cell) */
.touch-menu {
  position: fixed;
  z-index: 2000;
  display: flex;
  background: #fff;
  border: 1px solid #c8d0dc;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  overflow: hidden
}

.touch-menu button {
  border: 0;
  background: none;
  padding: 11px 18px;
  font: 600 14px system-ui, sans-serif;
  color: #1f2937;
  cursor: pointer
}

.touch-menu button+button {
  border-left: 1px solid #e3e7ee
}

/* ===== Round 3 fixes ===== */
/* Popups: title and Cancel/Apply stay fixed; only the middle part scrolls. */
.dialog {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(var(--height, 100dvh) - 24px)
}

.dialog>h2 {
  flex: 0 0 auto
}

.dialog>#modalBody {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch
}

.dialog>.field-error {
  flex: 0 0 auto
}

.dialog>.dialog-actions {
  position: static;
  flex: 0 0 auto;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  background: #fff
}

/* Color picker: never cut off; two-column layout on short (landscape phone) screens. */
.color-picker {
  max-height: calc(var(--height, 100vh) - 20px)
}

@media(max-height:520px) {
  .color-picker {
    width: min(520px, calc(100vw - 20px));
    display: grid;
    grid-template-columns: minmax(0, 1fr) 190px;
    overflow: auto
  }

  .color-picker .cp-title {
    grid-column: 1/-1;
    padding: 6px 12px
  }

  .color-picker .cp-area {
    grid-column: 1;
    grid-row: 2;
    height: clamp(70px, calc(var(--height, 100vh) - 150px), 150px);
    margin: 8px 10px 6px
  }

  .color-picker .cp-hue {
    grid-column: 1;
    grid-row: 3;
    margin: 0 10px 8px
  }

  .color-picker .cp-bottom {
    grid-column: 2;
    grid-row: 2;
    border-top: 0;
    padding: 8px 10px 0 0;
    align-self: start
  }

  .color-picker .cp-actions {
    grid-column: 2;
    grid-row: 3;
    padding: 0 10px 8px 0;
    align-self: end
  }
}

/* Resize handles stay grabbable when the object touches the edge of the visible sheet. */
.sel-box.in-r .sel-handle.ne,
.sel-box.in-r .sel-handle.e,
.sel-box.in-r .sel-handle.se {
  right: 2px
}

.sel-box.in-l .sel-handle.nw,
.sel-box.in-l .sel-handle.w,
.sel-box.in-l .sel-handle.sw {
  left: 2px
}

.sel-box.in-b .sel-handle.sw,
.sel-box.in-b .sel-handle.s,
.sel-box.in-b .sel-handle.se {
  bottom: 2px
}

.sel-box.in-t .sel-handle.nw,
.sel-box.in-t .sel-handle.n,
.sel-box.in-t .sel-handle.ne {
  top: 2px
}


/* ===== Round 3 fixes ===== */
/* While the on-screen keyboard is open, give the grid the room: hide header and sheet bar (and the toolbar in landscape). */
html.kbd-open .app-header,
html.kbd-open .sheet-bar {
  display: none !important
}

html.kbd-land .toolbar {
  display: none !important
}

html.kbd-open .formula-bar {
  flex-shrink: 0
}

html.kbd-open .work-area {
  min-height: 0;
  flex: 1 1 auto
}


/* ===== Round 4 fixes ===== */
/* Landscape phone, keyboard open, popup with a text box (rename, link, function, chart ...): compact popup that scrolls and keeps the focused box visible. */
html.kbd-modal .modal-shade {
  align-items: flex-start !important;
  padding: 2px 8px !important
}

html.kbd-modal .dialog {
  padding: 5px 10px !important;
  border-radius: 8px !important;
  max-height: calc(var(--height, 100dvh) - 4px) !important;
  max-width: min(640px, 100%) !important
}


/* ===== Round 5 fixes ===== */
/* Phone landscape with keyboard: the popup keeps its normal look and the whole popup (title, boxes, buttons) scrolls inside the space above the keyboard. */
html.kbd-modal .modal-shade {
  align-items: flex-start !important;
  padding: 4px 8px !important;
  overflow: hidden !important
}

html.kbd-modal .dialog {
  display: block !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  max-height: calc(var(--height, 100dvh) - 8px) !important
}

html.kbd-modal .dialog>#modalBody {
  overflow: visible !important;
  max-height: none !important
}

html.kbd-modal .dialog>.dialog-actions {
  position: static !important
}

/* ===== Round 6 fixes ===== */
/* Font size box: the number is never hidden behind the dropdown arrow. */
.text-tools #fontSize {
  min-width: 0;
  padding-left: 6px;
  padding-right: 1px;
  text-overflow: clip;
  text-align: left
}

/* Colour fields are plain read-only boxes (the browser's own colour window is never used). */
.color-control input.color-field {
  font-size: 16px;
  caret-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  color: transparent;
  background: transparent;
  border: 0;
  -webkit-appearance: none;
  appearance: none
}

.dialog input.color-field {
  cursor: pointer;
  min-height: 38px;
  -webkit-user-select: none;
  user-select: none;
  caret-color: transparent;
  border: 1px solid #cfd5df;
  border-radius: 6px
}

/* Colour picker: wider R/G/B boxes on landscape phones, and a one-row layout while typing so nothing is cut. */
@media(max-height:520px) {
  .color-picker {
    width: min(540px, calc(100vw - 20px));
    grid-template-columns: minmax(0, 1fr) 220px
  }

  .color-picker .cp-bottom {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 10px 0 0
  }

  .color-picker .cp-preview {
    width: 34px;
    height: 34px
  }

  .color-picker .cp-rgb {
    gap: 5px
  }

  .color-picker .cp-rgb input {
    min-width: 0;
    padding: 0 2px;
    font-size: 16px
  }
}

.color-picker.cp-compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  width: min(560px, calc(100vw - 20px));
  max-height: none;
  overflow: visible;
  padding: 8px 10px
}

.color-picker.cp-compact .cp-title,
.color-picker.cp-compact .cp-area,
.color-picker.cp-compact .cp-hue {
  display: none
}

.color-picker.cp-compact .cp-bottom {
  display: flex;
  flex: 1 1 240px;
  align-items: center;
  gap: 8px;
  border: 0;
  padding: 0;
  grid-column: auto;
  grid-row: auto
}

.color-picker.cp-compact .cp-preview {
  flex: none;
  width: 34px;
  height: 34px
}

.color-picker.cp-compact .cp-rgb {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(52px, 1fr));
  gap: 6px
}

.color-picker.cp-compact .cp-rgb input {
  height: 36px;
  min-width: 52px;
  padding: 0 4px
}

.color-picker.cp-compact .cp-actions {
  flex: none;
  padding: 0;
  grid-column: auto;
  grid-row: auto
}

.dialog .shape-picker {
  max-height: min(280px, 42vh);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: 6px 0 8px;
  padding: 2px 8px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff
}

.dialog .shape-head {
  font-size: 12px;
  font-weight: 700;
  color: #18213a;
  margin: 8px 0 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--line)
}

.dialog .shape-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 3px
}

.dialog .shape-grid button {
  height: 32px;
  min-height: 0;
  padding: 0;
  margin: 0;
  background: #fff;
  border: 1px solid transparent;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer
}

.dialog .shape-grid button[aria-pressed=true] {
  border-color: #2563eb;
  background: #eaf1ff
}

/* iPhone safe areas for popups, busy/progress screens and the toast (iOS only; Android and desktop are unchanged) */
@supports (-webkit-touch-callout:none) {

  .modal-shade,
  .progress-shade {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right))
  }

  .busy {
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right))
  }

  .dialog {
    max-height: calc(var(--height, 100dvh) - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom))
  }

  html.kbd-modal .modal-shade {
    padding-top: max(2px, env(safe-area-inset-top)) !important;
    padding-left: max(8px, env(safe-area-inset-left)) !important;
    padding-right: max(8px, env(safe-area-inset-right)) !important
  }

  .toast {
    bottom: calc(70px + env(safe-area-inset-bottom))
  }

  .color-picker {
    width: min(350px, calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: calc(100vh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom))
  }
}

/* Phone landscape: the whole shapes popup scrolls as one, so the Color field and buttons are always reachable */
@media (max-height:500px) and (orientation:landscape) and (pointer:coarse) {
  .dialog .shape-picker {
    max-height: none;
    overflow: visible
  }
}
/* ===== Phones: home title centered in the middle (back button left, Help right). ===== */
@media (max-width:760px), (max-height:500px) and (orientation:landscape) {
  body[data-mode="home"] .home-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
  }

  body[data-mode="home"] .home-header .backBtn,
  body[data-mode="home"] .home-header > .icon-button:first-child {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
  }

  body[data-mode="home"] .home-header h1 {
    font-size: 1.2rem;
    font-weight: 400;
    font-style: normal;
    letter-spacing: normal;
    flex: 0 1 auto;
    margin: 0 auto;
    min-width: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body[data-mode="home"] .home-header .icon-button[data-action="help"] {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
  }

  body[data-mode="home"] .home-header .icon-button {
    flex: 0 0 auto
  }
}

/* ===== Phone landscape (Android + iPhone): home cards fit in one tidy row under a compact header. ===== */
@media (max-height:500px) and (orientation:landscape) {
  body[data-mode="home"] .home-header {
    height: 46px;
    padding: 0 12px
  }

  body[data-mode="home"] .home-header h1 {
    font-size: 1.2rem;
    font-weight: 400;
    font-style: normal;
  }

  body[data-mode="home"] .home-header .icon-button {
    width: 36px;
    height: 36px
  }

  body[data-mode="home"] .home-main {
    display: block;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 14px
  }

  body[data-mode="home"] .home-cards {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 960px;
    margin: 0 auto
  }

  body[data-mode="home"] .home-card {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 12px 10px;
    min-height: 0;
    text-align: center;
    border-radius: 14px
  }

  body[data-mode="home"] .card-icon {
    width: 44px;
    height: 44px;
    border-radius: 11px
  }

  body[data-mode="home"] .card-copy {
    align-items: center;
    text-align: center;
    gap: 3px
  }

  body[data-mode="home"] .card-copy strong {
    font-size: 15px
  }

  body[data-mode="home"] .card-copy>span {
    font-size: 12px;
    line-height: 1.25
  }

  body[data-mode="home"] .chevron {
    display: none
  }
}

/* ===== Phone landscape: Create / Edit spreadsheet — slimmer upper part (header, toolbar, formula bar). ===== */
@media (max-height:500px) and (orientation:landscape) and (pointer:coarse) {
  body[data-mode="create"] .app-header,
  body[data-mode="edit"] .app-header {
    min-height: 34px;
    height: 34px;
    padding: 2px 8px;
    gap: 6px
  }

  body[data-mode="create"] .app-header h1,
  body[data-mode="edit"] .app-header h1 {
    font-size: 14px
  }

  body[data-mode="create"] .app-header .icon-button,
  body[data-mode="edit"] .app-header .icon-button {
    width: 28px;
    height: 28px;
    padding: 4px
  }

  body[data-mode="create"] .app-header .download-excel,
  body[data-mode="edit"] .app-header .download-excel {
    padding: 4px 12px;
    font-size: 12px
  }

  body[data-mode="create"] .toolbar,
  body[data-mode="edit"] .toolbar {
    padding: 2px 8px;
    gap: 4px
  }

  body[data-mode="create"] .mobile-tools button,
  body[data-mode="edit"] .mobile-tools button {
    padding: 2px 10px;
    font-size: 11px;
    min-height: 0
  }

  body[data-mode="create"] .text-tools select,
  body[data-mode="edit"] .text-tools select,
  body[data-mode="create"] .format-button,
  body[data-mode="edit"] .format-button,
  body[data-mode="create"] .color-control,
  body[data-mode="edit"] .color-control {
    height: 24px;
    padding-top: 1px;
    padding-bottom: 1px
  }

  body[data-mode="create"] .insert-symbol,
  body[data-mode="edit"] .insert-symbol {
    width: 24px;
    height: 24px;
    border-radius: 6px
  }

  body[data-mode="create"] .insert-symbol svg,
  body[data-mode="edit"] .insert-symbol svg {
    width: 15px;
    height: 15px
  }

  body[data-mode="create"] .insert-button,
  body[data-mode="edit"] .insert-button {
    font-size: 8px;
    gap: 0
  }

  body[data-mode="create"] .formula-bar,
  body[data-mode="edit"] .formula-bar {
    padding: 2px 8px;
    gap: 5px;
    min-height: 0
  }

  body[data-mode="create"] .formula-bar input,
  body[data-mode="edit"] .formula-bar input {
    height: 24px;
    padding-top: 1px;
    padding-bottom: 1px
  }
}
