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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3352;
  --accent: #4f6ef7;
  --accent-hover: #6b84ff;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --text: #e2e8f0;
  --text-muted: #7c8db5;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

/* ── Header ───────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text);
  white-space: nowrap;
}
.logo span {
  color: var(--accent);
  font-weight: 400;
  margin-left: 6px;
}

nav { display: flex; gap: 4px; flex: 1; }

.nav-btn {
  padding: 6px 18px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }


/* ── Main / Pages ─────────────────────────────────────────────── */
main { padding: 24px 32px 48px; max-width: 1200px; margin: 0 auto; }

.page { display: none; }
.page.active { display: block; }
.hidden { display: none !important; }

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  margin-top: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }

.btn-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}
.btn-icon:hover { background: var(--accent); border-color: var(--accent); }
.btn-icon.spinning { animation: spin 1s linear infinite; }

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

/* ── States ───────────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}
.loading::before {
  content: '';
  display: block;
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Card Grid ────────────────────────────────────────────────── */
.card-grid { display: grid; gap: 12px; }

/* ── Purchase Card ────────────────────────────────────────────── */
.purchase-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 16px;
  align-items: center;
  transition: border-color 0.15s;
}
.purchase-card:hover { border-color: var(--accent); }
.purchase-card.completed { grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; }

.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.field-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-value.price { color: var(--yellow); font-weight: 700; font-size: 15px; }
.field-value.project-assigned { color: var(--green); }

/* ── Receipt Button ───────────────────────────────────────────── */
.receipt-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.receipt-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.receipt-btn.no-receipt { opacity: 0.35; cursor: default; pointer-events: none; }

/* ── Card Actions ─────────────────────────────────────────────── */
.card-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 190px;
}

/* ── Searchable project dropdown ──────────────────────────────── */
.project-dropdown {
  position: relative;
  width: 100%;
}

.project-dropdown-input {
  width: 100%;
  padding: 7px 30px 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
  outline: none;
  text-overflow: ellipsis;
}
.project-dropdown-input::placeholder { color: var(--text-muted); }
.project-dropdown-input:focus { border-color: var(--accent); }
.project-dropdown-input.open { border-radius: 7px 7px 0 0; border-color: var(--accent); }

.project-dropdown-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  font-size: 10px;
  transition: transform 0.15s;
}
.project-dropdown.open .project-dropdown-arrow { transform: translateY(-50%) rotate(180deg); }

.project-dropdown-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 7px 7px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.project-dropdown.open .project-dropdown-list { display: block; }

.project-dropdown-option {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
.project-dropdown-option:hover,
.project-dropdown-option.highlighted { background: var(--accent); color: #fff; }
.project-dropdown-option.no-results { color: var(--text-muted); cursor: default; }
.project-dropdown-option.no-results:hover { background: transparent; color: var(--text-muted); }

.assign-btn {
  width: 100%;
  padding: 7px;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.assign-btn:hover { background: var(--accent-hover); }
.assign-btn:disabled { opacity: 0.5; cursor: default; }

.unassign-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.unassign-btn:hover { border-color: var(--red); color: var(--red); }

/* ── Summary Grid ─────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

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

.summary-card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.summary-project-name { font-size: 16px; font-weight: 700; }
.summary-total { font-size: 20px; font-weight: 800; color: var(--yellow); white-space: nowrap; }
.summary-meta { font-size: 12px; color: var(--text-muted); padding: 10px 22px; border-bottom: 1px solid var(--border); }
.summary-items { padding: 4px 0; }

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 22px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.summary-item:last-child { border-bottom: none; }
.summary-item-name { color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-item-date { color: var(--text-muted); font-size: 11px; margin: 0 12px; white-space: nowrap; }
.summary-item-price { color: var(--text); font-weight: 600; white-space: nowrap; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
}
.modal-content {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90vw;
  max-width: 900px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--red); border-color: var(--red); color: #fff; }
#modal-frame { width: 100%; height: 100%; border: none; background: #fff; }

/* ── Toast ────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--red);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s;
  max-width: 360px;
}
#toast.show { transform: translateY(0); opacity: 1; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 960px) {
  .purchase-card { grid-template-columns: 1fr 1fr 1fr; }
  .purchase-card .card-actions { grid-column: 1 / -1; flex-direction: row; }
  .purchase-card .card-actions .project-select { flex: 1; }
  .purchase-card.completed { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 700px) {
  header { height: auto; padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
  nav { flex: unset; width: 100%; justify-content: flex-start; }
  .logo { width: 100%; }
  main { padding: 16px; }
  .purchase-card { grid-template-columns: 1fr 1fr; }
  .purchase-card.completed { grid-template-columns: 1fr 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  nav .nav-btn { padding: 7px 14px; font-size: 13px; flex: 1; text-align: center; }
}
@media (max-width: 480px) {
  .purchase-card { grid-template-columns: 1fr; }
  .purchase-card.completed { grid-template-columns: 1fr; }
  .purchase-card .card-actions { flex-direction: column; }
  .modal-content { width: 100vw; height: 100dvh; border-radius: 0; }
}
