/* css/layout.css — Mat Window */

.auth-wrap {
  height: 100vh; height: 100dvh;
  position: relative;
  overflow: hidden;
  background: #070605;
}
.auth-pulse { display: none; }
.auth-card, .auth-corner { z-index: 2; }
.auth-corner { position: absolute; top: 20px; right: 20px; display: flex; gap: 8px; z-index: 5; }
.auth-card {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(400px, calc(100vw - 64px));
  height: fit-content;
  max-height: calc(100dvh - 48px);
  background: rgba(14, 13, 12, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  backdrop-filter: blur(28px) saturate(1.05);
  -webkit-backdrop-filter: blur(28px) saturate(1.05);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  padding: 40px 36px;
  display: flex; flex-direction: column; justify-content: center;
  overflow: auto;
}
.auth-logo {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: var(--accent);
  display: flex; align-items: center; justify-content: center; margin-bottom: 28px;
}
.auth-logo svg { color: var(--accent-text); width: 14px; height: 14px; }
.auth-card h1 {
  font-family: var(--font-display); font-size: 34px; font-weight: 600;
  letter-spacing: -0.04em; margin-bottom: 8px; line-height: 1.05;
}
.auth-card .sub { color: var(--text-2); margin-bottom: 32px; font-size: 13px; }
.auth-form .field-group { margin-bottom: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }
.switch-link { text-align: left; margin-top: 22px; font-size: 13px; color: var(--text-2); }
.switch-link a { font-weight: 600; border-bottom: 1px solid var(--accent); }
.auth-wrap::after { display: none; }
.auth-stage {
  position: absolute; inset: 0;
  margin: 0;
  background: #070605;
  pointer-events: none;
}
.auth-stage canvas { width: 100%; height: 100%; display: block; }

@media (max-width: 800px) {
  .auth-card { width: calc(100vw - 32px); padding: 32px 24px; }
}

.app { display: none; }
.app.active {
  display: grid;
  grid-template-columns: 212px 1fr;
  height: 100vh; height: 100dvh; overflow: hidden;
}

.sidebar {
  background: var(--bg-1); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 16px 14px 12px; }
.sb-logo {
  width: 24px; height: 24px; border-radius: var(--r-xs); background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sb-logo svg { color: var(--accent-text); width: 12px; height: 12px; }
.sb-brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sb-name { font-family: var(--font-display); font-size: 15px; font-weight: 600; line-height: 1.1; letter-spacing: -0.03em; }
.license-lock {
  position: fixed; inset: 0; z-index: 80; display: none;
  align-items: center; justify-content: center;
  background: #000; color: #fff;
}
.license-lock.show { display: flex; }
.license-lock-box {
  width: min(360px, calc(100vw - 48px));
  display: flex; flex-direction: column; gap: 12px;
}
.license-lock .input {
  background: #000; color: #fff; border: 1px solid #2a2a2a;
}
.license-lock .btn { width: 100%; }
.license-lock .error-msg { margin: 0; }

.sb-nav { padding: 4px 8px; display: flex; flex-direction: column; gap: 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: var(--r-sm); cursor: pointer; color: var(--text-2);
  font-weight: 500; font-size: 13px; position: relative;
  transition: color var(--t-med) var(--ease-out), background var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out);
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { color: var(--text); background: var(--bg-2); transform: translateX(2px); }
.nav-item:active { transform: translateX(0); }
.nav-item.active { color: var(--text); background: transparent; }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 2px; background: var(--accent);
  transform-origin: center;
  animation: navMark 180ms var(--ease-out);
}
@keyframes navMark {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}
.nav-item .count {
  margin-left: auto; background: transparent; color: var(--text-3);
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  padding: 0; min-width: auto; text-align: right;
}
.nav-item.active .count { color: var(--accent); background: transparent; }

.sb-divider { height: 1px; background: var(--border); margin: 8px 12px; }

.sb-models { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding: 0 8px; min-height: 0; }
.sb-search { margin-bottom: 6px; position: relative; }
.sb-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; color: var(--text-3); pointer-events: none;
}
.sb-search .input { padding: 8px 10px 8px 32px; font-size: 12.5px; background-color: var(--bg-2); }
.sb-search .input:focus { background-color: var(--bg); }
.sb-avatar.has-img { padding: 0; overflow: hidden; background: var(--bg-3); }
.sb-avatar.has-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sb-model-list { flex: 1; overflow-y: auto; padding-bottom: 10px; display: flex; flex-direction: column; gap: 0; min-height: 0; }
.sb-group-label {
  font-family: var(--font-mono);
  font-size: 9px; font-weight: 500; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--text-3); padding: 12px 6px 6px;
}

.model-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  border-radius: var(--r-sm); cursor: pointer; border: 1px solid transparent;
  position: relative;
  transition: background var(--t-med) var(--ease-out), border-color var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out);
}
.model-row::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; background: var(--accent); border-radius: var(--r-full);
  transform: scaleY(0); transform-origin: center;
  transition: transform var(--t-med) var(--ease-out);
}
.model-row:hover  { background: var(--bg-2); transform: translateX(2px); }
.model-row:active { transform: translateX(0); }
.model-row.active { background: var(--bg-2); border-color: var(--border); }
.model-row.active::before { transform: scaleY(1); }
.model-row .mr-icon {
  width: 28px; height: 28px; border-radius: var(--r-xs); background: var(--bg-3);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--text-2);
  transition: background 180ms var(--ease-out), color 180ms var(--ease-out);
}
.model-row.active .mr-icon { background: var(--accent); color: var(--accent-text); }
.model-row .mr-icon svg { width: 14px; height: 14px; }
.model-row .mr-body { flex: 1; min-width: 0; }
.model-row .mr-name { font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.model-row .mr-sub  { font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.sb-footer { padding: 8px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.sb-user {
  display: flex; align-items: center; gap: 8px; flex: 1; padding: 6px;
  border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--t-med) var(--ease-out); min-width: 0;
}
.sb-user:hover { background: var(--bg-2); }
.sb-avatar {
  width: 28px; height: 28px; border-radius: var(--r-full); background: var(--bg-3); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 500; font-size: 10px; flex-shrink: 0;
  border: 1px solid var(--border);
}
.sb-user-name { font-size: 12.5px; font-weight: 500; }

.main { overflow: hidden; display: flex; flex-direction: column; position: relative; min-width: 0; background: var(--bg); }
.view { flex: 1; overflow-y: auto; display: none; flex-direction: column; min-width: 0; min-height: 0; }
.view.active { display: flex; }
#view-generate.active { overflow: hidden; }

.view-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 20px 28px 16px; flex-wrap: wrap; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.view-head .vh-title { font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: -0.04em; line-height: 1.1; }
.view-head .vh-sub   { color: var(--text-2); font-size: 12.5px; margin-top: 4px; }
.view-head .vh-actions { display: flex; gap: 8px; align-items: center; }

.gen-layout {
  display: grid;
  grid-template-columns: minmax(340px, 400px) 1fr;
  flex: 1; overflow: hidden; min-height: 0; min-width: 0;
}
.gen-form-col {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border-right: 1px solid var(--border); background: var(--bg-1);
}
.gen-form {
  flex: 1; overflow-y: auto; overflow-x: visible; padding: 8px 24px 16px; min-width: 0;
}
.gen-form .dropdown.open { z-index: 30; }
.gen-stage-col {
  background: var(--bg-1);
  display: flex; flex-direction: column; overflow: hidden; min-width: 0; min-height: 0;
}

.gen-model-header {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px;
  align-items: center;
  padding: 22px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.gmh-desc {
  grid-column: 1 / -1; font-size: 12px; color: var(--text-3); line-height: 1.45; max-width: 36em;
}
.gmh-icon {
  width: 28px; height: 28px; border-radius: var(--r-xs); background: var(--bg-3);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  border: 1px solid var(--border);
}
.gmh-icon svg { color: var(--text-2); width: 14px; height: 14px; }
.gmh-body { flex: 1; min-width: 0; }
.gmh-name { font-family: var(--font-display); font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; letter-spacing: -0.03em; }
.gmh-provider { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin-top: 3px; }

.gen-section {
  display: flex; flex-direction: column; gap: 12px;
  padding: 22px 0; border-bottom: 1px solid var(--border);
}
.gen-section:last-child { border-bottom: none; }
.gs-head { position: relative; min-width: 0; }
.gs-title { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; margin-bottom: 6px; }
.gs-req {
  font-family: var(--font-mono); font-size: 9px; font-weight: 500; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent);
  padding: 1px 5px; border-radius: var(--r-xs);
}
.gs-desc { font-size: 12px; color: var(--text-3); line-height: 1.5; max-width: 36em; }
.gs-body { display: flex; flex-direction: column; gap: 10px; align-items: stretch; min-width: 0; }
.gs-body textarea, .gs-body .dropdown, .gs-body .input { width: 100%; }

.stage {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 22px 22px 12px; position: relative; overflow: hidden; min-height: 0;
  background: var(--bg-1);
}
.stage::before { display: none; }
.stage-frame { display: none; }
#stageContent {
  position: relative; z-index: 1;
  width: calc(100% - 28px); height: calc(100% - 28px);
  display: flex; align-items: center; justify-content: center;
  background: var(--mat-void);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stage-idle {
  text-align: center; color: var(--on-void); position: relative;
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 8%;
}
.stage-idle .si-orb { display: none; }
.si-aperture, .auth-aperture {
  position: absolute; inset: 7%;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  pointer-events: none;
}
.si-aperture i, .auth-aperture i {
  position: absolute; width: 28px; height: 28px;
  border-color: var(--accent); border-style: solid;
}
.si-aperture i:nth-child(1), .auth-aperture i:nth-child(1) { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.si-aperture i:nth-child(2), .auth-aperture i:nth-child(2) { top: -1px; right: -1px; border-width: 1px 1px 0 0; }
.si-aperture i:nth-child(3), .auth-aperture i:nth-child(3) { bottom: -1px; left: -1px; border-width: 0 0 1px 1px; }
.si-aperture i:nth-child(4), .auth-aperture i:nth-child(4) { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
.stage-idle .si-aperture {
  animation: apertureBreathe 4.2s var(--ease-smooth) infinite;
}
.auth-aperture {
  inset: 10%;
  animation: apertureBreathe 5.2s var(--ease-smooth) infinite;
}
.stage-idle .si-title {
  font-family: var(--font-display); font-size: clamp(32px, 4.2vw, 52px); font-weight: 600;
  letter-spacing: -0.04em; color: var(--on-void); line-height: 1.05;
  animation: idleInk 3.6s var(--ease-smooth) infinite;
}
.stage-idle .si-sub {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--text-3);
  display: inline-flex; align-items: center; gap: 10px;
}
.stage-idle .si-sub::before {
  content: ''; width: 10px; height: 10px; border-radius: var(--r-xs); background: var(--accent);
  animation: cordPulse 1.6s var(--ease-smooth) infinite;
}
@keyframes apertureBreathe {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.018); }
}
@keyframes idleInk {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}
@keyframes cordPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .stage-idle .si-aperture, .auth-aperture, .stage-idle .si-title, .stage-idle .si-sub::before {
    animation: none;
  }
}

.stage-img-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  width: 100%; height: 100%; position: relative; padding: 12px;
}
.stage-img-wrap .stage-single-img {
  max-width: 100%; max-height: 100%; border-radius: var(--r-xs);
  box-shadow: none; cursor: zoom-in; object-fit: contain;
}
.stage-multi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 2px; width: 100%; padding: 12px; }
.stage-multi-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r-xs); cursor: zoom-in; }
.stage-meta {
  font-family: var(--font-mono); display: flex; align-items: center; gap: 8px;
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3);
  position: absolute; left: 14px; bottom: 12px;
  background: var(--bg-1); color: var(--text); padding: 3px 8px;
}
.stage-close-btn {
  position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: var(--r-xs);
  background: var(--bg-1); border: 1px solid var(--border); color: var(--text-2);
  display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10;
  transition: background var(--t-fast), color var(--t-fast);
}
.stage-close-btn:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.stage-close-btn svg { width: 12px; height: 12px; }

.stage-strip { border-top: 1px solid var(--border); padding: 10px 14px; flex-shrink: 0; background: var(--bg-1); }
.stage-strip-title {
  font-family: var(--font-mono); font-size: 9px; font-weight: 500;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px;
}
.stage-strip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.strip-card {
  aspect-ratio: 1; border-radius: var(--r-sm); overflow: hidden; cursor: pointer;
  border: 1px solid var(--border); position: relative;
  transition: border-color var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out);
}
.strip-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.strip-card:active { transform: translateY(0); }
.strip-card img { width: 100%; height: 100%; object-fit: cover; }
.strip-card .sc-stat { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: var(--mat-void); color: var(--on-void); }

.gen-bar { border-top: 1px solid var(--border); padding: 12px 14px; background: var(--bg-1); flex-shrink: 0; }
.gen-btn {
  width: 100%; padding: 14px 18px; border-radius: var(--r-md);
  background: var(--accent); border: none; color: var(--accent-text);
  font-weight: 600; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
  position: relative;
  transition: background var(--t-med) var(--ease-out), box-shadow var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out);
}
.gen-btn:hover  { background: var(--accent-2); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.gen-btn:active { transform: translateY(0); box-shadow: none; }
.gen-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.job-chip {
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); background: transparent; border: 1px solid var(--border);
  border-radius: var(--r-xs); padding: 5px 8px; margin-bottom: 8px; text-align: center;
}
.stage-job-cancel {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 4; padding: 7px 12px; border-radius: var(--r-xs);
  background: var(--bg-1); color: var(--danger); border: 1px solid var(--border);
  font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer;
}
.stage-job-cancel:hover { background: var(--danger-soft); }
.strip-card.is-job { border-color: var(--accent); }
.strip-job-badge {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-family: var(--font-mono); font-size: 8px; font-weight: 500;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent-text); background: var(--accent); border-radius: var(--r-xs); padding: 3px 3px; text-align: center;
}
.gen-btn .rec {
  width: 8px; height: 8px; border-radius: var(--r-xs); background: currentColor; opacity: 0.9; flex-shrink: 0;
}
.gen-btn .kbd { font-family: var(--font-mono); font-size: 10px; opacity: 0.45; margin-left: auto; text-transform: none; letter-spacing: 0; }

.grid-wrap { padding: 0 28px 40px; flex: 1; overflow-y: auto; }
.lib-grouped { }

.settings-wrap { padding: 20px 28px 56px; max-width: 980px; width: 100%; }
.settings-wrap:has(.admin-inspect),
.settings-wrap:has(.admin-user-row) { max-width: 960px; }

.mobile-bar { display: none; }
.sb-overlay { display: none; }

@media (max-width: 1200px) {
  .gen-layout { grid-template-columns: minmax(320px, 360px) 1fr; }
}
@media (max-width: 1100px) {
  .gen-layout { grid-template-columns: minmax(300px, 340px) 1fr; }
}

@media (max-width: 900px) {
  .app.active { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    width: 240px; transform: translateX(-100%);
    box-shadow: none; border-right: 1px solid var(--border);
    transition: transform var(--t-med) var(--ease-out);
  }
  .sidebar.open { transform: translateX(0); }

  .sb-overlay {
    display: block; position: fixed; inset: 0; z-index: 90;
    background: rgba(28,25,20,0.55);
    opacity: 0; pointer-events: none; transition: opacity var(--t-med);
  }
  .sb-overlay.show { opacity: 1; pointer-events: auto; }

  .mobile-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    background: var(--bg-1); flex-shrink: 0;
  }
  .mb-title { font-family: var(--font-display); font-size: 16px; font-weight: 600; flex: 1; }

  .gen-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .gen-form-col { border-right: none; }
  .gen-stage-col { border-left: none; border-top: 1px solid var(--border); max-height: 48vh; }
  .gen-form { padding: 0 14px 16px; }

  .view-head { padding: 16px 14px 12px; }
  .grid-wrap  { padding: 0 14px 40px; }
  .settings-wrap { padding: 16px 14px 48px; }
  .gen-section { gap: 10px; padding: 18px 0; }
}
