/* ============================================================
   TagsRus Tag Designer — Main Editor Stylesheet
   ============================================================
   Layout: Top Bar | Left Tools | Center Canvas | Right Props | Bottom Bar
   Theme: Clean white, Apple-inspired
   ============================================================ */

/* ---------------------------------------------------------
   1. CSS CUSTOM PROPERTIES
   --------------------------------------------------------- */
:root {
  /* Backgrounds */
  --bg-app: #f5f5f7;
  --bg-panel: #ffffff;
  --bg-panel-hover: #f0f0f2;
  --bg-input: #f5f5f7;
  --bg-canvas: #e8e8ed;

  /* Borders */
  --border: #d2d2d7;
  --border-focus: #0071e3;

  /* Text */
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-dim: #86868b;

  /* Accent & semantic */
  --accent: #0071e3;
  --accent-hover: #0077ED;
  --accent-dim: rgba(0, 113, 227, 0.08);
  --danger: #ff3b30;
  --success: #34c759;
  --info: #007aff;

  /* Canvas zone indicators */
  --bleed: #ff3b30;
  --safe: #007aff;
  --trim: #1d1d1f;

  /* Spacing scale */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 12px;
  --sp-lg: 16px;
  --sp-xl: 24px;

  /* Sizing */
  --topbar-h: 48px;
  --bottombar-h: 36px;
  --left-panel-w: 240px;
  --right-panel-w: 280px;

  /* Transitions */
  --tr-fast: 0.15s ease;
  --tr-med: 0.25s cubic-bezier(0.66, 0, 0.1, 1);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}


/* ---------------------------------------------------------
   2. FONTS
   --------------------------------------------------------- */
@font-face {
  font-family: 'Baloo 2';
  src: url('../fonts/Baloo2-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Baloo 2';
  src: url('../fonts/Baloo2-Bold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Baloo 2';
  src: url('../fonts/Baloo2-ExtraBold.ttf') format('truetype');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}


/* ---------------------------------------------------------
   3. RESET & BASE
   --------------------------------------------------------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Baloo 2', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; }


/* ---------------------------------------------------------
   4. CUSTOM SCROLLBARS
   --------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}


/* ---------------------------------------------------------
   5. MAIN GRID LAYOUT
   --------------------------------------------------------- */
.editor-app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--bottombar-h);
  grid-template-columns: var(--left-panel-w) 1fr var(--right-panel-w);
  grid-template-areas:
    "topbar   topbar   topbar"
    "tools    canvas   properties"
    "statusbar statusbar statusbar";
  height: 100vh;
  width: 100vw;
}


/* ---------------------------------------------------------
   6. TOP BAR
   --------------------------------------------------------- */
.editor-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: 0 var(--sp-lg);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.topbar-logo {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  margin-right: var(--sp-sm);
}

.topbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.topbar-group {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.topbar-group label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.topbar-spacer { flex: 1; }


/* ---------------------------------------------------------
   7. SHARED FORM CONTROLS
   --------------------------------------------------------- */

/* Buttons */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--tr-fast), color var(--tr-fast);
}

.btn-icon:hover {
  background: var(--bg-panel-hover);
  color: var(--text-primary);
}

.btn-icon:active { transform: scale(0.95); }
.btn-icon:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.btn-accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-xs);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--tr-fast), transform 0.1s;
  white-space: nowrap;
}

.btn-accent:hover { background: var(--accent-hover); }
.btn-accent:active { transform: scale(0.97); }
.btn-accent:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* Inputs */
.prop-input {
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast);
}

.prop-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.prop-input::placeholder { color: var(--text-dim); }

/* Select */
select {
  padding: 5px 24px 5px 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386868b' d='M2 4l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 6px center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  transition: border-color var(--tr-fast);
}

select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.prop-select {
  width: 100%;
  padding: 6px 28px 6px 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386868b' d='M2 4l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 8px center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  transition: border-color var(--tr-fast);
}

.prop-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* Color swatch input */
.color-swatch {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
  background: none;
  overflow: hidden;
}

.color-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch::-webkit-color-swatch { border: none; border-radius: 2px; }

/* Color field container */
.color-field {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.color-field .prop-input { flex: 1; }

/* Sliders */
input[type="range"] {
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--tr-fast);
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

.prop-range { flex: 1; }


/* ---------------------------------------------------------
   8. LEFT TOOL PANEL
   --------------------------------------------------------- */
.editor-tools {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.tool-section { padding: var(--sp-sm) 0; }

.tool-section-header {
  padding: var(--sp-sm) var(--sp-lg) var(--sp-xs);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 7px var(--sp-lg);
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: color var(--tr-fast), background var(--tr-fast), border-color var(--tr-fast);
  white-space: nowrap;
}

.tool-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-size: 15px;
  opacity: 0.6;
  transition: opacity var(--tr-fast);
}

.tool-label { font-size: 13px; }

.tool-btn:hover {
  color: var(--text-primary);
  background: var(--bg-panel-hover);
}

.tool-btn:hover .tool-icon { opacity: 1; }

.tool-btn.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}

.tool-btn.active .tool-icon { opacity: 1; }

/* Templates mini grid */
.templates-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-xs);
  padding: 0 var(--sp-md);
}

/* Layers */
.layer-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-sm);
}


/* ---------------------------------------------------------
   9. CENTER CANVAS AREA
   --------------------------------------------------------- */
.editor-canvas-area {
  grid-area: canvas;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas);
  overflow: hidden;
  position: relative;
  cursor: grab;
}

.editor-canvas-area:active { cursor: grabbing; }

.canvas-ruler-corner {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  z-index: 12;
}

.canvas-ruler-h,
.canvas-ruler-v {
  position: absolute;
  background: var(--bg-panel);
  z-index: 10;
  pointer-events: none;
}

.canvas-ruler-h {
  top: 0;
  left: 20px;
  right: 0;
  height: 20px;
  border-bottom: 1px solid var(--border);
}

.canvas-ruler-v {
  top: 20px;
  left: 0;
  bottom: 0;
  width: 20px;
  border-right: 1px solid var(--border);
}

/* Canvas container within the area */
.canvas-container {
  position: relative;
  box-shadow:
    0 2px 20px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  border-radius: 2px;
}


/* ---------------------------------------------------------
   10. RIGHT PROPERTIES PANEL
   --------------------------------------------------------- */
.editor-properties {
  grid-area: properties;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

/* Collapsible section */
.properties-section {
  border-bottom: 1px solid var(--border);
}

.properties-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-md) var(--sp-lg);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: color var(--tr-fast);
}

.properties-section-header:hover { color: var(--text-primary); }

.section-toggle {
  font-size: 10px;
  transition: transform var(--tr-med);
}

.properties-section.collapsed .section-toggle {
  transform: rotate(-90deg);
}

.properties-section-body {
  padding: 0 var(--sp-lg) var(--sp-md);
}

.properties-section.collapsed .properties-section-body {
  display: none;
}

/* Property grid (2-col for X/Y/W/H) */
.prop-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: var(--sp-sm);
  align-items: center;
}

.prop-grid label {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
}

.prop-grid .prop-input {
  width: 100%;
}

/* Property row (label + value) */
.prop-row {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-sm);
}

.prop-row label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 52px;
  text-align: right;
  flex-shrink: 0;
}

/* Color presets */
.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: var(--sp-sm);
}

/* Text alignment group */
.text-align-group {
  display: flex;
  gap: 2px;
}

.text-align-group .btn-icon {
  flex: 1;
  font-size: 12px;
}

/* Layer order buttons */
.layer-order-buttons {
  display: flex;
  gap: var(--sp-xs);
}

.layer-order-buttons .btn-icon { flex: 1; }


/* ---------------------------------------------------------
   11. AI CHAT PANEL
   --------------------------------------------------------- */
.editor-ai-chat {
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-chat-body {
  display: flex;
  flex-direction: column;
  max-height: 260px;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  padding-bottom: var(--sp-sm);
  min-height: 60px;
  max-height: 200px;
}

.ai-message {
  max-width: 90%;
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.5;
}

.ai-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
}

.ai-message.ai {
  align-self: flex-start;
  background: var(--bg-input);
  color: var(--text-secondary);
}

.ai-chat-input-row {
  display: flex;
  gap: var(--sp-xs);
  padding-top: var(--sp-sm);
  border-top: 1px solid var(--border);
}

.ai-chat-input-row .prop-input { flex: 1; }

/* AI suggestion chips */
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--sp-sm);
}

.ai-suggestion-chip {
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(0, 113, 227, 0.15);
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--tr-fast);
}

.ai-suggestion-chip:hover {
  background: rgba(0, 113, 227, 0.15);
}


/* ---------------------------------------------------------
   12. BOTTOM STATUS BAR
   --------------------------------------------------------- */
.editor-statusbar {
  grid-area: statusbar;
  display: flex;
  align-items: center;
  gap: var(--sp-lg);
  padding: 0 var(--sp-lg);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  z-index: 100;
}

.status-info {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
}

.status-separator {
  color: var(--border);
}

/* Toggle pill buttons */
.status-toggles {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.status-toggle {
  padding: 3px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--tr-fast), background var(--tr-fast);
}

.status-toggle:hover { color: var(--text-secondary); background: var(--bg-panel-hover); }

.status-toggle.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: rgba(0, 113, 227, 0.15);
}

/* Export dropdown */
.export-dropdown { position: relative; }

.export-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  padding: var(--sp-xs) 0;
  display: none;
  z-index: 200;
}

.export-menu.show { display: block; }

.export-menu button {
  display: block;
  width: 100%;
  padding: 8px var(--sp-lg);
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background var(--tr-fast);
}

.export-menu button:hover { background: var(--bg-panel-hover); }

.export-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-xs) 0;
}

.status-export { margin-left: var(--sp-sm); }


/* ---------------------------------------------------------
   13. TOOLTIPS
   --------------------------------------------------------- */
[title] { position: relative; }


/* ---------------------------------------------------------
   14. UTILITY CLASSES
   --------------------------------------------------------- */
.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-dim { color: var(--text-dim); }


/* ---------------------------------------------------------
   15. ANIMATIONS & LOADING STATES
   --------------------------------------------------------- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.loading-pulse { animation: pulse 1.5s ease-in-out infinite; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s cubic-bezier(0.66, 0, 0.1, 1) forwards; }

/* Panel transitions */
.editor-tools,
.editor-properties {
  transition: width var(--tr-med), margin var(--tr-med), opacity var(--tr-med);
}


/* ---------------------------------------------------------
   16. MOBILE MENU
   --------------------------------------------------------- */
.mobile-menu-toggle {
  display: none;
  width: 36px;
  height: 36px;
  font-size: 18px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
}


/* ---------------------------------------------------------
   17. RESPONSIVE: TABLET (< 1024px)
   --------------------------------------------------------- */
@media (max-width: 1023px) {
  .editor-app {
    grid-template-columns: var(--left-panel-w) 1fr;
    grid-template-areas:
      "topbar   topbar"
      "tools    canvas"
      "statusbar statusbar";
  }

  .editor-properties {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: var(--bottombar-h);
    width: var(--right-panel-w);
    z-index: 150;
    transform: translateX(100%);
    transition: transform var(--tr-med);
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.08);
  }

  .editor-properties.mobile-visible { transform: translateX(0); }
}


/* ---------------------------------------------------------
   18. RESPONSIVE: MOBILE (< 768px)
   --------------------------------------------------------- */
@media (max-width: 767px) {
  .mobile-menu-toggle { display: flex; align-items: center; justify-content: center; }

  .editor-app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "canvas"
      "statusbar";
  }

  .editor-tools {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: var(--bottombar-h);
    width: var(--left-panel-w);
    z-index: 150;
    transform: translateX(-100%);
    transition: transform var(--tr-med);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.08);
  }

  .editor-tools.mobile-visible { transform: translateX(0); }

  .editor-properties {
    width: 100%;
    max-width: 320px;
  }

  .editor-topbar { gap: var(--sp-sm); padding: 0 var(--sp-sm); }

  /* Touch targets */
  .btn-icon, .tool-btn, .status-toggle { min-height: 44px; }
  .tool-btn { padding: 12px var(--sp-lg); }
}

@media (min-width: 768px) {
  .mobile-menu-toggle { display: none; }
}


/* ---------------------------------------------------------
   19. PRINT
   --------------------------------------------------------- */
@media print {
  .editor-topbar,
  .editor-tools,
  .editor-properties,
  .editor-statusbar { display: none !important; }

  .editor-app {
    display: block;
    height: auto;
    overflow: visible;
  }

  .editor-canvas-area {
    background: #fff;
    overflow: visible;
  }
}

/* ---------------------------------------------------------
   20. REDUCED MOTION
   --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
