:root {
  color-scheme: light;
  --ink: #14202a;
  --muted: #687682;
  --paper: #ffffff;
  --line: #a6a6a6;
  --header: #1f4e79;
  --excel-soft: #ddebf7;
  --blue: #00b0f0;
  --blue-dark: #008fc6;
  --yellow: #fff2cc;
  --yellow-strong: #ffd966;
  --panel: #ffffff;
  --shadow: 0 18px 45px rgba(25, 51, 74, 0.14);
  --radius: 8px;
  font-family:
    "Gill Sans MT", "Gill Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #fff;
}

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

button {
  cursor: pointer;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.82rem 0.88rem;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue-dark);
  box-shadow: 0 0 0 3px rgba(14, 173, 215, 0.2);
}

textarea {
  min-height: 128px;
  resize: vertical;
}

.app {
  min-height: 100vh;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1rem;
  background:
    linear-gradient(180deg, rgba(36, 87, 127, 0.13), transparent 40%),
    var(--paper);
}

.login-view.is-hidden,
.sheet-view.is-hidden {
  display: none;
}

.login-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h1,
.sheet-title h1,
.header-card h2,
.editor-heading h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.12;
}

.login-card h1 {
  font-size: 2rem;
}

.muted {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.form-stack {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.form-stack label,
.header-grid label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border-radius: 7px;
  font-weight: 850;
  letter-spacing: 0;
}

.primary-button {
  border: 1px solid var(--header);
  padding: 0.72rem 1rem;
  color: #fff;
  background: var(--header);
}

.primary-button:hover {
  background: #183f5f;
}

.ghost-button {
  border: 1px solid var(--line);
  padding: 0.72rem 1rem;
  color: var(--ink);
  background: #fff;
}

.compact {
  min-height: 36px;
  padding: 0.5rem 0.75rem;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  border: 0;
  place-items: center;
  color: #fff;
  background: var(--header);
}

.icon-button.dark {
  color: var(--ink);
  background: #eef5f8;
}

.sheet-view {
  min-height: 100vh;
  padding: 0 0 6rem;
  background: #fff;
}

.sheet-title {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  min-height: 64px;
  gap: 0;
  padding: calc(0.6rem + env(safe-area-inset-top)) 5rem 0.6rem;
  border: 0;
  color: #fff;
  text-align: center;
  background: var(--header);
}

.sheet-title h1 {
  color: #fff;
  font-size: clamp(1.2rem, 4.6vw, 2.4rem);
  font-weight: 900;
  text-transform: uppercase;
}

.sheet-title .eyebrow {
  display: none;
}

.sheet-title .icon-button,
.sheet-title .ghost-button {
  position: absolute;
  top: calc(0.75rem + env(safe-area-inset-top));
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  color: #fff;
  background: rgba(0, 0, 0, 0.08);
}

.sheet-title .icon-button {
  left: 0.75rem;
}

.sheet-title .ghost-button {
  right: 0.75rem;
  width: auto;
}

.sheet-note {
  display: flex;
  align-items: flex-start;
  min-height: 108px;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 0.72rem 0.85rem;
  color: #000;
  font-size: clamp(1.2rem, 2.1vw, 2rem);
  font-style: italic;
  line-height: 1.1;
  background: var(--excel-soft);
}

.header-card,
.status-strip,
.entry-focus {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}

.header-card {
  min-height: 192px;
  padding: 0.7rem 0.85rem 0.95rem;
  background: var(--excel-soft);
}

.header-card.is-locked {
  background: var(--excel-soft);
}

.header-card.is-locked .header-grid {
  grid-template-columns: 1fr;
  gap: 0;
}

.header-card.is-locked .header-grid label {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

.header-card.is-locked input {
  min-height: 0;
  border: 0;
  padding: 0;
  color: var(--ink);
  font-weight: 850;
  background: transparent;
  box-shadow: none;
}

.header-card-title {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.8rem;
  min-height: 0;
  margin-bottom: 0;
}

.header-card-title > div {
  display: none;
}

.header-card h2 {
  font-size: 1.05rem;
}

.header-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  max-width: 760px;
  margin-top: 1rem;
}

.header-grid label {
  grid-template-columns: 220px minmax(0, 1fr);
  align-items: center;
  min-height: 54px;
  color: #000;
  font-size: clamp(1.25rem, 2.1vw, 2rem);
  font-style: italic;
  font-weight: 900;
}

.header-grid input {
  border: 0;
  border-radius: 0;
  padding: 0.2rem 0;
  color: #000;
  font-size: clamp(1rem, 3.2vw, 1.55rem);
  font-style: normal;
  font-weight: 800;
  background: transparent;
  box-shadow: none;
}

.header-grid input::placeholder {
  color: rgba(0, 0, 0, 0.35);
}

.status-strip {
  display: none;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 0.85rem;
}

.status-strip div,
.entry-focus .focus-row {
  display: grid;
  gap: 0.2rem;
}

.status-strip strong {
  font-size: 1rem;
}

.status-strip span,
.entry-focus span {
  color: var(--muted);
  font-size: 0.86rem;
}

.entry-focus {
  display: none;
  padding: 0.85rem;
}

.focus-row {
  display: flex;
  justify-content: space-between;
}

.sheet-wrap {
  margin: 0;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  scroll-snap-type: x proximity;
}

.sheet-grid {
  min-width: 1180px;
}

.sheet-row {
  display: grid;
  grid-template-columns:
    82px 170px 180px 150px 220px 200px 110px 200px 185px 155px 160px
    220px;
}

.sheet-header {
  position: sticky;
  top: 0;
  z-index: 2;
}

.sheet-header .sheet-cell {
  min-height: 92px;
  border-top: 0;
  color: #fff;
  font-size: clamp(1rem, 1.8vw, 1.45rem);
  font-weight: 900;
  line-height: 1.12;
  text-align: center;
  word-break: normal;
  overflow-wrap: normal;
  background: var(--blue);
}

.sheet-spacer .sheet-cell {
  min-height: 64px;
  background: #fff;
}

.sheet-cell {
  display: flex;
  align-items: center;
  min-height: 54px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.65rem;
  overflow: hidden;
  color: var(--ink);
  text-align: left;
  word-break: break-word;
  background: #fff;
}

button.sheet-cell {
  width: 100%;
}

.sheet-cell:last-child {
  border-right: 0;
}

.sheet-row:not(.sheet-header) .sheet-cell {
  background: #fffdf0;
}

.sheet-row:not(.sheet-header) .sheet-cell.is-filled {
  background: #fff;
}

.sheet-row:not(.sheet-header) .sheet-cell.is-active {
  outline: 3px solid rgba(14, 173, 215, 0.28);
  outline-offset: -3px;
  background: #e9f8fc;
}

.sheet-row.is-current .sheet-cell:first-child {
  color: #fff;
  font-weight: 900;
  background: var(--header);
}

.cell-empty {
  color: #8b7a3c;
  font-size: 0.8rem;
}

.fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 12;
  display: grid;
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  place-items: center;
  color: #fff;
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  background: var(--header);
  box-shadow: 0 16px 34px rgba(36, 87, 127, 0.36);
}

.floating-tools {
  position: fixed;
  left: 0.85rem;
  bottom: 0.85rem;
  z-index: 18;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.4rem;
  max-width: min(620px, calc(100vw - 6.8rem));
}

.tool-button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 5px;
  padding: 0.35rem 0.62rem;
  color: #fff;
  font-weight: 850;
  background: rgba(31, 78, 121, 0.96);
}

.admin-tool {
  display: none;
}

.admin-tool.is-visible {
  display: inline-flex;
  align-items: center;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid rgba(31, 78, 121, 0.2);
  border-radius: 5px;
  padding: 0.35rem 0.55rem;
  color: #1f4e79;
  font-size: 0.76rem;
  font-weight: 850;
  background: rgba(255, 255, 255, 0.94);
}

.sync-badge[data-status="offline"],
.sync-badge[data-status="pending"],
.sync-badge[data-status="error"] {
  color: #6c4b00;
  background: #fff2cc;
}

.sheet-wrap {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  background: #fff;
}

.excel-sheet {
  display: grid;
  width: max-content;
  min-height: 100vh;
  background: #fff;
  font-family: "Gill Sans MT", "Gill Sans", Calibri, Arial, sans-serif;
}

.excel-row {
  display: grid;
  grid-template-columns:
    99px 233px 173px 212px 281px 192px 110px 198px 158px 109px 162px
    309px;
}

.excel-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  border: 0;
  padding: 0 4px;
  color: #000;
  text-align: left;
  white-space: normal;
  background: #fff;
}

button.excel-cell {
  width: 100%;
  cursor: pointer;
}

.merged {
  grid-column: 1 / -1;
  justify-content: center;
}

.row-1 .excel-cell,
.title-cell {
  height: 32px;
  color: #fff;
  font-size: 21.33px;
  font-weight: 900;
  text-align: center;
  background: #1f4e79;
}

.row-2 .excel-cell,
.instruction-cell {
  align-items: flex-start;
  justify-content: flex-start;
  height: 22px;
  color: #000;
  font-size: 21.33px;
  font-style: italic;
  line-height: 1.05;
  text-align: left;
  background: #ddebf7;
}

.row-3 .excel-cell,
.row-4 .excel-cell,
.row-5 .excel-cell,
.row-6 .excel-cell {
  height: 32px;
  background: #ddebf7;
}

.row-7 .excel-cell {
  height: 32px;
  border-right: 1px solid #d9d9d9;
  background: #fff;
}

.meta-label {
  position: relative;
  z-index: 1;
  overflow: visible;
  white-space: nowrap;
  font-size: 21.33px;
  font-style: italic;
  font-weight: 900;
}

.meta-value {
  justify-content: flex-start;
  font-size: 21.33px;
  font-style: italic;
  background: #ddebf7;
}

.row-6 .meta-value {
  padding-left: 46px;
}

.row-8 .excel-cell,
.column-head {
  justify-content: center;
  height: 64px;
  border: 1px solid #a6a6a6;
  color: #fff;
  font-size: 21.33px;
  font-weight: 900;
  line-height: 1.04;
  text-align: center;
  word-break: normal;
  overflow-wrap: normal;
  background: #00b0f0;
}

.data-row .excel-cell,
.data-cell {
  align-items: center;
  height: 58px;
  border: 1px solid #a6a6a6;
  font-size: 24px;
  line-height: 1;
  background: #fff2cc;
}

.data-cell.is-active {
  box-shadow: inset 0 0 0 3px #00b0f0;
}

.archives {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: none;
}

.archives.is-open {
  display: block;
}

.archives-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: min(72vh, 620px);
  overflow: auto;
  border-radius: 18px 18px 0 0;
  padding: 0.65rem 1rem calc(1rem + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -22px 50px rgba(10, 24, 36, 0.22);
}

.archives-list {
  display: grid;
  gap: 0.55rem;
}

.archive-item,
.archive-empty {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.82rem;
  text-align: left;
  background: #fff;
}

.archive-item strong,
.archive-item span {
  display: block;
}

.archive-item span,
.archive-empty {
  color: var(--muted);
}

.admin {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
}

.admin.is-open {
  display: block;
}

.admin-panel {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
  background: #fff;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.admin-card,
.admin-lists section {
  display: grid;
  gap: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.85rem;
  background: #fff;
}

.admin-card h3,
.admin-lists h3 {
  margin: 0;
  font-size: 1rem;
}

.admin-lists {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.admin-list {
  display: grid;
  gap: 0.5rem;
}

.admin-list-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.72rem;
  background: #f8fbfd;
}

.admin-list-item strong,
.admin-list-item span {
  display: block;
}

.admin-list-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.editor {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
}

.editor.is-open {
  display: block;
}

.editor-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 24, 36, 0.45);
}

.editor-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 18px 18px 0 0;
  padding: 0.65rem 1rem calc(1rem + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -22px 50px rgba(10, 24, 36, 0.22);
}

.editor-handle {
  width: 52px;
  height: 5px;
  margin: 0 auto 0.85rem;
  border-radius: 999px;
  background: #cfdae2;
}

.editor-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.editor-heading h2 {
  font-size: 1.25rem;
}

.editor-control {
  display: grid;
  gap: 0.45rem;
}

.editor-control small {
  color: var(--muted);
}

.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

@media (max-width: 780px) {
  .floating-tools {
    left: 0.45rem;
    bottom: 0.45rem;
    max-width: calc(100vw - 5.6rem);
    gap: 0.28rem;
  }

  .tool-button {
    min-height: 30px;
    padding: 0.28rem 0.42rem;
    font-size: 0.72rem;
  }

  .sync-badge {
    min-height: 30px;
    padding: 0.28rem 0.42rem;
    font-size: 0.68rem;
  }

  .admin-grid,
  .admin-lists {
    grid-template-columns: 1fr;
  }

  .excel-row {
    grid-template-columns:
      99px 233px 173px 212px 281px 192px 110px 198px 158px 109px 162px
      309px;
  }

  .row-1 .excel-cell,
  .title-cell {
    font-size: 18px;
  }

  .instruction-cell {
    height: 44px;
    font-size: 18px;
  }

  .meta-label,
  .meta-value {
    font-size: 18px;
  }

  .row-8 .excel-cell,
  .column-head {
    font-size: 18px;
  }

  .data-row .excel-cell,
  .data-cell {
    font-size: 20px;
  }

  .sheet-view {
    padding-bottom: 5.5rem;
  }

  .sheet-title {
    min-height: 58px;
    padding-right: 3.7rem;
    padding-left: 3.7rem;
  }

  .sheet-title h1 {
    font-size: 1.02rem;
    line-height: 1.08;
  }

  .sheet-title .ghost-button,
  .sheet-title .icon-button {
    top: calc(0.65rem + env(safe-area-inset-top));
    min-height: 32px;
    padding: 0.3rem 0.46rem;
    font-size: 0.78rem;
  }

  .sheet-title .icon-button {
    left: 0.55rem;
    width: 42px;
  }

  .sheet-title .ghost-button {
    right: 0.55rem;
  }

  .sheet-note,
  .header-card,
  .status-strip,
  .entry-focus,
  .sheet-wrap {
    margin: 0;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .header-card-title {
    align-items: stretch;
    flex-direction: column;
  }

  .header-card-title button {
    width: auto;
    margin-left: auto;
  }

  .header-card.is-locked .header-card-title {
    margin-bottom: 0;
  }

  .header-card.is-locked .header-grid {
    grid-template-columns: 1fr;
  }

  .header-card.is-locked .header-grid label {
    grid-template-columns: 118px minmax(0, 1fr);
    align-items: center;
  }

  .header-card {
    min-height: 178px;
  }

  .header-grid {
    margin-top: 0.75rem;
  }

  .header-grid label {
    grid-template-columns: 118px minmax(0, 1fr);
    min-height: 46px;
    font-size: clamp(1.25rem, 3.6vw, 2.25rem);
  }

  .sheet-note {
    font-size: clamp(1.22rem, 4.2vw, 2rem);
  }

  .sheet-spacer .sheet-cell {
    min-height: 52px;
  }

  .sheet-grid {
    min-width: 1040px;
  }

  .sheet-row {
    grid-template-columns:
      74px 128px 148px 128px 185px 168px 92px 168px 152px 130px 132px
      190px;
  }

  .sheet-cell {
    min-height: 58px;
    padding: 0.5rem;
    font-size: 0.9rem;
  }

  .sheet-header .sheet-cell {
    min-height: 66px;
    font-size: 0.9rem;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 0.5cm;
  }

  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    background: #fff;
  }

  .login-view,
  .floating-tools,
  .fab,
  .editor,
  .archives,
  .admin,
  .sync-badge {
    display: none !important;
  }

  .sheet-view,
  .sheet-wrap {
    display: block !important;
    width: auto;
    height: auto;
    overflow: visible;
    padding: 0;
  }

  body.pdf-export-mode .data-row.is-empty {
    display: none !important;
  }

  .excel-sheet {
    min-height: auto;
    transform: none;
    transform-origin: top left;
    zoom: 0.44;
  }
}
