:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #172033;
  --muted: #5d6677;
  --muted-strong: #445066;
  --border: #d8dde6;
  --border-soft: #e8ebf1;
  --blue: #143c70;
  --blue-dark: #102f59;
  --blue-soft: #e8eef7;
  --danger: #a83232;
  --shadow: 0 18px 48px rgba(23, 32, 51, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

button:hover:not(:disabled) {
  background: var(--blue-dark);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button,
.danger-button {
  min-width: 110px;
  padding: 0 14px;
  background: var(--blue-soft);
  color: var(--blue);
}

.secondary-button:hover:not(:disabled) {
  background: #dbe6f4;
}

.danger-button {
  background: #f6e7e7;
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  background: #edd4d4;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #f3c646;
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  inset-block-start: 12px;
  inset-inline-start: 12px;
  padding: 10px 12px;
  transform: translateY(-140%);
  background: var(--blue);
  color: white;
  border-radius: 6px;
  z-index: 10;
}

.skip-link:focus {
  transform: translateY(0);
}

.shell {
  width: min(1360px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-block-end: 18px;
}

.brand-block {
  max-width: 760px;
}

.brand-row {
  display: flex;
  align-items: center;
  margin-block-end: 12px;
  padding-inline-start: 0;
}

.brandmark {
  display: block;
  width: 30px;
  height: auto;
  flex: 0 0 auto;
}

.brand-logo {
  width: 156px;
  height: auto;
}

.brand {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.55rem);
  line-height: 1.08;
}

h2 {
  font-size: 1.05rem;
}

.workspace {
  display: grid;
  gap: 18px;
  align-items: start;
}

.control-panel,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  overflow: hidden;
}

.settings-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(320px, 1.4fr) auto;
  align-items: end;
  gap: 18px;
  padding: 20px;
}

.field {
  display: grid;
  gap: 8px;
}

label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.date-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

.settings-form > button {
  min-width: 180px;
  padding: 0 18px;
}

.status {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  min-height: 0;
  margin: 0;
  background: rgba(244, 246, 248, 0.68);
  backdrop-filter: blur(2px);
  z-index: 20;
}

.status.loading {
  display: grid;
  gap: 16px;
  color: var(--muted-strong);
  font-weight: 750;
  text-align: center;
}

.status:not(.loading) {
  position: static;
  display: flex;
  min-height: 0;
  align-items: center;
  margin: 0 0 10px;
  color: var(--muted);
  font-weight: 650;
}

.status.loading::before {
  width: 46px;
  height: 46px;
  content: "";
  border: 5px solid #cad6e6;
  border-top-color: var(--blue);
  border-radius: 999px;
  animation: spin 760ms linear infinite;
}

.status.error {
  color: var(--danger);
}

.report-stack {
  min-width: 0;
}

.result-panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-head button {
  min-width: 190px;
  padding: 0 14px;
  background: var(--blue-soft);
  color: var(--blue);
}

.panel-head button:hover:not(:disabled) {
  background: #dbe6f4;
}

.section-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.report-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  background: #f3f6fa;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  color: var(--muted-strong);
  font-size: 0.84rem;
  font-weight: 700;
}

.preview {
  min-height: calc(100svh - 230px);
  max-height: none;
  overflow: auto;
  padding: 24px 26px 32px;
}

.preview.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.preview h1 {
  margin-block-end: 10px;
  font-size: 1.38rem;
  line-height: 1.25;
}

.preview h2 {
  margin: 24px 0 12px;
  font-size: 1.12rem;
  line-height: 1.3;
}

.preview h3 {
  margin: 18px 0 10px;
  font-size: 1rem;
  line-height: 1.35;
}

.preview p {
  margin: 0 0 12px;
  line-height: 1.5;
}

.preview ul {
  margin: 0 0 14px 1.2rem;
  padding: 0;
  line-height: 1.5;
}

.preview li + li {
  margin-top: 6px;
}

.preview hr {
  margin: 20px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.table-wrap {
  max-width: 100%;
  overflow: visible;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 16px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
}

th,
td {
  padding: 8px;
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
  text-align: left;
  vertical-align: top;
}

th:nth-child(1),
td:nth-child(1) {
  width: 4%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 5%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 18%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 10%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 11%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 11%;
}

th:nth-child(7),
td:nth-child(7) {
  width: 25%;
}

th:nth-child(8),
td:nth-child(8) {
  width: 16%;
}

th {
  background: var(--blue);
  color: white;
  font-weight: 750;
}

tbody tr:nth-child(even) td {
  background: #f5f7fb;
}

a {
  color: var(--blue);
}

.history-section {
  margin-top: 18px;
  padding-bottom: 6px;
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.history-head p,
.history-empty {
  margin: 0;
  color: var(--muted);
  font-weight: 650;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.04);
}

.history-item summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
}

.history-summary-title {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-summary-time {
  justify-self: end;
  color: var(--muted);
  font-weight: 650;
  white-space: nowrap;
}

.history-item summary:focus-visible {
  outline: 3px solid #f3c646;
  outline-offset: 2px;
}

.history-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  padding: 0;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  place-items: center;
  padding: 0;
  border-radius: 6px;
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.history-preview {
  padding: 18px 18px 22px;
  border-top: 1px solid var(--border-soft);
  background: #fbfcfe;
}

.history-preview h1 {
  margin-block: 0 10px;
  font-size: 1.08rem;
  line-height: 1.3;
}

.history-preview h2,
.history-preview h3 {
  margin: 16px 0 10px;
  font-size: 0.98rem;
  line-height: 1.35;
}

.history-preview p {
  margin: 0 0 12px;
  line-height: 1.5;
}

.history-preview .table-wrap {
  overflow: auto;
}

.history-preview table {
  min-width: 860px;
  font-size: 0.75rem;
}

.site-footer {
  display: flex;
  justify-content: center;
  margin-top: 42px;
  opacity: 0.7;
  pointer-events: none;
}

.site-footer img {
  width: 156px;
  height: auto;
}

.login-shell {
  display: grid;
  width: min(100% - 32px, 430px);
  min-height: 100svh;
  margin: 0 auto;
  place-items: center;
}

.login-panel {
  display: grid;
  width: 100%;
  gap: 16px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel .brand-row {
  gap: 12px;
}

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

@media (max-width: 860px) {
  .shell {
    width: min(100% - 24px, 720px);
    padding: 28px 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 16px;
  }

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

  .settings-form,
  .date-grid {
    grid-template-columns: 1fr;
  }

  .settings-form > button {
    width: 100%;
  }

  .preview {
    min-height: 360px;
    max-height: none;
    padding: 18px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head button {
    width: 100%;
  }

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

  .history-item summary {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px 12px;
  }

  .history-summary-time {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
  }

  .history-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
    gap: 6px;
  }

  .site-footer {
    margin-top: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
