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

:root {
  --brand:       #5c6bc0;
  --brand-hover: #3949ab;
  --surface:     #ffffff;
  --surface-2:   #f8f9fc;
  --border:      #e2e5ee;
  --text:        #111827;
  --text-2:      #6b7280;
  --red:         #ef4444;
  --green:       #22c55e;
  --r:           6px;
  --shadow:      0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  min-height: 100vh;
}

/* Utility */
.hidden { display: none !important; }
.full   { width: 100%; }

/* Auth Screen */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 36px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}

.logo-mark {
  display: block;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin: 0 auto 8px;
  object-fit: cover;
}

.auth-logo h1 { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.auth-logo p  { color: var(--text-2); font-size: 13px; }

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.auth-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

.api-config {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.api-config label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* Form Fields */
.field { margin-bottom: 16px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.field-row .field { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
}

.field small {
  display: block;
  font-size: 11px;
  color: var(--text-2);
  margin-top: 4px;
}

.field-error {
  font-size: 12px;
  color: var(--red);
  margin-top: -8px;
  margin-bottom: 8px;
}

.field-error:not(:empty) { margin-bottom: 12px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(92,107,192,.15);
}

textarea { min-height: 72px; resize: vertical; }

/* Buttons */
button { cursor: pointer; font-family: inherit; font-size: 14px; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: var(--r);
  padding: 8px 16px;
  font-weight: 500;
  transition: background .15s;
}
.btn-primary:hover    { background: var(--brand-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 16px;
  font-weight: 500;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-2);
  padding: 6px 8px;
  border-radius: var(--r);
  transition: background .15s, color .15s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
  border: none;
  border-radius: var(--r);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  transition: background .15s;
}
.btn-danger:hover { background: #fecaca; }

.btn-edit {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  transition: background .15s;
}
.btn-edit:hover { background: var(--border); }

.btn-sm { padding: 5px 10px !important; font-size: 12px !important; }

.btn-view {
  background: rgba(92,107,192,.1);
  color: var(--brand);
  border: none;
  border-radius: var(--r);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  transition: background .15s;
}
.btn-view:hover { background: rgba(92,107,192,.2); }

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-brand {
  font-size: 17px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -.4px;
  flex-shrink: 0;
}

.topbar-nav { display: flex; gap: 4px; flex: 1; }

.nav-btn {
  background: none;
  border: none;
  padding: 6px 14px;
  border-radius: var(--r);
  font-size: 14px;
  color: var(--text-2);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-btn:hover  { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: rgba(92,107,192,.1); color: var(--brand); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* Main Content */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

.loading {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-2);
}

/* Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.4px;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

thead th {
  background: var(--surface-2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

thead th.th-sortable { cursor: pointer; user-select: none; }
thead th.th-sortable:hover { color: var(--text); }

tr.thead-filter th {
  background: var(--surface);
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}
tr.thead-filter select {
  width: 100%;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

td { padding: 12px 14px; vertical-align: middle; }

.td-actions { text-align: right; white-space: nowrap; }
.td-actions > * + * { margin-left: 6px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.badge-planned   { background: #e0e7ff; color: #4338ca; }
.badge-purchased { background: #fef3c7; color: #b45309; }
.badge-given     { background: #dcfce7; color: #15803d; }
.badge-canceled  { background: #f3f4f6; color: #6b7280; }
.badge-lost      { background: #ffedd5; color: #c2410c; }
.badge-granted   { background: #dcfce7; color: #15803d; }
.badge-open      { background: #e0e7ff; color: #4338ca; }
.badge-expired   { background: #fee2e2; color: #b91c1c; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-2);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.modal-dialog {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-dialog.modal-lg { max-width: 860px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.3px; }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Person Detail */
.detail-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.detail-section-head h3 { margin: 0; }

.detail-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-2);
  margin-bottom: 10px;
}

.detail-row { display: flex; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.detail-row strong { flex-shrink: 0; color: var(--text-2); min-width: 110px; }

.tag {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  margin: 2px;
}

.rel-add-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: flex-end;
}
.rel-add-form .field { margin: 0; flex: 1; }
.rel-add-form .field label { font-size: 11px; color: var(--text-2); margin-bottom: 3px; }

/* Toast */
#toast-area {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1f2937;
  color: white;
  padding: 11px 15px;
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  max-width: 320px;
  opacity: 0;
  transform: translateY(8px);
  animation: toast-in .18s forwards;
}
.toast.success { border-left: 3px solid #22c55e; }
.toast.error   { border-left: 3px solid #ef4444; }

@keyframes toast-in { to { opacity: 1; transform: translateY(0); } }

.text-muted { color: var(--text-2); }
.text-sm    { font-size: 12px; }

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
}

.filter-bar select,
.filter-bar input[type="text"] {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

.filter-bar select:focus,
.filter-bar input[type="text"]:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(92,107,192,.15);
}

.filter-bar select { width: 140px; }
.filter-bar input[type="text"] { flex: 1; min-width: 140px; max-width: 240px; }

.filter-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.filter-group > span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  font-weight: 600;
}

/* Inline add forms (inside modal fields) */
.btn-link {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 0;
  cursor: pointer;
  display: block;
  margin-top: 5px;
}
.btn-link:hover { text-decoration: underline; }

.inline-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px;
  margin-top: 6px;
}

.inline-form-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.inline-form-row input,
.inline-form-row select { flex: 1; margin: 0; }

.inline-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.occ-person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.occ-person-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: var(--r);
  cursor: pointer;
}
.occ-person-label:hover { background: var(--border); }

/* About */
.about-card {
  max-width: 480px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 40px;
  text-align: center;
}
.about-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 24px; }
.about-logo h1 { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin: 0; }
.about-version { color: var(--text-2); font-size: 13px; margin: 0; }
.about-desc { color: var(--text-2); font-size: 14px; line-height: 1.6; margin-bottom: 20px; }
.about-credit { font-size: 13px; color: var(--text-2); }
.kofi-btn {
  display: inline-block;
  margin-top: 20px;
  padding: 9px 20px;
  background: #ff5e5b;
  color: #fff;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.kofi-btn:hover { background: #e04f4c; }
