:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1b2430;
  --muted: #64748b;
  --line: #d8dee8;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 18px 45px rgba(18, 38, 63, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

button, a.secondary {
  border: 0;
  border-radius: 7px;
  padding: 11px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary { background: var(--brand); color: #fff; }
.primary:hover { background: var(--brand-dark); }
.secondary { background: #e7eef3; color: var(--text); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.danger { background: #fee2e2; color: var(--danger); }
.small { padding: 7px 9px; font-size: 13px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #e8f1ef, #f8fafc 55%, #f3eee6);
}

.login-shell {
  width: min(440px, calc(100% - 28px));
}

.login-panel {
  background: var(--panel);
  padding: 34px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand, .brand-mark {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  padding: 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  border-radius: 7px;
  font-weight: 700;
}

.login-panel .brand-mark {
  margin-bottom: 18px;
}

h1, h2, p {
  margin-top: 0;
}

h1 { font-size: clamp(25px, 4vw, 34px); margin-bottom: 6px; }
h2 { font-size: 19px; margin-bottom: 14px; }
p { color: var(--muted); line-height: 1.5; }

.form, .scan-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 14px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(15, 118, 110, .16);
  border-color: var(--brand);
}

/* Varsayılan bilgi mesajı nötr; böylece kırmızı gerçekten "hata/uyarı" demek. */
.message {
  min-height: 22px;
  color: var(--muted);
  font-weight: 600;
}

.message.ok { color: var(--ok); }
.message.warn { color: var(--accent); }
.message.error { color: var(--danger); }

/* Çıkış sonrası stoğu sıfırlanan ürünler için sayfa üstü uyarı şeridi. */
.stock-alert {
  border: 2px solid var(--danger);
  border-left-width: 8px;
  background: #fef2f2;
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: 0 10px 26px rgba(185, 28, 28, .16);
  animation: stock-alert-in .22s ease-out;
}

.stock-alert-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}

.stock-alert-head strong {
  color: var(--danger);
  font-size: 19px;
  letter-spacing: .4px;
}

.stock-alert-head strong::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-right: 9px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 16px;
  vertical-align: -5px;
}

.stock-alert-note {
  margin: 0 0 10px;
  color: var(--danger);
  font-size: 14px;
}

.stock-alert-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
}

.stock-alert-list li {
  background: #fff;
  border: 1px solid #fca5a5;
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--danger);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.stock-alert-list small {
  display: block;
  margin-top: 3px;
  color: #7f1d1d;
  font-weight: 600;
}

@keyframes stock-alert-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stock-alert { animation: none; }
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.scan-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

/* --- Ürün görselleri --- */

.thumb {
  width: 46px;
  height: 46px;
  border-radius: 7px;
  border: 1px solid var(--line);
  object-fit: contain;
  background: #fff;
  display: block;
  cursor: zoom-in;
}

.thumb-empty {
  cursor: default;
  background: repeating-linear-gradient(45deg, #f1f5f9, #f1f5f9 6px, #e2e8f0 6px, #e2e8f0 12px);
}

/* Dış bağlantısı kopmuş görsel */
.thumb-broken {
  cursor: default;
  background: repeating-linear-gradient(45deg, #fee2e2, #fee2e2 6px, #fecaca 6px, #fecaca 12px);
  border-color: #fca5a5;
}

/* Görselin sunucuda mı yoksa bağlantı mı olduğunu gösteren rozet */
.kaynak {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
}

.kaynak-yerel { background: #dcfce7; color: var(--ok); }
.kaynak-link  { background: #e0f2fe; color: #0369a1; }

/* Görseller ekranındaki saklama modu anahtarı */
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0 4px;
}

.switch input {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
}

.detail-image {
  display: block;
  width: 100%;
  max-width: 240px;
  max-height: 240px;
  object-fit: contain;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px;
  cursor: zoom-in;
}

.image-dialog {
  width: min(640px, calc(100% - 24px));
}

.image-dialog-photo {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.model-table {
  min-width: 1080px;
}

.model-table td {
  vertical-align: top;
}

.model-actions {
  display: grid;
  gap: 7px;
  min-width: 340px;
}

.model-search {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.model-input {
  display: flex;
  gap: 7px;
  align-items: center;
}

.model-input input[type="url"] {
  flex: 1;
  min-width: 150px;
  padding: 7px 9px;
  font-size: 13px;
}

.model-input input[type="file"] {
  flex: 1;
  min-width: 150px;
  padding: 5px;
  font-size: 12px;
  border-style: dashed;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-grid div {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detail-grid strong {
  display: block;
  overflow-wrap: anywhere;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 232px;
  background: #111827;
  color: #fff;
  display: flex;
  flex-direction: column;
}

.sidebar nav {
  display: grid;
  gap: 4px;
  padding: 10px;
}

.nav {
  justify-content: flex-start;
  background: transparent;
  color: #cbd5e1;
}

.nav.active, .nav:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.sidebar .ghost {
  margin: auto 14px 16px;
  color: #d1d5db;
  border-color: rgba(255,255,255,.18);
}

.app {
  margin-left: 232px;
  min-height: 100vh;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.view { display: none; }
.view.active { display: block; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.stats article, .panel, .table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(18, 38, 63, .06);
}

.stats article {
  padding: 20px;
}

.stats span, small {
  display: block;
  color: var(--muted);
}

.stats strong {
  display: block;
  margin-top: 12px;
  font-size: 34px;
}

.stat-filter {
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.stat-filter:hover,
.stat-filter.active {
  border-color: var(--brand);
  box-shadow: 0 10px 28px rgba(15, 118, 110, .14);
}

.stat-filter.active {
  transform: translateY(-1px);
}

.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.panel {
  padding: 20px;
}

.stack {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.list-item:last-child { border-bottom: 0; }
.delivery-active {
  margin-top: 18px;
}

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

.delivery-note-item {
  gap: 12px;
}

.link-button {
  background: transparent;
  color: var(--text);
  padding: 0;
  border-radius: 0;
  justify-content: flex-start;
  text-align: left;
  display: grid;
  gap: 3px;
}

.link-button:hover {
  color: var(--brand);
}

.brand-stock-wrap table {
  min-width: 720px;
}

.brand-stock-link {
  width: 100%;
}
.in { color: var(--ok); }
.out { color: var(--danger); }
.low-qty {
  color: var(--danger);
  font-weight: 800;
}

.return-tag {
  color: var(--danger);
  font-weight: 800;
}

.return-row td {
  background: #fff1f2;
}

.scan-panel {
  max-width: 760px;
}

.inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}

.toolbar input {
  max-width: 460px;
}

.toolbar select {
  max-width: 240px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1220px;
}

th, td {
  text-align: left;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  background: #f8fafc;
}

tr.critical td {
  background: #fff7ed;
}

tr.count-hit td {
  background: #dff7f3;
  transition: background .2s ease;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

.pill.in { background: #dcfce7; }
.pill.out { background: #fee2e2; }

.empty {
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

dialog {
  width: min(720px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

.wide-dialog {
  width: min(1180px, calc(100% - 24px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, .45);
}

.dialog-form {
  padding: 22px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.left-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.count-stats {
  margin-top: 18px;
}

.low-stock-panel {
  margin-top: 18px;
}

button:disabled, input:disabled, select:disabled, a.secondary[aria-disabled="true"] {
  opacity: .55;
  cursor: not-allowed;
}

/* Bildirimler: hatalar artık sessizce konsola düşmüyor. */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  z-index: 60;
  max-width: min(420px, calc(100% - 36px));
}

.toast {
  padding: 13px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
  animation: toast-in .18s ease-out;
}

.toast.error {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.toast.ok {
  background: #dcfce7;
  color: var(--ok);
  border: 1px solid #86efac;
}

/* Stok bitti uyarısı: kendiliğinden kapanmaz, tıklanarak kapatılır. */
.toast.alert {
  background: var(--danger);
  color: #fff;
  border: 2px solid #7f1d1d;
  font-size: 16px;
  cursor: pointer;
}

.toast.alert small {
  display: block;
  margin-top: 6px;
  color: #fecaca;
  font-weight: 600;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

@media (max-width: 820px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app {
    margin-left: 0;
    padding: 18px;
  }

  .topbar, .toolbar, .delivery-head {
    flex-direction: column;
  }

  .stats, .grid.two, .inline, .detail-grid {
    grid-template-columns: 1fr;
  }
}
