/* ============================================
   ForPost Image Editor — styles
   Layout: top bar + canvas + bottom toolbar
   Palette: dark navy + muted orange accent
   ============================================ */

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

/* ВАЖНО: [hidden] должен всегда побеждать display из CSS */
[hidden] {
  display: none !important;
}

:root {
  /* Палитра, восстановленная из скриншота ForPost */
  --bg-deep:        #050e22;
  --bg-toolbar:     #12284d;
  --bg-bar:         #1a3d63;
  --bg-btn:         #1a3d65;
  --bg-btn-hover:   #234a7a;
  --bg-input:       #0d1f3a;
  --bg-input-focus: #143055;
  --border:         #2a5285;
  --border-light:   #3a6298;
  --text:           #d5e3fd;
  --text-dim:       #8aa5cf;
  --text-muted:     #5d7eb0;
  --accent:         #cf755b;
  --accent-hover:   #d98a72;
  --accent-dim:     rgba(207, 117, 91, 0.15);
  --warn:           #b86b6b;
  --warn-hover:     #d08080;
}

html, body {
  height: 100%;
  background: #02060f;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.app {
  display: grid;
  grid-template-rows: 44px 1fr auto;
  height: min(860px, calc(100vh - 48px));
  width: min(1400px, calc(100vw - 48px));
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.7), 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* ============= BIG UPLOAD BUTTON (в шапке) ============= */
.btn.btn-upload-big {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 22px;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff !important;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  white-space: nowrap;
  user-select: none;
  min-height: 32px;
  box-shadow: 0 2px 8px rgba(207, 117, 91, 0.4);
}

.btn.btn-upload-big:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.btn-upload-big:active {
  transform: translateY(1px);
}

/* ============= GREEN PRESET BUTTON (800×450) ============= */
.btn.btn-preset-green {
  background: #76C457;
  border: 1px solid #76C457;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 5px 12px;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px rgba(118, 196, 87, 0.35);
}

.btn.btn-preset-green:hover:not(:disabled) {
  background: #88d165;
  border-color: #88d165;
}

.btn.btn-preset-green:disabled {
  background: #2a3a26;
  border-color: #2a3a26;
  color: #6a7a66;
  box-shadow: none;
  opacity: 0.6;
}

/* ============= TOP BAR ============= */
.topbar {
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: var(--bg-bar);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

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

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.brand-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 3px;
  display: block;
  object-fit: contain;
  /* фон не нужен — favicon уже имеет свой тёмно-синий фон */
}

.brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.4px;
  color: var(--text);
}

.topbar-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
}

#originalSize {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.topbar-info .sep {
  color: var(--text-muted);
}

.need-label {
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* ============= TOAST ============= */
.toast {
  position: fixed;
  bottom: 80px;
  right: 24px;
  background: var(--bg-bar);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  max-width: 320px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ============= INFO STRIP UNDER IMAGE ============= */
.info-strip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-bar);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.info-strip #originalSize {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.info-strip .sep {
  color: var(--text-muted);
}

.info-strip .need-label {
  color: var(--accent);
}

/* ============= CANVAS AREA ============= */
.canvas-area {
  background: var(--bg-deep);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 0 16px;
  position: relative;
  min-height: 0;
}

.canvas-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  overflow: auto;
  width: 100%;
}

.canvas-holder {
  position: relative;
  display: inline-block;
  line-height: 0;
}

/* ============= WATERMARK OVERLAY ============= */
.wm-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.wm-overlay img {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  max-height: none;
  pointer-events: none;
  user-select: none;
}

#canvas {
  display: block;
  background: #fff;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  cursor: grab;
}

#canvas:active {
  cursor: grabbing;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 80px 120px;
  border: 2px dashed var(--border-light);
  border-radius: 6px;
  color: var(--text-dim);
  text-align: center;
}

.empty-icon {
  font-size: 36px;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 14px;
}

.empty-hint {
  font-size: 12px !important;
  color: var(--text-muted);
}

.canvas-wrap.dragover .empty-state {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============= BOTTOM TOOLBAR ============= */
.toolbar {
  display: flex;
  align-items: stretch;
  background: var(--bg-toolbar);
  border-top: 1px solid var(--border);
  padding: 6px 8px;
  gap: 4px;
  overflow-x: auto;
}

.toolbar::-webkit-scrollbar {
  height: 6px;
}
.toolbar::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.tb-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.tb-block:last-child {
  border-right: none;
  flex: 1 1 auto;
}

.tb-block-grow {
  flex: 1.2 1 0;
  min-width: 220px;
}

.tb-block-save {
  flex: 2 1 0;
  min-width: 280px;
}

.tb-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 0;
}

.tb-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* ============= BUTTONS ============= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  background: var(--bg-btn);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
  user-select: none;
  min-height: 26px;
}

.btn:hover:not(:disabled) {
  background: var(--bg-btn-hover);
  border-color: var(--border-light);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-upload {
  background: var(--bg-btn);
  border-color: var(--border-light);
  color: var(--text);
  font-weight: 600;
}

.btn-upload:hover:not(:disabled) {
  background: var(--bg-btn-hover);
}

/* (устаревшее правило — оставлено как no-op для совместимости) */

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-warn {
  background: transparent;
  border-color: var(--warn);
  color: var(--warn);
}

.btn-warn:hover:not(:disabled) {
  background: var(--warn);
  color: #fff;
}

.btn-download {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 6px 22px;
  font-size: 13px;
  letter-spacing: 0.4px;
  margin-left: auto;
  box-shadow: 0 2px 8px rgba(207, 117, 91, 0.4);
}

.btn-download:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ============= FIELDS ============= */
.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 58px;
}

.field label {
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  font-weight: 600;
  text-transform: uppercase;
}

.field input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 3px;
  font-size: 11px;
  width: 100%;
  font-family: inherit;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input-focus);
}

.check {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.check input {
  cursor: pointer;
  accent-color: var(--accent);
}

/* ============= SELECT ============= */
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  min-height: 26px;
}

select:focus {
  outline: none;
  border-color: var(--accent);
}

.sel-small {
  width: auto;
  min-width: 64px;
}

select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============= QUALITY SLIDER ============= */
.quality-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 5px;
  height: 26px;
}

.q-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

.quality-wrap input[type="range"] {
  width: 50px;
  accent-color: var(--accent);
}

.q-value {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  min-width: 20px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============= FILENAME INPUT ============= */
.filename-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-family: inherit;
  width: 220px;
  min-height: 26px;
}

.filename-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input-focus);
}

.filename-input::placeholder {
  color: var(--text-muted);
}

/* ============= WM SELECTOR ============= */
.wm-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
  height: 26px;
  font-size: 11px;
}

.wm-label {
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-right: 2px;
}

.wm-radio {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  user-select: none;
  color: var(--text-dim);
  padding: 0 2px;
}

.wm-radio input {
  cursor: pointer;
  accent-color: var(--accent);
  margin: 0;
}

.wm-radio:has(input:checked) {
  color: var(--accent);
  font-weight: 600;
}

/* ============= CROP OVERLAY ============= */
.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-frame {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  cursor: move;
  pointer-events: auto;
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 2px;
}

.crop-handle-tl { top: -8px; left: -8px; cursor: nwse-resize; }
.crop-handle-tr { top: -8px; right: -8px; cursor: nesw-resize; }
.crop-handle-bl { bottom: -8px; left: -8px; cursor: nesw-resize; }
.crop-handle-br { bottom: -8px; right: -8px; cursor: nwse-resize; }

/* ============= RESPONSIVE ============= */
@media (max-width: 1100px) {
  .tb-block-save {
    min-width: 320px;
  }
  .filename-input {
    width: 140px;
  }
}

@media (max-width: 900px) {
  .toolbar {
    flex-wrap: wrap;
  }
  .tb-block {
    flex: 1 1 45%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
  }
  .topbar-info {
    font-size: 11px;
  }
  .need-label {
    display: none;
  }
}
