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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --text: #e8eaf0;
  --text-muted: #7a82a8;
  --primary: #4f8ef7;
  --primary-dark: #3a74e0;
  --danger: #e05252;
  --danger-dark: #c03a3a;
  --success: #3ec97a;
  --warning: #f0a840;
  --radius: 10px;
  --radius-sm: 6px;
}

html { height: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo {
  font-weight: 700;
  font-size: 17px;
  color: var(--primary);
  white-space: nowrap;
}
#nav {
  display: flex;
  gap: 4px;
}
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: var(--surface2); color: var(--text); font-weight: 500; }

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}
h1 { font-size: 22px; font-weight: 700; margin-bottom: 20px; }
h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); }

/* Dashboard cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
@media (max-width: 420px)  { .cards { grid-template-columns: 1fr; } }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.card-value { font-size: 36px; font-weight: 800; color: var(--text); }
.card-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .06em; }
.card-out .card-value { color: var(--warning); }
.card-available .card-value { color: var(--success); }

/* Tables */
section { margin-top: 28px; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }
.empty { color: var(--text-muted); text-align: center; padding: 24px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge-out { background: rgba(240,168,64,.15); color: var(--warning); }
.badge-avail { background: rgba(62,201,122,.15); color: var(--success); }

/* Search */
.search-wrap { margin-bottom: 16px; }
.search-wrap input {
  width: 100%;
  max-width: 360px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--primary); }

/* Scanner page */
.scan-page { padding: 16px; display: flex; flex-direction: column; align-items: center; }
.scanner-wrap { width: 100%; max-width: 480px; }
.scan-hint {
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

/* Modal backdrop */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  backdrop-filter: blur(3px);
}

/* Modal panels */
.modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 36px;
  max-width: 540px;
  margin: 0 auto;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,1,.23,1);
}
.modal.modal-enter { display: block; }
.modal.modal-visible { transform: translateY(0); }
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.modal-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 18px; }
.modal-sub code { color: var(--primary); font-size: 12px; }
.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.modal label input {
  padding: 11px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  width: 100%;
}
.modal label input:focus { border-color: var(--primary); }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* Check-in info */
.checkin-info {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}
.info-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-right: 8px;
}

/* Buttons */
.btn {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:active { opacity: .85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 400;
  opacity: 0;
  transition: transform .25s, opacity .25s;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-success { border-color: var(--success); color: var(--success); }

code { font-family: monospace; font-size: 0.9em; }

/* User area in header */
.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-username {
  font-size: 13px;
  color: var(--text-muted);
}
.btn-logout {
  padding: 5px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-logout:hover { background: var(--border); color: var(--text); }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
}
.login-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 24px;
  text-align: center;
}
.login-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.login-label input {
  padding: 11px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  width: 100%;
}
.login-label input:focus { border-color: var(--primary); }
.login-btn { width: 100%; margin-top: 8px; }
.login-error {
  background: rgba(224,82,82,.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* Admin tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab-btn {
  padding: 8px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Admin form */
.admin-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}
.admin-form input, .admin-form select {
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.admin-form input:focus, .admin-form select:focus { border-color: var(--primary); }
.form-error {
  margin-top: 8px;
  color: var(--danger);
  font-size: 13px;
}

/* Small action buttons */
.btn-sm {
  padding: 5px 10px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-sm:active { opacity: .85; }
.btn-sm.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm.btn-secondary:hover { background: var(--border); }
.btn-sm.btn-danger { background: var(--danger); color: #fff; }
.btn-sm.btn-danger:hover { background: var(--danger-dark); }
.action-cell { white-space: nowrap; }
.action-cell .btn-sm { margin-right: 4px; }

/* Item name edit input in table */
.item-name-input {
  padding: 5px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  width: 100%;
  max-width: 240px;
}
.item-name-input:focus { border-color: var(--primary); }

/* Role badges */
.badge-admin { background: rgba(79,142,247,.15); color: var(--primary); }
.badge-user  { background: rgba(122,130,168,.15); color: var(--text-muted); }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* --- Tablet (≤ 768px) --- */
@media (max-width: 768px) {
  .container { padding: 20px 14px 40px; }
}

/* --- Mobile (≤ 640px) --- */
@media (max-width: 640px) {

  /* Header: stack nav below logo + user-area */
  .header-inner {
    height: auto;
    flex-wrap: wrap;
    gap: 0;
    padding: 0 14px;
  }
  .logo   { order: 1; padding: 12px 0; flex: 1; }
  .user-area { order: 2; padding: 8px 0; }
  #nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px 0 8px;
    border-top: 1px solid var(--border);
    gap: 2px;
  }
  #nav::-webkit-scrollbar { display: none; }
  .nav-link {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 13px;
  }
  /* Hide username text on mobile — keep only logout button */
  .nav-username { display: none; }

  /* Typography */
  h1 { font-size: 20px; }
  h2 { font-size: 15px; }

  /* Container */
  .container { padding: 14px 12px 36px; }

  /* Admin tabs: horizontally scrollable, no wrap */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Admin add-forms: stack fields vertically */
  .admin-form {
    flex-direction: column;
    align-items: stretch;
  }
  .admin-form input,
  .admin-form select {
    width: 100%;
  }

  /* Search inputs in section headers: full width */
  input[type="search"] {
    width: 100% !important;
  }

  /* Buttons */
  .btn { font-size: 14px; padding: 11px 14px; }

  /* Cards: single column only on very small phones */
  .cards { grid-template-columns: 1fr; }

  /* Modal: extra bottom padding for home-bar devices */
  .modal { padding: 22px 16px 40px; }
}
