:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef4f0;
  --ink: #1d2329;
  --muted: #68737d;
  --line: #d9ded8;
  --green: #195f52;
  --green-2: #0f4b43;
  --blue: #2a5c8f;
  --gold: #b97912;
  --red: #ad3d35;
  --shadow: 0 14px 34px rgba(29, 35, 41, 0.08);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a.secondary-button,
a.primary-button {
  min-height: 36px;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.side-nav {
  background: #22312d;
  color: #f7fbf8;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: #d9efe7;
  color: var(--green-2);
  font-weight: 800;
}

.side-brand strong {
  display: block;
  font-size: 1rem;
}

.side-brand small {
  display: block;
  color: rgba(247, 251, 248, 0.7);
}

.tab-nav {
  display: grid;
  gap: 8px;
}

.tab-button {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: rgba(247, 251, 248, 0.76);
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  text-align: left;
}

.tab-button svg,
.icon-button svg,
.primary-button svg,
.secondary-button svg,
.danger-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.tab-button.active,
.tab-button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.main-workspace {
  min-width: 0;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 72px;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions,
.button-row,
.editor-actions,
.report-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-control {
  display: grid;
  gap: 4px;
  min-width: 170px;
}

.preview-control span,
label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.session-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-weight: 700;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button {
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 11px;
  text-decoration: none;
  white-space: nowrap;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.icon-button.ghost {
  border-color: transparent;
  background: transparent;
}

.primary-button {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
  font-weight: 800;
}

.primary-button:hover {
  background: var(--green-2);
}

.secondary-button {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 700;
}

.danger-button {
  background: #fff7f6;
  color: var(--red);
  border-color: #e8c9c5;
  font-weight: 800;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 16px;
  align-items: start;
}

.table-zone,
.editor-panel,
.report-section,
.share-panel,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(180px, 1fr) minmax(160px, 1fr);
  gap: 10px;
  flex: 1 1 620px;
}

label {
  display: grid;
  gap: 4px;
}

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

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

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(42, 92, 143, 0.22);
  outline-offset: 1px;
}

.data-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 190px);
}

.data-table {
  width: 100%;
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  max-width: 260px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf3ef;
  font-size: 0.78rem;
  color: #3d4c45;
}

.data-table td {
  line-height: 1.35;
}

.data-table tbody tr {
  cursor: pointer;
}

.data-table tbody tr:hover,
.data-table tbody tr.selected {
  background: #f1f7f4;
}

.cell-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-action {
  width: 52px;
  min-width: 52px;
}

.editor-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}

.editor-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.editor-head h2,
.report-section h2,
.share-panel h2 {
  margin: 0;
  font-size: 1rem;
}

#editor-meta {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 3px;
}

.event-form {
  padding: 14px;
  overflow: auto;
  display: grid;
  gap: 12px;
}

.field-group-title {
  margin: 8px 0 0;
  color: var(--blue);
  font-weight: 800;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.field-readonly input,
.field-readonly select,
.field-readonly textarea {
  background: #f3f5f2;
  color: #657069;
}

.editor-actions {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  justify-content: flex-end;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.toast-message {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  background: #eef7f3;
  color: var(--green-2);
  font-weight: 700;
}

.toast-message.error {
  background: #fff7f6;
  color: var(--red);
  border-color: #e8c9c5;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.metric-card small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.metric-card strong {
  font-size: 1.7rem;
  line-height: 1;
}

.metric-card.accent-green {
  border-top: 4px solid var(--green);
}

.metric-card.accent-blue {
  border-top: 4px solid var(--blue);
}

.metric-card.accent-gold {
  border-top: 4px solid var(--gold);
}

.metric-card.accent-red {
  border-top: 4px solid var(--red);
}

.report-toolbar {
  justify-content: flex-end;
  margin-bottom: 12px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.report-section {
  padding: 14px;
}

.report-section.wide {
  grid-column: 1 / -1;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.mini-table th,
.mini-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.mini-table th {
  color: var(--muted);
  font-size: 0.78rem;
}

.mini-table td:last-child,
.mini-table th:last-child {
  text-align: right;
}

.share-users {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.share-panel {
  padding: 14px;
}

.share-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.share-form {
  display: grid;
  gap: 10px;
}

.share-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.toggle-line input {
  width: 18px;
  height: 18px;
  min-height: 18px;
}

.permission-table {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 4px;
}

.permission-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 78px 78px;
  align-items: center;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}

.permission-row:last-child {
  border-bottom: 0;
}

.permission-row.header {
  background: #edf3ef;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.78rem;
}

.permission-row > span {
  padding: 8px 10px;
}

.permission-row label {
  place-items: center;
  padding: 0;
}

.permission-row input {
  width: 18px;
  height: 18px;
  min-height: 18px;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(135deg, #edf5f1, #f7f2e8 48%, #eef2f6);
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  padding: 28px;
}

.login-panel h1 {
  margin: 16px 0 6px;
  font-size: 1.45rem;
}

.login-panel p {
  margin: 0 0 18px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  background: var(--green);
  color: white;
  font-weight: 800;
}

.alert {
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-weight: 700;
}

.alert.error {
  background: #fff7f6;
  color: var(--red);
  border: 1px solid #e8c9c5;
}

[hidden],
.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 80px minmax(0, 1fr);
  }

  .side-brand div,
  .tab-button span {
    display: none;
  }

  .side-brand {
    justify-content: center;
  }

  .tab-button {
    grid-template-columns: 1fr;
    justify-items: center;
  }

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

  .editor-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
  }

  .side-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 10px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .tab-nav {
    display: flex;
  }

  .main-workspace {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-row,
  .share-users,
  .share-form-grid,
  .report-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .report-section.wide {
    grid-column: auto;
  }

  .data-table-wrap {
    max-height: none;
  }
}
