/* ─── App Styles ─── piecekeeper ─── */

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

:root {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-text: #0a0a0a;
  --color-text-muted: #6b7280;
  --color-text-light: #9ca3af;
  --color-border: #e5e7eb;
  --color-border-light: #f3f4f6;
  --color-primary: #0a0a0a;
  --color-primary-hover: #262626;
  --color-accent: #c45d3e;
  --color-accent-soft: #f0e0d8;
  --color-error: #dc2626;
  --color-error-bg: #fef2f2;
  --color-success: #16a34a;
  --color-success-bg: #f0fdf4;
  --color-warning: #ca8a04;
  --color-warning-bg: #fefce8;
  --color-info: #2563eb;
  --color-info-bg: #eff6ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Layout ─── */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.app-logo {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.app-logo span {
  color: var(--color-text-muted);
  font-weight: 400;
}

.app-nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.app-nav-link {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  transition: all 0.15s;
}

.app-nav-link:hover {
  color: var(--color-text);
  background: var(--color-border-light);
}

.app-nav-link.active {
  color: var(--color-text);
  background: var(--color-border-light);
  font-weight: 500;
}

.app-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ─── Page Header ─── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* ─── Buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: var(--font);
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

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

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

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

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

.btn-danger {
  color: #fff;
  background: var(--color-error);
  border-color: var(--color-error);
}

.btn-danger:hover {
  background: #b91c1c;
}

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

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

.btn-sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}

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

.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn-secondary.loading::after {
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: var(--color-text);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Filters Bar ─── */

.filters-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.filter-select,
.filter-input {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.filter-select:focus,
.filter-input:focus {
  border-color: var(--color-primary);
}

.filter-input {
  min-width: 200px;
}

/* ─── Table ─── */

.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-border-light);
}

.data-table td {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: #fafafa;
}

.data-table .thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--color-border-light);
  display: block;
}

.data-table .thumb-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-light);
  font-size: 1.25rem;
}

.data-table a {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
}

.data-table a:hover {
  color: var(--color-accent);
}

/* ─── Status Badges ─── */

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-verfuegbar {
  color: #15803d;
  background: #dcfce7;
}

.badge-verkauft {
  color: #991b1b;
  background: #fee2e2;
}

.badge-reserviert {
  color: #854d0e;
  background: #fef9c3;
}

.badge-kommission {
  color: #1e40af;
  background: #dbeafe;
}

/* ─── Empty State ─── */

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* ─── Card / Detail ─── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-body {
  padding: 1.5rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.detail-image {
  width: 100%;
  max-height: 500px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--color-border-light);
}

.detail-image-placeholder {
  width: 100%;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-border-light);
  border-radius: var(--radius);
  color: var(--color-text-light);
  font-size: 3rem;
}

.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-light);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.375rem 0;
  font-size: 0.875rem;
}

.detail-label {
  color: var(--color-text-muted);
  flex-shrink: 0;
  margin-right: 1rem;
}

.detail-value {
  font-weight: 500;
  text-align: right;
}

.detail-notes {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--color-text);
  white-space: pre-wrap;
}

/* ─── Form ─── */

.form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.form-section {
  margin-bottom: 2rem;
}

.form-section:last-child {
  margin-bottom: 0;
}

.form-section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-light);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 0.375rem;
}

.form-label .required {
  color: var(--color-error);
  margin-left: 0.125rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-light);
}

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

.form-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* ─── Image Upload ─── */

.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.upload-area:hover {
  border-color: var(--color-text-muted);
  background: var(--color-border-light);
}

.upload-area.has-preview {
  padding: 0.5rem;
  border-style: solid;
}

.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  font-size: 2rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

.upload-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-top: 0.25rem;
}

.upload-preview {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 6px;
}

.upload-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.upload-remove:hover {
  background: rgba(0,0,0,0.8);
}

/* ─── Form Actions ─── */

.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border-light);
}

/* ─── Alert / Toast ─── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* ─── Modal ─── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  transform: translateY(10px);
  transition: transform 0.2s;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.modal p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ─── Price Display ─── */

.price {
  font-variant-numeric: tabular-nums;
}

/* ─── Count Badge ─── */

.count-badge {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--color-border-light);
  padding: 0.25rem 0.5rem;
  border-radius: 100px;
  font-weight: 500;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .app-main {
    padding: 1.25rem 1rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .filter-input {
    min-width: unset;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .form-card {
    padding: 1.25rem;
  }

  .data-table {
    font-size: 0.8125rem;
  }

  .data-table th:nth-child(n+4),
  .data-table td:nth-child(n+4) {
    display: none;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .app-nav-inner {
    height: 48px;
  }

  .app-nav-link {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  .page-title {
    font-size: 1.25rem;
  }
}

/* ─── Transition helpers ─── */

.hidden {
  display: none !important;
}

.fade-in {
  animation: fadeIn 0.2s ease-out;
}

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

/* ─── Gallery Grid ─── */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.gallery-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
  color: var(--color-text);
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: pointer;
}

.gallery-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.gallery-card-image {
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--color-border-light);
  flex-shrink: 0;
}

.gallery-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s;
}

.gallery-card:hover .gallery-card-img {
  transform: scale(1.03);
}

.gallery-card-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-light);
}

.gallery-card-info {
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.gallery-card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.gallery-card-meta span + span::before {
  content: '·';
  margin-right: 0.5rem;
}

.gallery-card-badge {
  margin-top: 0.125rem;
}

/* ─── Gallery Single View ─── */

.gallery-back {
  margin-bottom: 1.5rem;
}

.gallery-single {
  max-width: 760px;
  margin: 0 auto;
}

.gallery-single-image-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  box-shadow: var(--shadow-lg);
}

.gallery-single-img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

.gallery-single-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem;
  color: var(--color-text-light);
  font-size: 0.875rem;
}

.gallery-single-info {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gallery-single-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.gallery-single-title {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gallery-single-meta {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.gallery-single-actions {
  margin-top: 0.5rem;
}

/* ─── Gallery Responsive ─── */

@media (max-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.875rem;
  }

  .gallery-single-image-wrap {
    min-height: 280px;
  }

  .gallery-single-img {
    max-height: 60vh;
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }

  .gallery-card-info {
    padding: 0.75rem;
  }
}
