:root {
  color-scheme: light;
  --tp-bg: #f5f7f5;
  --tp-surface: #ffffff;
  --tp-surface-subtle: #eef2ef;
  --tp-surface-strong: #e4eae6;
  --tp-surface-hover: #f8faf8;
  --tp-border: #d7dfda;
  --tp-border-strong: #b8c5bd;
  --tp-text: #16211b;
  --tp-text-muted: #58665e;
  --tp-brand: #073b28;
  --tp-brand-hover: #062b1d;
  --tp-brand-soft: #eaf2ed;
  --tp-wood: #b84d00;
  --tp-focus: #d96008;
  --tp-success: #176640;
  --tp-success-soft: #edf8f1;
  --tp-warning: #7a520c;
  --tp-warning-soft: #fff8e8;
  --tp-warning-border: #e5c77f;
  --tp-error: #982b2b;
  --tp-error-soft: #fff3f3;
  --tp-error-border: #dfb5b5;
  --tp-radius-sm: 4px;
  --tp-radius-md: 8px;
  --tp-shadow-sm: 0 2px 8px rgb(6 43 29 / 8%);
  --tp-space-1: 4px;
  --tp-space-2: 8px;
  --tp-space-3: 12px;
  --tp-space-4: 16px;
  --tp-space-5: 20px;
  --tp-space-6: 24px;
  --tp-space-8: 32px;
  --tp-space-10: 40px;
  --tp-z-sticky: 300;
  --tp-z-shell: 1000;
  --tp-z-modal: 1200;
  --tp-z-toast: 1300;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--tp-text); background: var(--tp-bg); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.noscript {
  margin: var(--tp-space-6);
  padding: var(--tp-space-4);
  border: 1px solid var(--tp-warning-border);
  border-radius: var(--tp-radius-sm);
  color: var(--tp-warning);
  background: var(--tp-warning-soft);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--tp-space-10) var(--tp-space-6);
  background: var(--tp-bg);
}

.login-panel {
  width: min(440px, 100%);
  display: grid;
  justify-items: center;
  gap: var(--tp-space-8);
}

.login-card {
  width: 100%;
  display: grid;
  gap: var(--tp-space-2);
  padding: var(--tp-space-8);
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius-md);
  background: var(--tp-surface);
}

.login-logo {
  width: 320px;
  height: auto;
  justify-self: center;
}

.login-card label {
  margin-top: var(--tp-space-2);
  color: var(--tp-text);
  font-size: .875rem;
  font-weight: 650;
}

.login-card input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  padding: 0 var(--tp-space-3);
  color: var(--tp-text);
  background: var(--tp-surface);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 3px solid var(--tp-focus);
  outline-offset: 2px;
}

.login-card > button[type="submit"] {
  min-height: 48px;
  margin-top: var(--tp-space-3);
  border: 1px solid var(--tp-brand);
  border-radius: var(--tp-radius-sm);
  padding: 0 var(--tp-space-5);
  color: white;
  background: var(--tp-brand);
  font-weight: 750;
  cursor: pointer;
}

.login-card > button[type="submit"]:hover { background: var(--tp-brand-hover); }
.login-card > button[type="submit"]:disabled { cursor: wait; opacity: .68; }
.login-error {
  margin: var(--tp-space-2) 0 0;
  padding: var(--tp-space-3);
  border: 1px solid var(--tp-error-border);
  border-radius: var(--tp-radius-sm);
  color: var(--tp-error);
  background: var(--tp-error-soft);
  font-size: .875rem;
  line-height: 1.45;
}

.admin-app { min-height: 100vh; }
.admin-header {
  position: relative;
  z-index: var(--tp-z-shell);
  min-height: 64px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(16px, 3vw, 36px);
  padding: var(--tp-space-2) clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--tp-border);
  color: var(--tp-text);
  background: var(--tp-surface);
}

.admin-brand {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: var(--tp-space-3);
  color: var(--tp-brand);
  text-decoration: none;
  font-size: .8125rem;
  font-weight: 750;
  white-space: nowrap;
}

.admin-brand img { width: 146px; height: auto; }
.admin-brand span {
  padding-left: var(--tp-space-3);
  border-left: 1px solid var(--tp-border-strong);
}

.admin-nav { display: flex; align-items: center; gap: var(--tp-space-1); }
.admin-nav button,
.logout-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--tp-radius-sm);
  padding: 0 var(--tp-space-4);
  color: var(--tp-text-muted);
  background: transparent;
  font-weight: 650;
  cursor: pointer;
}

.admin-nav button:hover { color: var(--tp-brand); background: var(--tp-surface-subtle); }
.admin-nav button.active {
  border-color: var(--tp-border-strong);
  color: var(--tp-brand);
  background: var(--tp-brand-soft);
}

.logout-button { color: var(--tp-text-muted); }
.logout-button:hover { color: var(--tp-error); background: var(--tp-error-soft); }
.admin-view { min-height: calc(100vh - 64px); }
#content-view, #nc-root { min-height: calc(100vh - 64px); }
#content-view { background: var(--tp-bg); }
#analytics-view { overflow: auto; background: var(--tp-bg); }

.preview-view { overflow: hidden; background: var(--tp-surface-subtle); }
.preview-toolbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tp-space-4);
  padding: var(--tp-space-3) clamp(16px, 2.5vw, 32px);
  border-bottom: 1px solid var(--tp-border);
  background: var(--tp-surface);
}
.preview-summary { min-width: 0; display: grid; gap: var(--tp-space-1); }
.preview-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-summary span { color: var(--tp-text-muted); font-size: .8125rem; }
.preview-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--tp-space-2); flex-wrap: wrap; }
.preview-actions button,
.preview-actions a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  padding: 0 var(--tp-space-3);
  color: var(--tp-brand);
  background: var(--tp-surface);
  font-size: .8125rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.preview-actions button:hover,
.preview-actions a:hover { background: var(--tp-brand-soft); }
.viewport-switcher { display: flex; align-items: center; }
.viewport-switcher button { border-radius: 0; }
.viewport-switcher button:first-child { border-radius: var(--tp-radius-sm) 0 0 var(--tp-radius-sm); }
.viewport-switcher button:last-child { border-radius: 0 var(--tp-radius-sm) var(--tp-radius-sm) 0; }
.viewport-switcher button + button { margin-left: -1px; }
.viewport-switcher button.active { position: relative; border-color: var(--tp-brand); color: white; background: var(--tp-brand); }
.preview-stage {
  height: calc(100vh - 137px);
  overflow: auto;
  padding: var(--tp-space-5);
  background: var(--tp-surface-strong);
}
.preview-stage iframe {
  width: min(1440px, 100%);
  height: calc(100vh - 178px);
  display: block;
  margin: 0 auto;
  border: 0;
  background: white;
  box-shadow: 0 2px 8px rgb(6 43 29 / 12%);
}
.preview-stage[data-width="768"] iframe { width: min(768px, 100%); }
.preview-stage[data-width="390"] iframe { width: min(390px, 100%); }

@media (max-width: 680px) {
  .login-view { align-items: center; padding: var(--tp-space-5); }
  .login-panel { gap: var(--tp-space-6); }
  .login-card { padding: var(--tp-space-6); }
  .login-logo { width: min(300px, 86vw); }

  .admin-header {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--tp-space-1) var(--tp-space-2);
    padding: var(--tp-space-2) var(--tp-space-3) 0;
  }
  .admin-brand img { width: 118px; }
  .admin-brand span { padding-left: var(--tp-space-2); }
  .admin-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    border-top: 1px solid var(--tp-border);
    overflow-x: auto;
  }
  .admin-nav button { flex: 1 0 auto; border-radius: 0; padding-inline: var(--tp-space-3); }
  .admin-nav button.active { border-color: transparent; border-bottom-color: var(--tp-brand); }
  .logout-button { grid-column: 2; grid-row: 1; padding: 0 var(--tp-space-2); }
  .admin-view, #content-view, #nc-root { min-height: calc(100vh - 108px); }
  #content-view {
    position: relative;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--tp-border-strong) transparent;
  }
  #nc-root { width: 100%; min-width: 0; }
  .preview-toolbar { align-items: flex-start; flex-direction: column; }
  .preview-summary { width: 100%; }
  .preview-actions { width: 100%; justify-content: flex-start; }
  .viewport-switcher { width: 100%; }
  .viewport-switcher button { flex: 1; }
  .preview-stage { height: calc(100vh - 278px); padding: var(--tp-space-3); }
  .preview-stage iframe { height: calc(100vh - 302px); }
}

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