:root {
  --blue: #0f62d9;
  --blue-dark: #0647a8;
  --blue-soft: #eaf2ff;
  --ink: #1f2937;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --page: #f5f7fb;
  --green: #14804a;
  --orange: #c25a00;
  --red: #c73333;
  --shadow: 0 10px 30px rgba(20, 32, 58, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--page);
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 8px;
  margin: 0 auto 18px;
}

.nav-item,
.icon-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.nav-item {
  min-height: 64px;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
}

.nav-item span {
  font-size: 13px;
}

.nav-item.active {
  color: var(--blue);
  background: var(--blue-soft);
  box-shadow: inset 4px 0 0 var(--blue);
}

.main-panel {
  min-width: 0;
}

.topbar {
  height: 64px;
  background: linear-gradient(90deg, var(--blue-dark), var(--blue));
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .icon-button {
  color: #fff;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: rgba(15, 98, 217, 0.1);
  outline: 0;
}

.topbar .icon-button:hover,
.topbar .icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.16);
}

.topbar-actions {
  display: flex;
  gap: 4px;
}

.menu-toggle {
  display: none;
}

.view {
  display: none;
  padding: 28px;
}

.view.active {
  display: block;
}

.home-hero,
.form-panel,
.filters,
.stat-card,
.chart-panel,
.table-panel,
dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.home-hero {
  width: min(760px, 100%);
  max-width: 760px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 24px;
  margin-bottom: 18px;
}

.hero-icon {
  flex: 0 0 84px;
  height: 84px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 8px;
  background: var(--blue);
}

.hero-icon svg {
  width: 48px;
  height: 48px;
}

.home-hero h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.home-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
}

.primary-action {
  width: min(760px, 100%);
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 26px 0 12px;
}

.section-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

#homeView .section-head {
  max-width: 760px;
}

.section-head h2,
.section-head h3 {
  margin: 0;
}

.section-head.compact {
  margin: 0 0 12px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
  text-transform: uppercase;
}

.recent-list {
  width: min(760px, 100%);
  max-width: 760px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.recent-item {
  width: 100%;
  border: 0;
  background: #fff;
  text-align: left;
  color: inherit;
  display: grid;
  grid-template-columns: 48px 1fr auto 28px;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.recent-item:last-child {
  border-bottom: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--blue-dark);
  background: #dff4ff;
}

.recent-main strong {
  display: block;
}

.recent-main span,
.recent-meta {
  color: var(--muted);
  font-size: 13px;
}

.chevron {
  color: var(--muted);
  font-size: 24px;
}

.form-panel {
  max-width: 620px;
  margin: 0 auto;
  overflow: hidden;
}

.form-head {
  min-height: 64px;
  display: grid;
  grid-template-columns: 54px 1fr 54px;
  align-items: center;
  padding: 0 10px;
  background: var(--blue);
  color: #fff;
}

.form-head h2 {
  margin: 0;
  font-size: 20px;
}

.form-head .icon-button {
  color: #fff;
}

.field {
  display: grid;
  gap: 8px;
  padding: 14px 24px 0;
}

.field span {
  font-weight: 700;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(15, 98, 217, 0.12);
}

.combo-row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 8px;
}

.combo-row .icon-button {
  height: 48px;
  border: 1px solid var(--line);
}

.info-strip {
  margin: 22px 24px 0;
  padding: 14px;
  color: #174c9c;
  background: var(--blue-soft);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 22px 24px 24px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--blue);
  color: #fff;
  background: var(--blue);
}

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

.danger-button {
  border: 1px solid var(--red);
  color: #fff;
  background: var(--red);
  margin-right: auto;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr)) auto auto;
  gap: 14px;
  align-items: end;
  padding: 18px;
  margin-bottom: 18px;
}

.filters label {
  display: grid;
  gap: 8px;
}

.filters span {
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 22px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  right: 22px;
  top: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--blue-soft);
}

.stat-card.accent::after {
  background: #fff1df;
}

.stat-card.green::after {
  background: #e7f7ee;
}

.stat-card span {
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 42px;
  color: var(--blue);
  line-height: 1;
}

.stat-card.accent strong {
  color: var(--orange);
}

.stat-card.green strong {
  color: var(--green);
}

.stat-card small {
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 18px;
}

.chart-panel,
.table-panel {
  padding: 18px;
  min-width: 0;
}

.table-panel.wide {
  grid-column: 1 / -1;
}

.table-panel:not(.wide) table {
  min-width: 100%;
}

canvas {
  width: 100%;
  height: 300px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: #fff;
  background: #1f5fa8;
  font-weight: 700;
}

tbody tr:nth-child(odd) {
  background: #edf5ff;
}

tbody tr:hover {
  background: #ddecff;
}

.logs-table table {
  min-width: 1080px;
}

.sheet-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr)) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sheet-settings label {
  display: grid;
  gap: 8px;
}

.sheet-settings span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.google-sheet-shell {
  background: #fff;
  border: 1px solid #c6c6c6;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet-formula {
  height: 28px;
  display: grid;
  grid-template-columns: 86px 30px 1fr;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid #d7dbe0;
  color: #202124;
  font-size: 13px;
}

.sheet-formula strong {
  color: #6f7378;
  font-style: italic;
}

.sheet-grid-wrap {
  overflow: auto;
  max-height: 68vh;
}

.sheet-grid {
  min-width: 1380px;
  table-layout: fixed;
  border-collapse: collapse;
  color: #3c4043;
  font-size: 13px;
}

.sheet-grid .row-num {
  width: 46px;
}

.sheet-grid .col-a {
  width: 98px;
}

.sheet-grid .col-b {
  width: 154px;
}

.sheet-grid .col-c {
  width: 168px;
}

.sheet-grid .col-d {
  width: 98px;
}

.sheet-grid .col-e {
  width: 126px;
}

.sheet-grid .col-f {
  width: 140px;
}

.sheet-grid .col-g {
  width: 246px;
}

.sheet-grid .col-extra {
  width: 60px;
}

.sheet-grid th,
.sheet-grid td {
  height: 26px;
  padding: 4px 8px;
  border: 1px solid #d9d9d9;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.sheet-grid tbody th,
.sheet-letters th {
  background: #f8fafd;
  color: #202124;
  text-align: center;
  font-weight: 400;
}

.sheet-headers th {
  position: relative;
  height: 44px;
  color: #fff;
  background: #1f5fa8;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  overflow: visible;
}

.sheet-headers th:first-child {
  color: #188038;
  background: #d9f0e3;
}

.sheet-headers th:nth-child(n+9) {
  color: #202124;
  background: #fff;
}

.anonymous-tag {
  position: absolute;
  top: -17px;
  left: 30px;
  padding: 2px 8px;
  color: #fff;
  background: #188038;
  border-radius: 4px;
  font-size: 10px;
  line-height: 1;
}

.filter-mark {
  position: absolute;
  right: 8px;
  bottom: 12px;
  width: 12px;
  height: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.8);
  border-bottom: 1px solid rgba(255, 255, 255, 0.8);
}

.sheet-grid tbody tr:nth-child(odd),
.sheet-grid tbody tr.template-row {
  background: #e9f3ff;
}

.sheet-grid tbody tr:hover {
  background: #ddecff;
}

.sheet-grid tbody td {
  text-align: center;
}

.sheet-cell.selected {
  position: relative;
  outline: 2px solid #1a73e8;
  outline-offset: -2px;
}

.sheet-cell.selected::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1a73e8;
}

.staff-cell {
  position: relative;
  padding-right: 20px;
}

.dropdown-caret {
  position: absolute;
  right: 6px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #5f6368;
  transform: translateY(-50%);
}

.sheet-grid tbody tr:nth-child(odd) .dropdown-caret {
  border-top-color: #1a73e8;
}

.sheet-tabs {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: #f1f3f4;
  border-top: 1px solid #c6c6c6;
}

.sheet-add,
.sheet-menu,
.sheet-tab {
  border: 0;
  background: transparent;
  color: #3c4043;
}

.sheet-add,
.sheet-menu {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
}

.sheet-menu svg {
  width: 18px;
  height: 18px;
}

.sheet-tab {
  height: 36px;
  padding: 0 14px;
  font-weight: 700;
}

.sheet-tab.active {
  color: #0b57d0;
  background: #dfe7f5;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.mini-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  background: #fff;
  font-weight: 700;
}

dialog {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.edit-form {
  padding-top: 18px;
}

.edit-form .section-head {
  padding: 0 20px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 220px;
  max-width: calc(100vw - 36px);
  padding: 14px 16px;
  color: #fff;
  background: #1f2937;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 76px 1fr;
  }

  .sidebar {
    padding-inline: 8px;
  }

  .nav-item span {
    font-size: 11px;
  }

  .filters,
  .sheet-settings,
  .stats-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .filters {
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .main-panel {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    position: fixed;
    z-index: 50;
    width: 100%;
    height: 76px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-right: 0;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    box-shadow: 0 -8px 24px rgba(20, 32, 58, 0.08);
  }

  .sidebar.open {
    transform: none;
  }

  .brand-mark {
    display: none;
  }

  .nav-item {
    flex: 1 1 0;
    min-height: 60px;
    padding: 6px 4px;
    gap: 4px;
  }

  .nav-item.active {
    box-shadow: inset 0 3px 0 var(--blue);
  }

  .nav-item svg {
    width: 21px;
    height: 21px;
  }

  .nav-item span {
    font-size: 11px;
    line-height: 1.15;
  }

  .menu-toggle {
    display: none;
  }

  .view {
    padding: 16px 14px 104px;
    overflow-x: hidden;
  }

  .topbar {
    width: 100%;
    max-width: 100vw;
    height: 56px;
    padding: 0 12px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 17px;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .topbar .icon-button {
    width: 36px;
  }

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

  body[data-view="new"] .topbar {
    display: none;
  }

  .home-hero {
    width: 100%;
    max-width: 100%;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
  }

  .primary-action,
  #homeView .section-head,
  .recent-list {
    width: 100%;
    max-width: 100%;
  }

  .hero-icon {
    flex-basis: 62px;
    height: 62px;
  }

  .hero-icon svg {
    width: 36px;
    height: 36px;
  }

  .home-hero h2 {
    font-size: 22px;
  }

  .home-hero p {
    font-size: 15px;
  }

  .primary-action {
    min-height: 56px;
    font-size: 16px;
  }

  .section-head {
    margin: 22px 0 12px;
  }

  .section-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .section-head h2,
  .section-head h3 {
    font-size: 20px;
  }

  .link-button {
    font-size: 14px;
  }

  .recent-item {
    grid-template-columns: 44px 1fr 26px;
    min-height: 86px;
    padding: 14px;
  }

  .recent-meta {
    grid-column: 2;
  }

  #newView {
    padding: 0 0 104px;
  }

  .form-panel {
    max-width: none;
    min-height: calc(100vh - 76px);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .form-head {
    grid-template-columns: 48px 1fr 48px;
    min-height: 58px;
  }

  .form-head h2 {
    font-size: 18px;
  }

  .field {
    gap: 7px;
    padding-top: 16px;
    padding-inline: 16px;
  }

  .field span {
    font-size: 14px;
  }

  input,
  select,
  textarea {
    min-height: 52px;
    padding: 12px 14px;
    font-size: 16px;
  }

  .combo-row {
    grid-template-columns: 1fr 52px;
  }

  .combo-row .icon-button {
    height: 52px;
    width: 52px;
  }

  .info-strip,
  .form-actions {
    margin-inline: 16px;
  }

  .info-strip {
    align-items: flex-start;
    font-size: 14px;
  }

  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding-inline: 0;
  }

  .primary-button,
  .secondary-button,
  .danger-button {
    min-height: 50px;
    padding: 0 14px;
  }

  .filters {
    padding: 14px;
    gap: 12px;
  }

  .stats-grid {
    gap: 12px;
  }

  .stat-card {
    padding: 18px;
  }

  .stat-card strong {
    font-size: 34px;
  }

  .dashboard-grid {
    gap: 12px;
  }

  .chart-panel,
  .table-panel {
    padding: 14px;
  }

  canvas {
    height: 240px;
  }

  .sheet-settings {
    margin-left: -14px;
    margin-right: -14px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .sheet-settings .primary-button,
  .sheet-settings .secondary-button {
    width: 100%;
  }

  .google-sheet-shell {
    margin-left: -14px;
    margin-right: -14px;
    border-left: 0;
    border-right: 0;
  }

  .sheet-grid-wrap {
    max-height: calc(100vh - 330px);
    -webkit-overflow-scrolling: touch;
  }

  .sheet-tabs {
    height: 44px;
  }

  .sheet-tab {
    height: 42px;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 12px 12px 0 0;
  }

  .edit-form .form-actions {
    margin-inline: 16px;
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    min-width: 0;
  }
}
