/* Inter — yerel dosyalar, PNG'de Türkçe karakterlerin doğru çıkması için gerekli */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/inter-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --desk: #efebe6;
  --surface: #ffffff;
  --ink: #241c17;
  --muted: #6f655d;
  --faint: #a2978d;
  --line: #e9e2da;
  --line-strong: #d9cfc4;
  --tint: #f4ece3;
  --tint-soft: #faf6f1;
  --accent: #6b4428;
  --accent-hover: #55341d;
  --accent-soft: #f0e4d6;
  --danger: #a8291c;
  --ring: 0 0 0 3px rgba(107, 68, 40, 0.22);
  --topbar-h: 60px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 14px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Üst çubuk ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--topbar-h);
  padding: 0 20px 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

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

.doc-status {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex: 1;
  padding-left: 20px;
  border-left: 1px solid var(--line);
}

.doc-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-state {
  color: var(--faint);
  font-size: 13px;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.count {
  display: inline-block;
  min-width: 20px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--tint);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: 300px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px -16px rgba(36, 28, 23, 0.28);
}

.menu-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.menu-item span {
  display: block;
  font-weight: 600;
}

.menu-item small {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--tint);
  outline: none;
}

/* ---------- Düğmeler ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
}

.btn-secondary:hover {
  border-color: var(--faint);
}

.btn-quiet {
  background: none;
  color: var(--ink);
}

.btn-quiet:hover {
  background: var(--tint);
}

.btn-quiet.danger {
  color: var(--danger);
}

.btn-small {
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  background: var(--tint);
  color: var(--ink);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ---------- Çalışma alanı ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 680px) minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}

.editor {
  padding: 8px 32px 64px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.section {
  padding: 28px 0;
}

.section + .section {
  border-top: 1px solid var(--line);
}

.section h2 {
  margin-bottom: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
}

/* ---------- Alanlar ---------- */

.field {
  margin-bottom: 16px;
}

.field > label,
.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.optional {
  color: var(--faint);
  font-weight: 400;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field {
  min-width: 0;
}

.grow {
  flex: 1;
}

.field.code {
  width: 150px;
  flex-shrink: 0;
}

.input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder {
  color: var(--faint);
}

.input:hover {
  border-color: var(--faint);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.suffix-input {
  position: relative;
}

.suffix-input .input {
  padding-right: 38px;
}

.suffix-input span {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}

.model-row .field:not(.grow) {
  width: 120px;
  flex-shrink: 0;
}

.unit-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.unit-field .input {
  width: 64px;
  height: 34px;
  text-align: center;
}

/* ---------- Çipler ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.chip:hover {
  border-color: var(--faint);
}

.chip[aria-pressed='true'] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.fit-input {
  max-width: 260px;
  margin-top: 8px;
}

.presets {
  margin-bottom: 14px;
}

/* ---------- Ölçü tablosu ---------- */

.grid-scroll {
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.grid th,
.grid td {
  padding: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font-weight: inherit;
}

.grid tbody tr:last-child > * {
  border-bottom: 0;
}

.grid thead th {
  background: var(--tint);
}

.grid .cell {
  display: block;
  width: 100%;
  min-width: 60px;
  height: 44px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.grid .cell:focus {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 2px;
  background: var(--surface);
}

.grid thead .cell {
  font-weight: 600;
}

.grid .label-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
}

.grid thead .label-col {
  background: var(--tint);
}

.grid .label-col .cell {
  min-width: 112px;
  padding: 0 12px;
  text-align: left;
  font-weight: 500;
}

.grid thead .label-col .cell {
  font-weight: 600;
  text-align: center;
}

.col-head {
  position: relative;
}

.col-head .cell {
  padding-right: 18px;
  padding-left: 18px;
}

.col-del {
  position: absolute;
  top: 50%;
  right: 3px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--faint);
  opacity: 0.55;
  transform: translateY(-50%);
  cursor: pointer;
}

.col-head:hover .col-del,
.col-del:focus-visible {
  opacity: 1;
}

.col-del:hover {
  background: rgba(168, 41, 28, 0.08);
  color: var(--danger);
}

.col-del:disabled {
  display: none;
}

.grid .tools-col {
  position: sticky;
  right: 0;
  z-index: 2;
  width: 1%;
  border-right: 0;
  background: var(--surface);
  box-shadow: -1px 0 0 var(--line);
}

.grid thead .tools-col {
  background: var(--tint);
}

.add-col {
  height: 44px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.add-col:hover:not(:disabled) {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.add-col:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.row-tools {
  display: flex;
  justify-content: center;
  padding: 0 3px;
}

.row-tools .icon-btn {
  width: 26px;
  height: 28px;
}

.row-tools [data-act='del-row']:hover:not(:disabled) {
  background: rgba(168, 41, 28, 0.08);
  color: var(--danger);
}

.grid-footer {
  margin-top: 12px;
}

.grid-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

/* Parça (Hırka, İçlik) başlık satırı */
.grid .group-cell {
  background: var(--tint-soft);
}

.group-head {
  display: flex;
  align-items: center;
}

.grid .group-input {
  flex: 1;
  padding: 0 14px;
  text-align: left;
  font-weight: 600;
}

.group-add {
  flex-shrink: 0;
  height: 30px;
  margin-right: 6px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.group-add:hover:not(:disabled) {
  background: var(--accent-soft);
}

.group-add:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.grid .group-row .tools-col {
  background: var(--tint-soft);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

/* ---------- Notlar ---------- */

.notes {
  margin: 4px 0 12px;
  padding: 0;
  list-style: none;
}

.note-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.note-label {
  width: 150px;
  flex-shrink: 0;
  font-weight: 500;
}

.note-text {
  flex: 1;
  min-width: 0;
}

.note-row .icon-btn:hover {
  background: rgba(168, 41, 28, 0.08);
  color: var(--danger);
}

.note-add .label {
  margin-bottom: 8px;
}

/* ---------- Önizleme ---------- */

.preview {
  padding: 40px 40px 64px;
}

.preview-inner {
  position: sticky;
  top: calc(var(--topbar-h) + 40px);
  max-width: 820px;
  margin: 0 auto;
}

.sheet {
  background: #fff;
  border-radius: 3px;
  box-shadow:
    0 1px 2px rgba(36, 28, 23, 0.06),
    0 24px 48px -24px rgba(36, 28, 23, 0.22);
  line-height: 0;
}

.sheet canvas {
  display: block;
  width: 100%;
  height: auto;
}

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
}

.dims {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

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

/* ---------- Tablolarım ---------- */

.drawer {
  width: min(440px, 100vw);
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: -24px 0 48px -24px rgba(36, 28, 23, 0.3);
}

.drawer[open] {
  display: flex;
  flex-direction: column;
}

.drawer::backdrop {
  background: rgba(36, 28, 23, 0.3);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 10px 24px;
}

.drawer-search {
  padding: 0 24px 12px;
}

.lib-list {
  flex: 1;
  margin: 0;
  padding: 0 12px;
  overflow-y: auto;
  list-style: none;
}

.lib-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
}

.lib-item:hover,
.lib-item.is-current {
  background: var(--tint);
}

.lib-open {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.lib-name {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-meta {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
}

.lib-actions {
  display: flex;
  padding-right: 6px;
}

.lib-empty {
  flex: 1;
  margin: 0;
  padding: 24px;
  color: var(--muted);
}

.drawer-foot {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--line);
}

.drawer-foot p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12.5px;
}

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

/* ---------- Bildirim ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 12px 14px 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 16px 40px -12px rgba(36, 28, 23, 0.45);
  transform: translateX(-50%);
  animation: toast-in 0.18s ease-out;
}

.toast-action {
  flex-shrink: 0;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.toast-action:hover {
  background: rgba(255, 255, 255, 0.2);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Dar ekranlar ---------- */

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .editor {
    border-right: 0;
  }

  .preview {
    order: -1;
    padding: 24px 16px;
    border-bottom: 1px solid var(--line);
  }

  .preview-inner {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 8px;
    padding: 0 8px 0 16px;
  }

  .brand-name,
  .doc-status {
    display: none;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .editor {
    padding: 0 16px 48px;
  }

  .field-row {
    flex-wrap: wrap;
  }

  .field.code,
  .model-row .field:not(.grow) {
    width: calc(50% - 6px);
  }

  .model-row .field.grow {
    flex-basis: 100%;
  }

  .preview-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-actions .btn {
    flex: 1;
  }

  .note-label {
    width: 110px;
  }
}
