/* ===== RESET & VARIABLES ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #1a56db;
  --primary-dark:  #1547c0;
  --success:       #059669;
  --warning:       #d97706;
  --danger:        #dc2626;
  --info:          #7c3aed;

  --bg:            #f1f5f9;
  --card:          #ffffff;
  --border:        #e2e8f0;

  --text-1:        #1e293b;
  --text-2:        #64748b;
  --text-3:        #94a3b8;

  --sidebar-bg:    #1e2a3b;
  --sidebar-w:     220px;

  --radius:        8px;
  --radius-lg:     12px;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
  --shadow:        0 1px 3px rgba(0,0,0,.10), 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,.05);
  --shadow-lg:     0 10px 25px rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.td-center { text-align: center; color: var(--text-2); padding: 40px !important; }

/* ===== LOGIN ===== */
.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1e2a3b 0%, #1a56db 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-paw { font-size: 40px; display: block; margin-bottom: 10px; }
.login-logo h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.login-logo p { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.login-hint { text-align: center; margin-top: 16px; font-size: 12px; color: var(--text-3); }
.login-hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--text-1); margin-bottom: 5px;
}
.form-group input, .form-group select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text-1); background: var(--card);
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 8px 16px; border: none; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, box-shadow .15s; white-space: nowrap;
  text-decoration: none; line-height: 1;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-dark); }
.btn-secondary { background: var(--card); color: var(--text-1); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled)  { background: #047857; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; }
.btn-text     { background: none; color: var(--primary); padding: 4px 8px; }
.btn-text:hover { text-decoration: underline; }
.btn-full     { width: 100%; }
.btn-sm       { padding: 5px 10px; font-size: 12px; }

/* ===== LAYOUT ===== */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg);
  display: flex; flex-direction: column; flex-shrink: 0;
  transition: width .2s; overflow: hidden;
  z-index: 100;
}
.sidebar.collapsed { width: 52px; }
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 14px; border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-logo { display: flex; align-items: center; gap: 9px; color: #fff; font-weight: 700; font-size: 15px; }
.logo-paw { font-size: 18px; flex-shrink: 0; }
.logo-text { white-space: nowrap; overflow: hidden; transition: opacity .2s; }
.sidebar.collapsed .logo-text { opacity: 0; width: 0; }
.sidebar-toggle {
  background: none; border: none; color: #94a3b8; cursor: pointer;
  font-size: 17px; padding: 2px; border-radius: 4px; flex-shrink: 0;
  transition: color .15s;
}
.sidebar-toggle:hover { color: #fff; }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; overflow-x: hidden; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 14px; color: #94a3b8; text-decoration: none;
  cursor: pointer; background: none; border: none; width: 100%;
  font-size: 13.5px; transition: background .12s, color .12s;
  border-left: 3px solid transparent; white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(26,86,219,.25); color: #fff; border-left-color: var(--primary); }
.nav-danger:hover { color: #fc8181 !important; }
.nav-icon { font-size: 15px; flex-shrink: 0; }
.nav-label { transition: opacity .2s; overflow: hidden; }
.sidebar.collapsed .nav-label { opacity: 0; width: 0; }
.sidebar.collapsed .nav-item { padding: 10px 14px; justify-content: center; }
.sidebar.collapsed .nav-item { border-left: none; }

.sidebar-footer { padding: 8px 0; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 99;
}

/* ===== MAIN ===== */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.main-header {
  background: var(--card); border-bottom: 1px solid var(--border);
  height: 58px; padding: 0 22px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.header-left { display: flex; align-items: center; gap: 14px; }
.header-left h1 { font-size: 17px; font-weight: 600; }
.mobile-menu-btn {
  display: none; background: none; border: none;
  font-size: 20px; cursor: pointer; color: var(--text-2);
}
.header-right { display: flex; align-items: center; gap: 10px; }
.last-sync-label { font-size: 12px; color: var(--text-3); }

.sync-icon { display: inline-block; transition: transform .3s; }
.sync-icon.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SECTIONS ===== */
.content-section {
  display: none; flex: 1; padding: 22px;
  overflow-y: auto; overflow-x: hidden;
}
.content-section.active { display: block; }

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px 16px; display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.bg-blue   { background: #eff6ff; }
.bg-amber  { background: #fffbeb; }
.bg-green  { background: #ecfdf5; }
.bg-slate  { background: #f1f5f9; }
.bg-indigo { background: #eef2ff; }
.bg-purple { background: #f5f3ff; }

.stat-value { display: block; font-size: 26px; font-weight: 800; letter-spacing: -1px; }
.stat-label { display: block; font-size: 11.5px; color: var(--text-2); margin-top: 1px; }

/* ===== CHARTS ===== */
.charts-grid {
  display: grid; grid-template-columns: 280px 1fr;
  gap: 14px; margin-bottom: 20px;
}
.chart-card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.chart-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-2); margin-bottom: 14px;
}
.chart-wrap { position: relative; height: 210px; }

/* ===== CARDS ===== */
.section-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-header h3 { font-size: 14px; font-weight: 600; }

/* ===== BADGE ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
}
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-slate  { background: #f1f5f9; color: #475569; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ===== PENDING LIST ===== */
.pending-list { padding: 8px 18px; }
.pending-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.pending-item:last-child { border-bottom: none; }
.pending-info { flex: 1; min-width: 0; }
.pending-name { font-weight: 600; font-size: 14px; }
.pending-meta { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===== ACTIVITY LIST ===== */
.activity-list { padding: 4px 0; }
.activity-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.act-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0; margin-top: 6px;
}
.dot-payment     { background: var(--success); }
.dot-emission    { background: var(--primary); }
.dot-registration{ background: var(--info); }
.dot-coupon      { background: var(--warning); }
.act-text { font-size: 13.5px; }
.act-time { font-size: 12px; color: var(--text-3); }

/* ===== EMPTY STATE ===== */
.empty-state {
  padding: 36px 18px; text-align: center;
  color: var(--text-2); font-size: 13.5px;
}

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.search-wrap { flex: 1; min-width: 200px; position: relative; }
.search-wrap::before {
  content: "🔍"; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 13px; pointer-events: none;
}
.search-wrap input {
  width: 100%; padding: 8px 12px 8px 32px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13.5px; background: var(--card);
  transition: border-color .15s, box-shadow .15s;
}
.search-wrap input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-group select {
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px; background: var(--card); cursor: pointer;
}

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: #f8fafc; padding: 9px 14px;
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbfc; }

.dog-cell { display: flex; align-items: center; gap: 9px; }
.dog-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: #e2e8f0; border: 2px solid var(--border);
}
.dog-avatar-placeholder {
  width: 34px; height: 34px; border-radius: 50%;
  background: #e2e8f0; display: flex; align-items: center;
  justify-content: center; font-size: 15px; flex-shrink: 0;
}
.dog-name  { font-weight: 600; font-size: 13.5px; }
.dog-owner { font-size: 12px; color: var(--text-2); }

.score-pill {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; font-weight: 700; font-size: 12px;
}
.score-high { background: #d1fae5; color: #065f46; }
.score-mid  { background: #fef3c7; color: #92400e; }

.coupon-code {
  font-family: 'Courier New', monospace; font-size: 12px; font-weight: 700;
  background: #f1f5f9; padding: 2px 7px; border-radius: 5px; letter-spacing: .5px;
}
.ambassador-code {
  background: #fef3c7; color: #92400e;
}

.row-actions { display: flex; gap: 5px; }

/* ===== AMBASSADOR REPORT ===== */
.ambassador-report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.ambassador-report-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.amb-card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px;
}
.amb-card-name { font-weight: 700; font-size: 15px; color: var(--text-1); }
.amb-card-dog  { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.amb-card-uses {
  background: #fef3c7; color: #92400e;
  font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
  white-space: nowrap;
}
.amb-card-stats { display: flex; gap: 12px; }
.amb-stat {
  flex: 1; background: var(--bg);
  border-radius: var(--radius); padding: 10px 12px;
}
.amb-stat-label { display: block; font-size: 11px; color: var(--text-2); margin-bottom: 4px; }
.amb-stat-value { display: block; font-size: 16px; font-weight: 700; color: var(--text-1); }
.amb-commission { color: #92400e !important; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 14px;
}
.page-info { font-size: 12.5px; color: var(--text-2); }

/* ===== RECORD CARDS (mobile) ===== */
.rec-cards { display: none; flex-direction: column; gap: 10px; }
.rec-card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 9px;
}
.rec-card-top    { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rec-card-meta   { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.rec-card-actions{ display: flex; gap: 6px; }

/* ===== LOGS ===== */
.logs-list { }
.log-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px; border-bottom: 1px solid var(--border);
}
.log-item:last-child { border-bottom: none; }
.log-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.log-payment     { background: #d1fae5; }
.log-emission    { background: #dbeafe; }
.log-registration{ background: #ede9fe; }
.log-coupon      { background: #fef3c7; }
.log-body { flex: 1; min-width: 0; }
.log-text { font-size: 13.5px; }
.log-type { font-size: 11.5px; color: var(--text-2); }
.log-time { font-size: 12px; color: var(--text-3); white-space: nowrap; flex-shrink: 0; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 16px;
}
.modal {
  background: var(--card); border-radius: var(--radius-lg);
  width: 100%; max-width: 500px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-lg { max-width: 680px; }
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.btn-close {
  background: none; border: none; font-size: 17px; cursor: pointer;
  color: var(--text-2); padding: 3px; border-radius: 4px; line-height: 1;
}
.btn-close:hover { background: var(--bg); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0;
}

/* Config sections */
.config-section { margin-bottom: 22px; }
.config-section h3 {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-2); margin-bottom: 12px;
  padding-bottom: 7px; border-bottom: 1px solid var(--border);
}
.cfg-badge-rec {
  background: #dbeafe; color: #1e40af;
  font-size: 10px; padding: 1px 6px; border-radius: 10px;
  font-weight: 700; margin-left: 5px; vertical-align: middle;
}
.cfg-hint {
  display: block; margin-top: 5px;
  font-size: 11.5px; color: var(--text-2); line-height: 1.5;
}
.cfg-hint a { color: var(--primary); }
.cfg-collapse-btn {
  background: none; border: none; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  padding: 0; display: flex; align-items: center; gap: 6px;
  text-transform: uppercase; letter-spacing: .5px;
  width: 100%; padding-bottom: 7px; border-bottom: 1px solid var(--border);
}
.cfg-collapse-btn:hover { color: var(--text-1); }

/* Detail layout */
.detail-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px; background: var(--bg); border-radius: var(--radius);
  margin-bottom: 18px;
}
.detail-dog-img {
  width: 60px; height: 60px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--border);
  background: #e2e8f0; flex-shrink: 0;
}
.detail-dog-name  { font-size: 18px; font-weight: 800; }
.detail-dog-breed { font-size: 13px; color: var(--text-2); }
.detail-score {
  margin-left: auto; text-align: center;
}
.detail-score-num  { display: block; font-size: 34px; font-weight: 900; line-height: 1; }
.detail-score-denom{ display: block; font-size: 11px; color: var(--text-2); }

.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px;
}
.detail-field label {
  display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .4px; color: var(--text-2); margin-bottom: 3px;
}
.detail-field span { font-size: 13.5px; word-break: break-all; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%;
    transform: translateX(-100%); z-index: 200; width: var(--sidebar-w) !important;
    transition: transform .2s;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }

  .mobile-menu-btn { display: flex !important; }
  .sidebar-toggle { display: none; }
  .logo-text, .nav-label { opacity: 1 !important; width: auto !important; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .content-section { padding: 14px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: 0; }

  #rec-table-wrap { display: none; }
  .rec-cards { display: flex; }

  .detail-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 22px; }
}
