:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f0f4f8;
  --text: #17202a;
  --muted: #667085;
  --line: #d8dee6;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --accent: #b45309;
  --danger: #b42318;
  --shadow: 0 16px 44px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.25;
}

.brand p,
.hint,
.sidebar-card p,
.node-help,
.output-toolbar,
.project-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.workflow-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-btn {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-btn:hover,
.nav-btn.is-active {
  border-color: var(--line);
  background: white;
}

.nav-btn.is-active {
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.12);
}

.nav-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.nav-copy {
  min-width: 0;
}

.nav-copy strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-copy span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar-card {
  padding: 16px;
}

.sidebar-card:first-of-type {
  margin-top: auto;
}

.sidebar-card strong {
  display: block;
  margin: 6px 0;
  font-size: 16px;
}

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

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

.topbar h2 {
  margin-top: 4px;
  font-size: 26px;
}

.topbar-actions,
.button-row,
.output-toolbar,
.split-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

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

.workspace-grid.hide-profile {
  grid-template-columns: minmax(0, 1fr);
}

.workspace-grid.hide-profile .input-panel {
  display: none;
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 16px;
}

.panel-heading h3 {
  margin-top: 4px;
  font-size: 18px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 13px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

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

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

textarea {
  min-height: 82px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.generator-panel {
  min-height: calc(100vh - 112px);
}

.node-help {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.primary-btn,
.ghost-btn,
.primary-link,
.icon-btn,
.tab {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: white;
  color: var(--text);
  font-weight: 800;
}

.primary-link {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--primary);
  color: white;
  text-decoration: none;
  font-weight: 800;
}

.ghost-link {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: white;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.primary-btn {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.primary-btn:hover {
  background: var(--primary-strong);
}

.ghost-btn:hover,
.tab:hover {
  border-color: #aab4c1;
}

.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.full {
  width: 100%;
}

.output-toolbar {
  justify-content: space-between;
  margin: 14px 0 8px;
}

#savePositioningBtn {
  display: none;
}

#savePositioningBtn.is-visible {
  display: inline-flex;
  align-items: center;
}

.output,
.template-preview {
  overflow: auto;
  min-height: 390px;
  max-height: 62vh;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #e7eef6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(560px, 94vw);
  height: 100vh;
  overflow: auto;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: white;
  box-shadow: -18px 0 44px rgba(15, 23, 42, 0.16);
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.settings-drawer.is-open {
  transform: translateX(0);
}

.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  background: rgba(15, 23, 42, 0.28);
}

.drawer-mask.is-open {
  display: block;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 18px;
}

.icon-btn {
  width: 40px;
  padding: 0;
  font-size: 24px;
}

.drawer-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.tab.is-active {
  border-color: var(--primary);
  background: #e6f5f3;
  color: var(--primary-strong);
}

.drawer-section {
  display: none;
}

.drawer-section.is-active {
  display: block;
}

.drawer-section textarea {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.template-preview {
  min-height: 320px;
  max-height: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17202a;
  color: white;
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(12px);
  transition: 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.admin-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.admin-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

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

.admin-nav .tab {
  justify-content: flex-start;
  text-align: left;
}

.admin-main {
  min-width: 0;
  padding: 24px;
}

.admin-main .drawer-section {
  max-width: 980px;
}

.admin-actions {
  justify-content: flex-end;
  margin: 0 0 12px;
}

.admin-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

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

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  background: var(--panel-soft);
  color: #334155;
  font-size: 12px;
}

.inline-date {
  min-width: 150px;
  min-height: 34px;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: #e6f5f3;
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.pending {
  background: #fff7ed;
  color: #b45309;
}

.status-pill.expired,
.status-pill.rejected {
  background: #fee4e2;
  color: var(--danger);
}

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 12px;
    padding: 14px 16px 12px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    background: rgba(251, 252, 253, 0.97);
    backdrop-filter: blur(12px);
  }

  .admin-side {
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .workflow-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 8px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .workflow-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 104px;
    grid-template-columns: 22px minmax(0, auto);
    padding: 9px 10px;
    border-color: var(--line);
    background: white;
  }

  .nav-btn.is-active {
    border-color: var(--primary);
    background: #e6f5f3;
  }

  .nav-index {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .nav-copy strong {
    font-size: 13px;
  }

  .nav-copy span {
    display: none;
  }

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

  .sidebar-card {
    display: none;
  }
}

body.touch-nav .app-shell {
  display: block;
}

body.touch-nav .sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 12px;
  padding: 14px 16px 12px;
  border-right: none;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 253, 0.97);
  backdrop-filter: blur(12px);
}

body.touch-nav .workflow-nav {
  display: flex;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

body.touch-nav .workflow-nav::-webkit-scrollbar {
  display: none;
}

body.touch-nav .nav-btn {
  flex: 0 0 auto;
  width: auto;
  min-width: 104px;
  grid-template-columns: 22px minmax(0, auto);
  padding: 9px 10px;
  border-color: var(--line);
  background: white;
}

body.touch-nav .nav-btn.is-active {
  border-color: var(--primary);
  background: #e6f5f3;
}

body.touch-nav .nav-index {
  width: 22px;
  height: 22px;
  font-size: 11px;
}

body.touch-nav .nav-copy strong {
  font-size: 13px;
}

body.touch-nav .nav-copy span,
body.touch-nav .sidebar-card {
  display: none;
}

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

@media (max-width: 900px) {
  .main,
  .sidebar,
  .admin-main,
  .admin-side {
    padding: 16px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    font-size: 16px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    font-size: 12px;
  }

  .main {
    padding-top: 12px;
  }

  .topbar,
  .panel-heading,
  .output-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .button-row,
  .split-row {
    align-items: stretch;
    flex-direction: column;
  }

  .drawer-tabs {
    grid-template-columns: 1fr;
  }

  .topbar {
    margin-bottom: 12px;
  }

  .topbar .eyebrow {
    display: none;
  }

  .topbar h2 {
    font-size: 24px;
  }

  .workspace-grid {
    gap: 12px;
  }

  .panel {
    padding: 14px;
  }

  .generator-panel {
    min-height: auto;
  }

  .output {
    min-height: 300px;
    max-height: none;
  }

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