/* BNI Key單神器 - BNI Brand Style */

:root {
  --bni-red: #CC0000;
  --bni-red-dark: #A30000;
  --bni-red-light: #FF3333;
  --bni-gray-dark: #333333;
  --bni-gray-mid: #666666;
  --bni-gray-light: #F5F5F5;
  --bni-gray-border: #E0E0E0;
  --bni-white: #FFFFFF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: var(--bni-gray-light);
  color: var(--bni-gray-dark);
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: var(--bni-white);
  border-bottom: 3px solid var(--bni-red);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-brand {
  font-size: 22px;
  font-weight: 900;
  color: var(--bni-red);
  letter-spacing: 1px;
}

.header-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--bni-gray-dark);
  letter-spacing: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.user-stats {
  font-size: 12px;
  color: #888;
  background: #f5f5f5;
  padding: 3px 10px;
  border-radius: 4px;
}

.header-link {
  font-size: 13px;
  color: var(--bni-red);
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--bni-red);
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

.header-link:hover,
.header-link.active {
  background: var(--bni-red);
  color: #fff;
}

/* ── Main Container ── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: #999;
}

/* ── Flash Messages ── */
.flash {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.flash-success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.flash-error {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
}

/* ── Auth Card ── */
.auth-card {
  max-width: 420px;
  margin: 60px auto;
  background: #fff;
  border-radius: 12px;
  padding: 40px 32px;
  box-shadow: var(--shadow-md);
}

.auth-title {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  color: #1a1a1a;
  margin-bottom: 28px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: #666;
}

.auth-footer a {
  color: var(--bni-red);
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* ── Form Elements ── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1.5px solid #ddd;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--bni-red);
}

.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1.5px solid #ddd;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}

.form-textarea:focus {
  border-color: var(--bni-red);
}

.form-hint {
  font-size: 12px;
  color: #999;
  margin-top: 6px;
  line-height: 1.6;
}

.form-hint code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  word-break: break-all;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.flex-1 {
  flex: 1;
}

.form-section {
  margin-top: 8px;
}

/* ── Page Card ── */
.page-card {
  background: var(--bni-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--bni-gray-dark);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--bni-gray-mid);
  margin-bottom: 24px;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--bni-red);
  color: var(--bni-white);
  border: none;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}

.btn-primary:hover {
  background: var(--bni-red-dark);
}

.btn-primary:disabled {
  background: #CCC;
  cursor: not-allowed;
}

.btn-block {
  display: block;
  width: 100%;
}

.btn-outline {
  background: transparent;
  color: var(--bni-red);
  border: 1.5px solid var(--bni-red);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-outline:hover {
  background: #FFF5F5;
}

.btn-small {
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-approve {
  background: #e8f5e9;
  color: #2e7d32;
}

.btn-approve:hover {
  background: #c8e6c9;
}

.btn-reject {
  background: #ffebee;
  color: #c62828;
}

.btn-reject:hover {
  background: #ffcdd2;
}

.btn-remove {
  background: none;
  border: none;
  color: #ccc;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  align-self: center;
  transition: color 0.2s;
}

.btn-remove:hover {
  color: var(--bni-red);
}

/* ── Referral Entry ── */
.referral-entry {
  background: var(--bni-gray-light);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  align-self: center;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--bni-gray-dark);
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--bni-red);
  cursor: pointer;
}

.referral-type-tag {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  white-space: nowrap;
}

.tag-outside {
  background: #e3f2fd;
  color: #1565c0;
}

.tag-inside {
  background: #fce4ec;
  color: #c62828;
}

/* ── Results ── */
.results-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 2px solid var(--bni-gray-border);
}

.results-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--bni-gray-dark);
}

.result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 14px;
}

.result-ok {
  background: #e8f5e9;
  color: #2e7d32;
}

.result-fail {
  background: #ffebee;
  color: #c62828;
}

.result-icon {
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.result-name {
  font-weight: 600;
}

.result-detail {
  color: inherit;
  opacity: 0.75;
  font-size: 13px;
  margin-left: auto;
}

.results-summary {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bni-gray-light);
  border-radius: 6px;
  font-size: 15px;
  color: var(--bni-gray-dark);
  text-align: center;
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 32px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--bni-gray-border);
  border-top: 4px solid var(--bni-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* ── Admin Dashboard ── */
.admin-container {
  max-width: 1100px;
  margin: 0 auto;
}

.admin-title {
  font-size: 24px;
  font-weight: 800;
  color: #1a1a1a;
  margin-bottom: 24px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-number {
  font-size: 36px;
  font-weight: 900;
  color: var(--bni-red);
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-top: 4px;
}

.admin-section-title {
  font-size: 18px;
  font-weight: 700;
  color: #333;
  margin-bottom: 12px;
  margin-top: 8px;
}

.table-wrapper {
  overflow-x: auto;
  margin-bottom: 32px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.admin-table thead {
  background: var(--bni-red);
  color: #fff;
}

.admin-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
}

.admin-table td {
  padding: 10px 16px;
  font-size: 13px;
  color: #333;
  border-bottom: 1px solid #f0f0f0;
}

.admin-table tbody tr:hover {
  background: #fafafa;
}

/* ── Badges ── */
.badge-admin {
  background: var(--bni-red);
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge-121 {
  background: #e3f2fd;
  color: #1565c0;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge-referral {
  background: #f3e5f5;
  color: #7b1fa2;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: #e8f5e9;
  color: #2e7d32;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge-fail {
  background: #ffebee;
  color: #c62828;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge-pending {
  background: #fff8e1;
  color: #f57f17;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

/* ── BNI Token / Login Section ── */
.token-section {
  margin-bottom: 8px;
}

.token-status {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.token-ok {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.token-needed {
  background: #fff8e1;
  color: #f57f17;
  border: 1px solid #ffe082;
}

.token-needed a {
  color: var(--bni-red);
  font-weight: 600;
}

.login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--bni-gray-border);
}

.tab-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--bni-gray-mid);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  font-family: inherit;
}

.tab-btn.active {
  color: var(--bni-red);
  border-bottom-color: var(--bni-red);
}

.tab-btn:hover {
  color: var(--bni-gray-dark);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.bni-status {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
}

.bni-connected {
  background: #e8f5e9;
  color: #2e7d32;
}

.bni-disconnected {
  background: #fff8e1;
  color: #f57f17;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .header {
    padding: 12px 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  .header-left {
    flex-wrap: wrap;
  }
  .header-brand {
    font-size: 18px;
  }
  .header-title {
    font-size: 18px;
  }
  .header-right {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
  }
  .header-nav {
    flex-wrap: wrap;
    gap: 4px;
  }
  .container { padding: 16px; }
  .page-card { padding: 16px; text-align: left; }
  .page-title { font-size: 20px; }
  .auth-card { margin: 30px 16px; padding: 28px 20px; }
  .admin-stats { grid-template-columns: 1fr; }
  .form-group { text-align: left; width: 100%; }
  .form-label { text-align: left; }
  .form-input, .form-textarea { text-align: left; width: 100%; }
  .form-row { flex-direction: column; gap: 0; }
  .form-row .form-group { flex: none !important; width: 100%; }
  .referral-entry .form-row { flex-direction: column; }
  .referral-entry .form-group { flex: none !important; width: 100%; }
  .checkbox-group { justify-content: flex-start; }
  .results-section { text-align: left; }
  .result-item { text-align: left; }
}
