/* =============================================================
   Çınar Ölçüm — Modern UI
   ============================================================= */

:root {
  --bg: #f5f7fb;
  --bg-grid: #eef2f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-glass: rgba(255, 255, 255, 0.78);
  --border: #e5e9f2;
  --border-strong: #d4dae8;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --primary: #0ea5a4;
  --primary-600: #0d9488;
  --primary-700: #0f766e;
  --primary-soft: #ccfbf1;

  --accent: #10b981;
  --accent-2: #0891b2;

  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-600: #dc2626;
  --success: #10b981;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 8px 24px -8px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, 0.25), 0 8px 24px -8px rgba(15, 23, 42, 0.12);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  --appbar-h: 64px;
  --statusbar-h: 32px;
  --toolbar-h: 56px;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(14, 165, 164, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(8, 145, 178, 0.06), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; }
input, button, select, textarea { font-family: inherit; }

/* =============================================================
   App bar
   ============================================================= */
.appbar {
  height: var(--appbar-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 50;
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 800;
  font-size: 16px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

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

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

/* =============================================================
   Buttons
   ============================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition), color var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-sm { padding: 6px 10px; font-size: 12px; gap: 6px; }
.btn-lg { padding: 12px 22px; font-size: 14px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent-2) 100%);
  color: white;
  box-shadow: 0 8px 20px -8px rgba(14, 165, 164, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.btn-primary:hover {
  box-shadow: 0 12px 26px -8px rgba(14, 165, 164, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-600); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* =============================================================
   Drop zone
   ============================================================= */
.dropzone-wrap {
  height: calc(100% - var(--appbar-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.dropzone {
  width: 100%;
  max-width: 720px;
  background:
    radial-gradient(600px 200px at 50% 0%, rgba(14, 165, 164, 0.08), transparent 80%),
    var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 56px 32px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition), background var(--transition);
  cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  box-shadow: 0 20px 50px -20px rgba(14, 165, 164, 0.35);
}
.dropzone.dragover {
  background:
    radial-gradient(800px 300px at 50% 0%, rgba(14, 165, 164, 0.18), transparent 80%),
    var(--surface);
  transform: scale(1.01);
}

.dropzone-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.dropzone-illustration {
  margin-bottom: 8px;
  display: grid;
  place-items: center;
}

.dropzone-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.dropzone-subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 13px;
}

.dropzone-features {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  justify-content: center;
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  width: 100%;
}

.feature {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}
.feature-icon {
  width: 18px; height: 18px;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-700);
  font-weight: 700;
  font-size: 11px;
}

/* =============================================================
   Editor layout
   ============================================================= */
.editor {
  display: grid;
  height: calc(100% - var(--appbar-h));
  grid-template-columns: 1fr var(--sidebar-w);
  grid-template-rows: 1fr var(--statusbar-h);
  grid-template-areas:
    "viewport sidebar"
    "status sidebar";
  position: relative;
}

.viewport {
  grid-area: viewport;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--surface);
  cursor: crosshair;
}
.viewport.panning { cursor: grabbing; }
.viewport.tool-select { cursor: grab; }
.viewport.tool-select.over-shape { cursor: move; }

.viewport canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  image-rendering: -webkit-optimize-contrast;
}

#canvasDraw { pointer-events: none; }

.toolbar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 6px 4px;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 20;
  user-select: none;
  cursor: grab;
}
.toolbar:active { cursor: grabbing; }
.toolbar.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lg);
  transition: none;
}
/* Interactive elements get default cursors */
.toolbar button,
.toolbar .zoom-display { cursor: pointer; }
.toolbar .zoom-display { cursor: default; }

.toolbar-grip {
  width: 20px;
  height: 32px;
  display: grid;
  place-items: center;
  margin-right: 2px;
  color: var(--text-soft);
  border-radius: 6px;
  transition: var(--transition);
  pointer-events: none; /* visual only — drag handled on toolbar itself */
}
.toolbar:hover .toolbar-grip { color: var(--text-muted); }

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tool-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.tool {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent-2) 100%);
  color: white;
  box-shadow: 0 6px 16px -6px rgba(14, 165, 164, 0.6);
}
.tool.danger:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.zoom-display {
  min-width: 56px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 6px;
}

.hint {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--text);
  color: white;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 15;
  box-shadow: var(--shadow);
  max-width: 80%;
  text-align: center;
}
.hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =============================================================
   Sidebar
   ============================================================= */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

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

.section-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.badge {
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
.badge-soft {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary-700);
}
.badge.ok {
  background: #dcfce7;
  border-color: transparent;
  color: #166534;
}

.scale-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.scale-info {
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
}
.scale-info.empty { color: var(--text-soft); font-weight: 400; }

.measurements {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  font-size: 12.5px;
  color: var(--text-soft);
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.measurement-item {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.measurement-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.measurement-item.selected {
  border-color: var(--primary);
  background: rgba(14, 165, 164, 0.05);
  box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.12);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

.m-info {
  flex: 1;
  min-width: 0;
}
.m-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-value {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.m-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.measurement-item:hover .m-actions { opacity: 1; }

.totals .total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
}
.totals .total-row.subtle {
  color: var(--text-muted);
  font-size: 12.5px;
}
.total-label { color: var(--text-muted); font-size: 12.5px; font-weight: 500; }
.total-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.totals .total-row.subtle .total-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* =============================================================
   Status bar
   ============================================================= */
.statusbar {
  grid-area: status;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.status-item:not(:last-child)::after {
  content: '';
  width: 1px;
  height: 14px;
  background: var(--border);
  margin-left: 16px;
}

/* =============================================================
   Modals
   ============================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 200ms ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideUp 240ms cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-wide { max-width: 640px; }
@keyframes slideUp {
  from { transform: translateY(20px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 20px 22px;
}
.modal-text {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.55;
}

.modal-footer {
  padding: 14px 22px 18px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.spacer { flex: 1; }

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}
.input-group input,
.modal-body input[type="text"],
.modal-body input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 500;
  border: 1.5px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group input:focus,
.modal-body input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.15);
}
.input-suffix {
  position: absolute;
  right: 14px;
  color: var(--text-muted);
  font-weight: 500;
  pointer-events: none;
}
.input-group input { padding-right: 36px; }

.form-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 14px 0 8px;
}
.form-label:first-child { margin-top: 0; }

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text);
}
.chip:hover { border-color: var(--primary); }
.chip.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent-2) 100%);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px -4px rgba(14, 165, 164, 0.4);
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
  position: relative;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px white inset;
}

.help-list { padding-left: 20px; }
.help-list li { margin-bottom: 8px; color: var(--text); line-height: 1.6; font-size: 13.5px; }
.help-list b { font-weight: 700; }

kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  background: var(--text);
  color: white;
  border-radius: 5px;
  border: 1px solid #000;
  box-shadow: 0 1px 0 #000;
  margin: 0 2px;
}

.shortcuts {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px 12px;
}
.kbd-row {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* =============================================================
   Toasts
   ============================================================= */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 360px;
  animation: toastIn 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.error { border-left-color: var(--danger); }
.toast.leaving { animation: toastOut 200ms forwards; }
@keyframes toastIn {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toastOut {
  to { transform: translateX(40px); opacity: 0; }
}

/* =============================================================
   Loading overlay
   ============================================================= */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 150;
}
.loading > * { grid-column: 1; grid-row: 1; }
.loading-text {
  margin-top: 96px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.loader {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================================
   Responsive
   ============================================================= */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .editor { grid-template-columns: 1fr; grid-template-areas: "viewport" "status"; }
  .dropzone { padding: 36px 20px; }
  .dropzone-title { font-size: 18px; }
  .toolbar { transform: translateX(-50%) scale(0.92); }
}
