:root {
  color-scheme: light;
  --paper: #f3efe5;
  --ink: #1c252b;
  --accent: #b85c38;
  --border: rgba(28, 37, 43, 0.14);
  --shadow: 0 24px 60px rgba(28, 37, 43, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(184, 92, 56, 0.20), transparent 32rem),
    linear-gradient(135deg, #f8f1df 0%, var(--paper) 42%, #e8ddd0 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.page {
  position: relative;
  width: min(1500px, calc(100vw - 48px));
  min-height: calc(100vh - 48px);
  margin: 24px auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(28, 37, 43, 0.92);
  color: #fff;
  font-size: 1.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-menu {
  position: absolute;
  top: 36px;
  right: 32px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 3px;
  border: 1px solid rgba(28, 37, 43, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 8px 20px rgba(28, 37, 43, 0.10);
}

.top-menu-link {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  border: 0;
  background: transparent;
  font-family: inherit;
}

.top-menu-link:hover,
.top-menu-link.active {
  background: var(--ink);
  color: #fff;
}

.top-menu-link.disabled {
  color: rgba(28, 37, 43, 0.45);
  cursor: not-allowed;
}

.top-menu-link.disabled:hover {
  background: transparent;
  color: rgba(28, 37, 43, 0.45);
}

.top-menu-icon {
  width: 28px;
  justify-content: center;
  padding: 0;
}

.top-menu-link svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.help-control {
  position: relative;
  display: inline-flex;
}

.help-icon-button {
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

button.help-icon-button {
  width: 28px;
  min-width: 0;
  min-height: 22px;
  padding: 0;
  color: var(--ink);
}

.help-menu {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 20;
  display: none;
  width: min(430px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 120px));
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 30px rgba(28, 37, 43, 0.18);
}

.help-control.open .help-menu {
  display: grid;
  gap: 10px;
}

.help-section {
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(28, 37, 43, 0.10);
}

.help-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.help-section h2 {
  margin: 0 0 5px;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.help-section p {
  margin: 0;
  color: rgba(28, 37, 43, 0.68);
  font-size: 0.88rem;
  line-height: 1.42;
}

.layout-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 42px 0 8px;
}

h1 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.active-file {
  max-width: min(420px, 34vw);
  margin-top: 0.36rem;
  color: rgba(28, 37, 43, 0.74);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: right;
  overflow-wrap: anywhere;
}

.lead {
  max-width: 760px;
  margin: 0 0 24px;
  color: rgba(28, 37, 43, 0.72);
  font-size: 1.05rem;
  line-height: 1.55;
}

.layout-test-menu {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 54px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.layout-area-select {
  position: relative;
  margin: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

.layout-area-select summary {
  display: inline-flex;
  align-items: center;
  min-width: 132px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
}

.layout-area-select summary::-webkit-details-marker {
  display: none;
}

.layout-area-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 10;
  display: grid;
  gap: 2px;
  min-width: 170px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 26px rgba(28, 37, 43, 0.14);
}

.layout-area-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 6px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.layout-area-menu label:hover {
  background: rgba(184, 92, 56, 0.12);
}

.layout-area-menu input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.layout-preview-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  min-height: 34px;
  padding: 7px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: none;
}

.layout-preview-button:hover {
  background: var(--accent);
}

.layout-workspaces {
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  overflow: hidden;
}

.layout-workspace {
  min-height: 360px;
  padding: 18px;
}

.layout-workspace[hidden] {
  display: none;
}

.layout-workspace h2 {
  margin: 0 0 10px;
  font-size: 1.12rem;
}

.layout-workspace p {
  max-width: 680px;
  margin: 0;
  color: rgba(28, 37, 43, 0.66);
  line-height: 1.5;
}

.workspace-summary,
.workspace-empty {
  margin: 0 0 12px;
}

.workspace-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.workspace-counts span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: rgba(28, 37, 43, 0.70);
  font-size: 0.82rem;
  font-weight: 800;
}

.ocr-grouping-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
}

.ocr-grouping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.ocr-grouping-table th,
.ocr-grouping-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(28, 37, 43, 0.10);
  text-align: left;
  vertical-align: top;
}

.ocr-grouping-table th {
  background: rgba(248, 241, 223, 0.64);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ocr-grouping-table tr:last-child td {
  border-bottom: 0;
}

.layout-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 330px;
  min-height: 610px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  overflow: hidden;
}

.layout-sidebar,
.layout-inspector {
  padding: 16px;
  background: rgba(255, 255, 255, 0.58);
}

.layout-sidebar { border-right: 1px solid var(--border); }
.layout-inspector { border-left: 1px solid var(--border); }

.section-label {
  margin: 0 0 8px;
  color: rgba(28, 37, 43, 0.56);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-item,
.tool-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 34px;
  margin-bottom: 6px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
}

.nav-item.active,
.tool-button:hover,
.nav-item:hover {
  border-color: rgba(184, 92, 56, 0.28);
  background: rgba(184, 92, 56, 0.12);
}

.layout-stage {
  padding: 18px;
  overflow: auto;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.icon-group {
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 34px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.context-line {
  color: rgba(28, 37, 43, 0.62);
  font-size: 0.86rem;
  font-weight: 700;
}

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

.layout-card {
  min-height: 170px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  overflow: hidden;
}

.layout-card h2 {
  margin: 0;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 241, 223, 0.64);
  font-size: 0.96rem;
}

.layout-card p {
  margin: 0;
  padding: 12px;
  color: rgba(28, 37, 43, 0.66);
  line-height: 1.5;
}

.dropzone {
  min-height: 230px;
  display: grid;
  place-items: center;
  margin: 12px;
  padding: 16px;
  border: 1px dashed rgba(28, 37, 43, 0.28);
  border-radius: 8px;
  color: rgba(28, 37, 43, 0.62);
  text-align: center;
  background: rgba(255, 255, 255, 0.52);
}

details {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.80);
  overflow: hidden;
}

summary {
  cursor: pointer;
  padding: 10px;
  font-weight: 800;
}

details p {
  margin: 0;
  padding: 0 10px 10px;
  color: rgba(28, 37, 43, 0.66);
  line-height: 1.5;
}

.layout-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(184, 92, 56, 0.34);
  border-radius: 8px;
  background: rgba(184, 92, 56, 0.10);
  color: #7a321c;
  font-weight: 700;
}

@media (max-width: 1120px) {
  .layout-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .layout-inspector { display: none; }
}

@media (max-width: 760px) {
  .page {
    width: min(100vw - 20px, 1500px);
    margin: 10px auto;
    padding: 18px;
  }
  .top-menu {
    position: static;
    margin-top: 14px;
    width: max-content;
    max-width: 100%;
    flex-wrap: wrap;
  }
  .layout-heading {
    flex-direction: column;
    gap: 8px;
    margin-top: 28px;
  }
  .active-file {
    max-width: 100%;
    text-align: left;
  }
  .layout-test-menu {
    align-items: flex-start;
    flex-direction: column;
  }
  .layout-area-select,
  .layout-area-select summary {
    width: 100%;
  }
  .layout-area-menu {
    position: static;
    margin-top: 6px;
    width: 100%;
  }
  .layout-preview-button {
    width: 100%;
    margin-left: 0;
  }
  .layout-shell,
  .card-grid { grid-template-columns: 1fr; }
  .layout-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
