/* ─── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --bg-card:     #1a1d27;
  --bg-input:    #12141c;
  --border:      #2a2d3e;
  --border-focus:#4a6cf7;
  --text:        #e2e4f0;
  --text-muted:  #8b8fa8;
  --accent:      #4a6cf7;
  --accent-hover:#3a5ce6;
  --danger:      #e05260;
  --danger-hover:#c83f4d;
  --success:     #3dd68c;
  --warning:     #f5a623;
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --font:        'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Header ───────────────────────────────────────────────────── */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.header-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}

h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* ─── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font);
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

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

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #363a52; }

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

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); border-color: var(--text-muted); }
.btn-icon.edit:hover  { color: var(--accent); border-color: var(--accent); }
.btn-icon.delete:hover { color: var(--danger); border-color: var(--danger); }

/* ─── Main ─────────────────────────────────────────────────────── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ─── Stats Bar ────────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ─── Filters ──────────────────────────────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.filter-input,
.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.45rem 0.85rem;
  font-size: 0.875rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.filter-input { min-width: 240px; }
.filter-input:focus,
.filter-select:focus { border-color: var(--border-focus); }
.filter-select option { background: var(--bg-card); }

/* ─── Inventory Table ──────────────────────────────────────────── */
.inventory-section { overflow: hidden; }

.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: #12141f;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  font-weight: 600;
  padding: 0.75rem 1rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(74, 108, 247, 0.05); }

tbody td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  color: var(--text);
}

/* Color swatch cell */
.color-swatch-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.12);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* Usage bar */
.usage-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 90px;
}
.usage-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s;
}
.usage-pct {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Badge for material type */
.type-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(74, 108, 247, 0.15);
  color: #8ba4ff;
  border: 1px solid rgba(74, 108, 247, 0.3);
}

/* Quantity stepper */
.qty-control {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.qty-btn {
  background: var(--bg);
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s;
  font-family: var(--font);
}
.qty-btn:hover { background: var(--border); }
.qty-btn:disabled { opacity: 0.3; cursor: default; }
.qty-btn:disabled:hover { background: var(--bg); }
.qty-value {
  padding: 0.25rem 0.5rem;
  min-width: 2rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.875rem;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.notes-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.actions-cell {
  display: flex;
  gap: 0.4rem;
  white-space: nowrap;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 2rem !important;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { margin-bottom: 0.25rem; }
.empty-state strong { color: var(--text); }

/* ─── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  transition: transform 0.2s;
  padding: 1.75rem;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal--sm { max-width: 400px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

/* ─── Form ─────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group--full { grid-column: 1 / -1; }
.form-group--color { justify-content: flex-end; }

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.required { color: var(--danger); }

input[type="text"],
input[type="number"],
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--border-focus); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; }

input[type="color"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  cursor: pointer;
  padding: 3px;
}

.input-prefix-wrap {
  position: relative;
}
.input-prefix {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}
.input-prefix-wrap input { padding-left: 1.6rem; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* error state */
input.invalid, textarea.invalid {
  border-color: var(--danger);
}

/* delete modal message */
.delete-msg {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

/* ─── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #3a3d52; }

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 680px) {

  /* Header */
  .header-inner {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    gap: 0.6rem;
  }
  .header-inner .btn { flex: 1; justify-content: center; font-size: 0.82rem; }
  h1 { font-size: 1rem; }

  /* Main padding */
  main { padding: 0.75rem; gap: 0.75rem; }

  /* Stats: 2-up grid */
  .stats-bar { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .stat-card { padding: 0.75rem 1rem; }
  .stat-value { font-size: 1.3rem; }
  .stat-label { font-size: 0.68rem; }

  /* Filters: stack */
  .filters { flex-direction: column; align-items: stretch; }
  .filter-input,
  .filter-select { width: 100%; min-width: unset; }

  /* ── Table → Card layout ── */
  .table-wrapper {
    background: transparent;
    border: none;
    overflow-x: unset;
  }

  table, thead, tbody, tr, th, td { display: block; }

  /* Hide column headers visually */
  thead { position: absolute; left: -9999px; top: -9999px; }

  /* Each row becomes a card */
  tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    padding: 0.25rem 0;
    position: relative;
  }
  tbody tr:last-child { border-bottom: 1px solid var(--border); }
  tbody tr:hover { background: var(--bg-card); }

  /* Each cell: label on left, value on right */
  tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.9rem;
  }
  tbody td:last-child { border-bottom: none; }

  /* Show the data-label as a dim prefix */
  tbody td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-right: 1rem;
    min-width: 80px;
  }

  /* Hide the color swatch row and actions label row (empty data-label) */
  tbody td[data-label=""] {
    padding: 0.4rem 1rem;
    justify-content: flex-start;
  }
  tbody td[data-label=""]::before { display: none; }

  /* Actions: full-width row of buttons */
  .actions-cell {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }
  .actions-cell .btn-icon {
    flex: 1;
    justify-content: center;
    padding: 0.55rem;
    font-size: 0.85rem;
  }

  /* Notes: allow wrapping */
  .notes-cell {
    white-space: normal;
    max-width: unset;
    text-align: right;
  }

  /* Empty state */
  .empty-state { padding: 3rem 1rem !important; }

  /* Modal: full screen */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    padding: 1.25rem 1rem;
  }
  .modal--sm { border-radius: 16px 16px 0 0; }

  /* Form */
  .form-grid { grid-template-columns: 1fr; }
  .form-group--full { grid-column: 1; }

  /* Form actions: full-width buttons */
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; padding: 0.75rem; }

  input[type="text"],
  input[type="number"],
  textarea { font-size: 1rem; padding: 0.7rem 0.9rem; }
  input[type="color"] { height: 48px; }
}
