/* ── Reset & Base ─────────────────────────────────────────────────────────── */

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

:root {
  --bg:        #2e2b26;
  --bg-card:   #38342d;
  --bg-raised: #443f37;
  --border:    #524d44;
  --border-light: #615b51;
  --text:      #f5f0e8;
  --text-muted: #a09a8e;
  --text-dim:  #756e64;
  --gold:      #b8960c;
  --gold-light: #d4ae24;
  --green:     #4a7c59;
  --green-light: #5a9469;
  --red:       #8b3a3a;
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --radius:    6px;
  --radius-lg: 10px;
  --shadow:    0 2px 8px rgba(0,0,0,0.4);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); text-decoration: underline; }

h1, h2, h3 { font-family: var(--font-serif); font-weight: normal; line-height: 1.3; }

/* ── Navigation ──────────────────────────────────────────────────────────── */

.nav {
  background: #221e1a;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.nav-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.nav-brand:hover { text-decoration: none; }

.nav-logo {
  height: 32px;
  width: auto;
  display: block;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: color 0.15s;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }

.nav-user {
  color: var(--text-dim);
  font-size: 0.875rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
}

.btn-logout {
  color: var(--text-muted) !important;
  font-size: 0.875rem;
}
.btn-logout:hover { color: var(--text) !important; }

/* ── Main Layout ─────────────────────────────────────────────────────────── */

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

/* ── Footer ──────────────────────────────────────────────────────────────── */

.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}
.alert-success { background: rgba(74,124,89,0.15); border-color: var(--green); color: #8ac89e; }
.alert-error   { background: rgba(139,58,58,0.15); border-color: var(--red);   color: #c88a8a; }
.alert-info    { background: rgba(184,150,12,0.1);  border-color: var(--gold);  color: var(--gold-light); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  border: 1px solid transparent;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn-primary {
  background: var(--gold);
  color: #111;
  border-color: var(--gold);
}
.btn-primary:hover { background: var(--gold-light); border-color: var(--gold-light); color: #111; }
.btn-secondary {
  background: var(--bg-raised);
  color: var(--text);
  border-color: var(--border-light);
}
.btn-secondary:hover { background: #383838; border-color: #4a4a4a; color: var(--text); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-raised); color: var(--text); border-color: var(--border-light); }
.btn-ghost.active { color: var(--gold); border-color: var(--gold); }
.btn-sm   { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; padding: 0.7rem; font-size: 1rem; }

/* ── Auth Pages ──────────────────────────────────────────────────────────── */

.auth-page {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.auth-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
}

.auth-logo {
  width: 120px;
  height: auto;
}

.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
}
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; }

.auth-form .form-group + .form-group { margin-top: 1.25rem; }
.auth-form .btn-full { margin-top: 1.75rem; }

/* ── Form Elements ───────────────────────────────────────────────────────── */

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

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

.required { color: var(--gold); }

input[type="text"],
input[type="email"],
input[type="password"],
select,
.textarea {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, select:focus, .textarea:focus {
  outline: none;
  border-color: var(--gold);
}
input::placeholder, .textarea::placeholder { color: var(--text-dim); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M6 8L0 0h12z' fill='%23666'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }
.textarea { resize: vertical; min-height: 90px; }

.select-sm {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  appearance: none;
}

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 800px;
}
.form-card-narrow { max-width: 480px; }
.form-card-compact { margin-bottom: 2rem; }

.form-inline {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-inline .form-group { flex: 1; min-width: 180px; }
.form-inline .btn { margin-bottom: 0; align-self: flex-end; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

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

.page-header {
  margin-bottom: 2rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.8rem; color: var(--text); }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; }
.page-header-actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.breadcrumb { margin-bottom: 1.25rem; }
.breadcrumb a { color: var(--text-muted); font-size: 0.875rem; }
.breadcrumb a:hover { color: var(--text); text-decoration: none; }

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

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-open     { background: rgba(74,124,89,0.2);  color: #8ac89e; border: 1px solid rgba(74,124,89,0.4); }
.badge-reserved { background: rgba(184,150,12,0.15); color: var(--gold-light); border: 1px solid rgba(184,150,12,0.3); }
.badge-admin    { background: rgba(184,150,12,0.1);  color: var(--gold-light); border: 1px solid rgba(184,150,12,0.25); }
.badge-pending  { background: rgba(100,100,100,0.15); color: var(--text-muted); border: 1px solid var(--border); }
.badge-fail     { background: rgba(139,58,58,0.2); color: #c88a8a; border: 1px solid rgba(139,58,58,0.4); }
.badge-lg       { font-size: 0.85rem; padding: 0.3rem 0.8rem; }

/* ── Inventory Controls ──────────────────────────────────────────────────── */

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

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.55rem 0.75rem 0.55rem 2.1rem;
  width: 100%;
  transition: border-color 0.15s;
}
.search-input:focus {
  outline: none;
  border-color: var(--gold);
}
.search-input::placeholder { color: var(--text-dim); }

.sort-select {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.55rem 2rem 0.55rem 0.75rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M6 8L0 0h12z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  transition: border-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.sort-select:focus {
  outline: none;
  border-color: var(--gold);
}

/* ── Inventory Grid ──────────────────────────────────────────────────────── */

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

.piece-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  text-decoration: none !important;
  color: var(--text) !important;
}
.piece-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.card-photo {
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: var(--bg-raised);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.card-body { padding: 0.85rem; flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.card-name  { font-family: var(--font-serif); font-size: 0.95rem; line-height: 1.3; color: var(--text); }
.card-type  { font-size: 0.75rem; color: var(--text-muted); }
.card-caliber { font-size: 0.75rem; color: var(--text-dim); }
.card-footer { margin-top: auto; padding-top: 0.5rem; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0;
}

/* ── Piece Detail ────────────────────────────────────────────────────────── */

.piece-detail { max-width: 860px; }

.detail-photo-wrap {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-raised);
  margin-bottom: 2rem;
  max-height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}
.detail-photo {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  display: block;
}
.detail-photo-placeholder {
  width: 100%;
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.detail-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.detail-name { font-size: 2rem; color: var(--text); }

.detail-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.field-row {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.field-row:nth-child(even) { border-right: none; }
.field-row-full { grid-column: 1 / -1; border-right: none; }
.field-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); margin-bottom: 0.2rem; }
.field-value { color: var(--text); font-size: 0.95rem; }

.detail-section {
  margin-bottom: 2.5rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
}
.detail-section:last-child { border-bottom: none; }

.section-title {
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
}
.section-intro { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.25rem; }

.status-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.inline-reserve-form { display: flex; align-items: center; gap: 0.5rem; }

/* ── Interest ────────────────────────────────────────────────────────────── */

.interest-form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 600px; }

.interest-mine { margin-bottom: 1.5rem; }
.interest-mine-entry { position: relative; }

.interest-entry {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.interest-author {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gold);
  margin-bottom: 0.4rem;
}
.interest-text { color: var(--text); line-height: 1.6; white-space: pre-wrap; }
.interest-date { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.5rem; }

.interest-others { margin-top: 1.5rem; }
.interest-others-title { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin-bottom: 0.75rem; }

/* ── Stories ─────────────────────────────────────────────────────────────── */

.story-entry {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.story-header { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.story-author { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold); }
.story-date   { font-size: 0.75rem; color: var(--text-dim); }
.story-text   { color: var(--text); line-height: 1.6; white-space: pre-wrap; }

.story-form { max-width: 600px; margin-top: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.empty-state-sm { color: var(--text-dim); font-size: 0.875rem; margin-bottom: 1rem; }

/* ── Change Log ──────────────────────────────────────────────────────────── */

.changelog-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: var(--font-sans);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 1rem;
  transition: color 0.15s, border-color 0.15s;
}
.changelog-toggle:hover { color: var(--text); border-color: var(--border-light); }

.changelog { font-size: 0.82rem; }

.changelog-entry {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: baseline;
}
.changelog-entry:last-child { border-bottom: none; }
.changelog-date  { color: var(--text-dim); min-width: 160px; flex-shrink: 0; }
.changelog-actor { color: var(--gold); font-weight: 600; min-width: 100px; }
.changelog-action { color: var(--text-muted); flex: 1; }
.changelog-action em { color: var(--text); font-style: normal; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  background: var(--bg-raised);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-raised); }
.data-table .row-fail td { background: rgba(139,58,58,0.05); }
.data-table .empty-state { text-align: center; color: var(--text-muted); padding: 2rem; }
.nowrap { white-space: nowrap; }

/* ── Sort label ──────────────────────────────────────────────────────────── */
.sort-label { font-size: 0.8rem; color: var(--text-muted); }

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

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

@media (max-width: 768px) {
  .inventory-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-fields  { grid-template-columns: 1fr; }
  .field-row { border-right: none; }
  .form-grid { grid-template-columns: 1fr; }
  .nav-links { gap: 0.75rem; }
}

@media (max-width: 480px) {
  .inventory-grid { grid-template-columns: 1fr; }
  .main { padding: 1.25rem 1rem; }
  .auth-card { padding: 1.75rem 1.25rem; }
}
