:root {
  --black: #050505;
  --panel: #0b0b0b;
  --raised: #121212;
  --white: #f5f5f2;
  --muted: #8b8b86;
  --line: #292929;
  --line-strong: #4a4a47;
  --danger: #ff6b6b;
  --radius: 18px;
  --radius-sm: 10px;
  --ease: 180ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }

body {
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 80% -10%, rgba(255, 255, 255, 0.08), transparent 28rem),
    var(--black);
  color: var(--white);
  font-family: "Geo", sans-serif;
  font-size: 18px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 clamp(18px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.88);
  backdrop-filter: blur(18px);
}

.brand {
  color: var(--white);
  font-size: 24px;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.brand span { color: var(--muted); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.12em;
}

.status-badge::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.status-badge.ok { color: var(--white); }
.status-badge.err { color: var(--danger); }

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 450px) minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.control-panel {
  padding: clamp(28px, 4vw, 52px);
  border-right: 1px solid var(--line);
  background: rgba(8, 8, 8, 0.65);
}

.panel-heading { margin-bottom: 34px; }
.eyebrow { margin-bottom: 7px; color: var(--muted); font-size: 14px; letter-spacing: 0.18em; }
h1 { max-width: 320px; font-size: clamp(38px, 4.2vw, 60px); font-weight: 400; line-height: 0.95; letter-spacing: -0.035em; }
h2 { font-size: clamp(28px, 3vw, 42px); font-weight: 400; line-height: 1; }

.form-group { min-width: 0; margin-bottom: 20px; }
.form-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--white);
  font-size: 16px;
}
.form-group label span { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; }

.form-row { display: grid; grid-template-columns: 1.5fr 0.65fr; gap: 12px; }
.form-row-three { grid-template-columns: 1fr 0.72fr 1.18fr; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--raised);
  color: var(--white);
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease);
}

input, select { height: 47px; padding: 0 13px; }
textarea { min-height: 120px; padding: 14px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #666662; }
input:focus, select:focus, textarea:focus { border-color: var(--white); box-shadow: 0 0 0 1px var(--white); }
input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }

select {
  appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--white) 50%),
    linear-gradient(135deg, var(--white) 50%, transparent 50%);
  background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

input[type="range"] {
  height: 47px;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--white);
}

.reference-drop {
  position: relative;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--raised);
  transition: border-color var(--ease), background var(--ease);
}
.reference-drop.is-dragging { border-color: var(--white); background: #181818; }
.upload-trigger {
  width: 100%;
  min-height: 86px;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--white);
  cursor: pointer;
  text-align: left;
}
.upload-title, .upload-note { display: block; }
.upload-note { margin-top: 4px; color: var(--muted); font-size: 14px; }
.reference-preview { display: grid; grid-template-columns: 72px 1fr; gap: 12px; padding: 9px; }
.reference-preview img { width: 72px; height: 72px; border-radius: 7px; object-fit: cover; }
.reference-details { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; justify-content: center; }
.reference-details span { overflow: hidden; width: 100%; color: var(--muted); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.reference-details button { margin-top: 5px; border: 0; background: transparent; color: var(--white); cursor: pointer; text-decoration: underline; }
.reference-url-row { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 8px; margin-top: 8px; }
.reference-url-row > span { color: var(--muted); font-size: 12px; text-align: center; }
.reference-url-row input { height: 40px; font-size: 15px; }

.primary-button, .secondary-button, .text-button {
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform var(--ease), background var(--ease), color var(--ease), opacity var(--ease);
}
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  background: var(--white);
  color: var(--black);
  text-decoration: none;
}
.primary-button:hover:not(:disabled) { transform: translateY(-2px); background: #fff; }
.primary-button:disabled { cursor: not-allowed; opacity: 0.48; }
.primary-button.compact { width: auto; min-height: 44px; }
.secondary-button { min-height: 44px; padding: 0 18px; border: 1px solid var(--line-strong); background: transparent; color: var(--white); }
.secondary-button:hover { border-color: var(--white); }
.text-button { padding: 9px 0; background: transparent; color: var(--muted); text-decoration: underline; }
.text-button:hover:not(:disabled) { color: var(--white); }
.text-button:disabled { cursor: default; opacity: 0; }
.btn-loader { display: inline-flex; align-items: center; gap: 10px; }
.spinner { width: 15px; height: 15px; border: 1px solid rgba(0,0,0,0.28); border-top-color: var(--black); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-box { margin-top: 12px; border: 1px solid rgba(255,107,107,0.55); border-radius: var(--radius-sm); background: rgba(255,107,107,0.07); color: var(--danger); padding: 12px 14px; font-size: 15px; }

.gallery-panel { min-width: 0; padding: clamp(28px, 4vw, 52px); }
.gallery-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, 200px); align-content: start; justify-content: start; gap: clamp(12px, 2vw, 24px); }
.gallery-item, .shimmer-card { position: relative; overflow: hidden; width: 200px; height: 200px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.gallery-item { cursor: zoom-in; }
.gallery-item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.gallery-item .overlay {
  position: absolute;
  inset: auto 0 0;
  padding: 30px 16px 14px;
  background: linear-gradient(transparent, rgba(0,0,0,0.82));
  color: var(--white);
  opacity: 0;
  transition: opacity var(--ease);
}
.gallery-item:hover .overlay { opacity: 1; }

.shimmer-card::after {
  position: absolute;
  inset: 0;
  transform: translateX(-110%);
  background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,0.13) 48%, transparent 76%);
  animation: shimmer 1.25s infinite;
  content: "";
}
.shimmer-meta { position: absolute; right: 16px; bottom: 14px; left: 16px; height: 8px; border-radius: 99px; background: #222; }
@keyframes shimmer { to { transform: translateX(110%); } }

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  min-height: min(58vh, 600px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
.empty-mark { width: 58px; height: 58px; margin-bottom: 20px; border: 1px solid var(--line-strong); border-radius: 50%; }
.empty-state p { margin-bottom: 4px; color: var(--white); font-size: 24px; }
.empty-state span { max-width: 280px; font-size: 16px; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(0,0,0,0.9); backdrop-filter: blur(12px); cursor: zoom-out; }
.modal-content { position: relative; display: flex; overflow: hidden; max-width: min(1100px, 94vw); max-height: 92vh; flex-direction: column; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--panel); }
.modal-content img { display: block; max-width: 100%; max-height: 76vh; object-fit: contain; }
.modal-close { position: absolute; top: 12px; right: 12px; z-index: 2; min-height: 38px; padding: 0 13px; border: 1px solid rgba(255,255,255,0.35); border-radius: 99px; background: rgba(0,0,0,0.65); color: var(--white); cursor: pointer; }
.modal-actions { display: flex; justify-content: center; gap: 10px; padding: 14px; border-top: 1px solid var(--line); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--black); }
::-webkit-scrollbar-thumb { border: 2px solid var(--black); border-radius: 99px; background: var(--line-strong); }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .gallery-panel { min-height: 70vh; }
}

@media (max-width: 620px) {
  body { font-size: 17px; }
  .header { height: 60px; }
  .brand { font-size: 21px; }
  .status-badge { font-size: 12px; }
  .workspace { min-height: calc(100vh - 60px); }
  .control-panel, .gallery-panel { padding: 26px 18px; }
  .panel-heading { margin-bottom: 28px; }
  .form-row, .form-row-three { grid-template-columns: 1fr 1fr; }
  .form-row-three .form-group:last-child { grid-column: 1 / -1; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, 200px); }
  .empty-state { min-height: 360px; padding: 22px; }
  .modal { padding: 10px; }
  .modal-actions { flex-direction: column; }
  .primary-button.compact, .secondary-button { width: 100%; }
}

@media (max-width: 390px) {
  .form-row, .form-row-three { grid-template-columns: 1fr; }
  .form-row-three .form-group:last-child { grid-column: auto; }
  .gallery-header { align-items: center; }
}

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