/* ============================================
   app.css — Diagrammatic App UI
   Consumes tokens from base.css only.
   ============================================ */

/* ── Chrome ── */
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-3);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  text-decoration: none;
  color: var(--text);
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--teal);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-wordmark { font-size: var(--text-base); font-weight: 600; }

.logo-product {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
}

.header-actions { display: flex; gap: var(--space-1); }

/* ── Tab Bar ── */
.tabs {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
}

.tab {
  padding: 10px var(--space-3);
  min-height: 44px;
  border: none;
  background: none;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover  { color: var(--teal); }
.tab.active { color: var(--teal); border-bottom-color: var(--teal); }

/* ── Layout ── */
.main {
  display: flex;
  height: calc(100vh - 57px - 41px);
  overflow: hidden;
}

.tab-panel        { display: none; }
.tab-panel.active { display: flex; }

/* ── Sidebar ── */
.sidebar {
  width: 320px;
  background: var(--white);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section { border-bottom: 1px solid var(--border); padding: var(--space-2); }
.sidebar-section:last-child { border-bottom: none; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.section-header h3 {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── Layout Grid ── */
.layout-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.layout-btn {
  aspect-ratio: 1.4;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.layout-btn:hover  { border-color: var(--teal); background: var(--teal-light); }
.layout-btn.active { border-color: var(--teal); background: var(--teal-light); box-shadow: 0 0 0 2px rgba(21,96,130,0.2); }
.layout-btn svg    { width: 100%; height: 70%; }
.layout-btn span   { font-size: 8px; color: var(--text-muted); margin-top: 2px; }

/* ── Form Elements ── */
.form-group { margin-bottom: var(--space-2); }
.form-group:last-child { margin-bottom: 0; }

.form-group label,
.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(21,96,130,0.1);
}

.form-group textarea { resize: vertical; min-height: 60px; }

.form-row { display: flex; gap: var(--space-1); }
.form-row .form-group { flex: 1; }

/* ── Toggle ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) 0;
}

.toggle-label { font-size: var(--text-sm); color: var(--text); }
.toggle-label .brand-mark { font-weight: 600; }

.toggle-switch {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 11px;
  right: 2px;
  bottom: 11px;
  left: 2px;
  background: #CBD5E0;
  border-radius: 22px;
  transition: 0.25s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.25s;
}

.toggle-switch input:checked + .toggle-slider { background: var(--teal); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Box Editor ── */
.box-item {
  background: var(--teal-light);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-1);
}
.box-item:last-child { margin-bottom: 0; }

.box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-1);
}

.box-number { font-size: var(--text-xs); font-weight: 600; color: var(--teal); }

.box-delete {
  background: none;
  border: none;
  color: var(--coral);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 4px;
  transition: background 0.15s;
}
.box-delete:hover { background: rgba(224,122,95,0.12); }

/* ── Color Swatches ── */
.color-options { display: flex; gap: 4px; flex-wrap: wrap; }

.color-option {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  appearance: none;
  transition: transform 0.12s;
}
.color-option:hover  { transform: scale(1.15); }
.color-option.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--text); }

/* ── Buttons ── */
.btn {
  padding: 8px var(--space-2);
  min-height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-primary { background: var(--teal); color: var(--white); }
.btn-primary:hover {
  background: var(--teal-mid);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(21,96,130,0.25);
}

.btn-secondary { background: var(--teal-light); color: var(--teal); }
.btn-secondary:hover { background: #d5e9ef; }

.btn-small { padding: 6px var(--space-2); font-size: 12px; }
.btn-block { width: 100%; }

/* ── Canvas ── */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-toolbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 8px var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.canvas-info { font-size: 12px; color: var(--text-muted); }

.preview-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #E8ECEF;
  background-image: radial-gradient(circle, rgba(0,0,0,0.15) 1px, transparent 1px);
  background-size: 20px 20px;
}

.preview-container {
  background: var(--white);
  box-shadow: var(--shadow-lg);
  border-radius: 4px;
  overflow: hidden;
}

#preview-container svg { display: block; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--white);
  padding: 10px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
}
.toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }

#export-canvas { display: none; }

@media (max-width: 640px) {
  .app-header {
    height: auto;
    min-height: 56px;
    align-items: flex-start;
    gap: var(--space-1);
    flex-direction: column;
    padding: var(--space-2);
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .main {
    height: auto;
    min-height: calc(100dvh - 110px);
    flex-direction: column;
    overflow: visible;
  }

  .tab-panel.active,
  .sidebar {
    width: 100%;
  }

  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 16px;
  }
}
