/* ============================================================
   DerivPesa — Main Stylesheet
   Palette: Teal sage, white, deep forest greens
   ============================================================ */

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

:root {
  /* Color palette from the seed image */
  --white:        #FFFFFF;
  --off-white:    #F2F5F4;
  --teal-pale:    #C8DCDA;   /* lightest */
  --teal-light:   #89B5B0;   /* mid-light */
  --teal-mid:     #6A9E98;   /* primary teal */
  --teal-deep:    #3D6E69;   /* deep teal */
  --forest:       #1E3D38;   /* darkest green */
  --forest-dark:  #152B27;   /* sidebar bg */

  /* Semantic */
  --bg:           #F4F8F7;
  --surface:      #FFFFFF;
  --surface-2:    #EDF3F2;
  --border:       #D4E4E2;
  --border-light: #E8F0EF;
  --text:         #1A3330;
  --text-2:       #4A6B67;
  --text-3:       #7A9B97;
  --accent:       var(--teal-mid);
  --accent-hover: var(--teal-deep);
  --danger:       #D14343;
  --danger-bg:    #FEF0F0;
  --success:      #2D8A6E;
  --success-bg:   #EBF7F3;

  /* Type */
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  /* Space */
  --sidebar-w:    240px;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 2px 12px rgba(30,61,56,.08);
  --shadow-md:    0 6px 24px rgba(30,61,56,.12);
}

html { font-size: 15px; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth Layout ───────────────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

/* Background blobs */
.bg-blobs { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .18;
}
.blob-1 {
  width: 600px; height: 600px;
  background: var(--teal-mid);
  top: -150px; left: -150px;
}
.blob-2 {
  width: 400px; height: 400px;
  background: var(--teal-deep);
  bottom: -100px; right: -100px;
}
.blob-3 {
  width: 300px; height: 300px;
  background: var(--teal-pale);
  top: 50%; left: 55%;
}

.auth-container {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(900px, 96vw);
  min-height: 560px;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(30,61,56,.18);
}

/* Left branding panel */
.auth-left {
  background: linear-gradient(160deg, var(--forest) 0%, var(--forest-dark) 100%);
  padding: 52px 48px;
  display: flex;
  flex-direction: column;
  gap: 0;
  color: var(--white);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 64px;
}
.brand-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  display: grid;
  place-items: center;
}
.brand-name {
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: .02em;
}

.auth-hero { flex: 1; }
.auth-hero h1 {
  font-family: var(--font-display);
  font-size: 2.2rem;
  line-height: 1.2;
  color: var(--white);
  margin-bottom: 16px;
}
.auth-hero h1 em {
  font-style: italic;
  color: var(--teal-pale);
}
.auth-hero p {
  color: var(--teal-pale);
  font-size: .9rem;
  line-height: 1.7;
  opacity: .85;
}

.auth-features {
  margin-top: 48px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.feature-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .85rem;
  color: var(--teal-pale);
  opacity: .85;
}
.feature-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--teal-light);
  flex-shrink: 0;
}

/* Right form panel */
.auth-right {
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
}

.auth-card { width: 100%; max-width: 380px; }

.auth-card-header { margin-bottom: 32px; }
.auth-card-header h2 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  color: var(--text);
}
.auth-card-header p {
  color: var(--text-3);
  font-size: .9rem;
  margin-top: 4px;
}

/* Alerts */
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 20px;
}
.alert-error   { background: var(--danger-bg);  color: var(--danger);  }
.alert-success { background: var(--success-bg); color: var(--success); }

/* Form elements */
.auth-form { display: flex; flex-direction: column; gap: 20px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: .825rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .02em;
  text-transform: uppercase;
}

.input-wrap { position: relative; }
.input-wrap input {
  width: 100%;
  padding: 12px 44px 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .95rem;
  color: var(--text);
  background: var(--off-white);
  transition: border-color .2s, box-shadow .2s, background .2s;
  outline: none;
}
.input-wrap input:focus {
  border-color: var(--teal-mid);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(106,158,152,.15);
}
.input-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  display: none;
  pointer-events: none;
}
.toggle-pw {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--text-3); cursor: pointer;
  padding: 4px;
  transition: color .2s;
}
.toggle-pw:hover { color: var(--teal-mid); }

.form-row { display: flex; align-items: center; }

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-2);
  user-select: none;
}
.checkbox-label input[type="checkbox"] { display: none; }
.checkmark {
  width: 18px; height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  background: var(--off-white);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color .2s, background .2s;
}
.checkbox-label input:checked + .checkmark {
  background: var(--teal-mid);
  border-color: var(--teal-mid);
}
.checkbox-label input:checked + .checkmark::after {
  content: '';
  width: 5px; height: 9px;
  border: 2px solid white;
  border-top: none; border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

/* Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--teal-deep);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s, transform .15s, box-shadow .2s;
  letter-spacing: .01em;
}
.btn-primary:hover {
  background: var(--forest);
  box-shadow: 0 4px 16px rgba(30,61,56,.2);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-full { width: 100%; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .875rem;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-ghost:hover { border-color: var(--teal-mid); color: var(--teal-mid); }

.auth-footer-note {
  text-align: center;
  font-size: .8rem;
  color: var(--text-3);
  margin-top: 24px;
}

/* ── App Layout ────────────────────────────────────────────── */
.app-body {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--forest-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  padding: 24px 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 28px;
  color: var(--white);
  font-family: var(--font-display);
  font-size: 1.15rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 16px;
}
.sidebar-brand .brand-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: rgba(200,220,218,.7);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: background .2s, color .2s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: var(--teal-pale); }
.nav-item.active { background: rgba(137,181,176,.18); color: var(--teal-pale); }

.sidebar-footer {
  padding: 16px 16px 0;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.user-chip.inline { display: inline-flex; }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal-mid), var(--teal-deep));
  display: grid;
  place-items: center;
  color: white;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user-avatar.sm { width: 26px; height: 26px; font-size: .7rem; }
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-name {
  font-size: .8rem; font-weight: 600;
  color: rgba(255,255,255,.9);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role {
  font-size: .7rem;
  color: var(--teal-light);
  text-transform: capitalize;
}

.logout-btn {
  color: rgba(200,220,218,.5);
  padding: 6px;
  border-radius: 8px;
  transition: color .2s, background .2s;
  flex-shrink: 0;
}
.logout-btn:hover { color: var(--danger); background: rgba(209,67,67,.12); }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100vh;
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-header h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--forest);
  line-height: 1;
}
.header-sub {
  font-size: .875rem;
  color: var(--text-3);
  margin-top: 5px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Live badge */
.live-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 40px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-2);
}
.live-badge.live { color: var(--success); border-color: var(--success); background: var(--success-bg); }
.live-badge.error { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.7); }
}

/* Controls */
.header-controls { display: flex; align-items: center; gap: 8px; }
.ctrl-select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .85rem;
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.ctrl-select:focus { border-color: var(--teal-mid); }
.btn-refresh {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-refresh:hover { border-color: var(--teal-mid); color: var(--teal-mid); }
.btn-refresh.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Summary cards */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.summary-card {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}
.summary-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
}
.summary-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--text);
}
.summary-value.accent { color: var(--teal-deep); }

/* Filters */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.filter-search {
  padding: 9px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .875rem;
  background: var(--white);
  color: var(--text);
  outline: none;
  min-width: 260px;
  transition: border-color .2s;
}
.filter-search:focus { border-color: var(--teal-mid); }
.filter-pills { display: flex; gap: 6px; }
.pill {
  padding: 6px 14px;
  border-radius: 40px;
  border: 1.5px solid var(--border);
  background: var(--white);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all .2s;
}
.pill:hover { border-color: var(--teal-mid); color: var(--teal-mid); }
.pill.active {
  background: var(--teal-deep);
  border-color: var(--teal-deep);
  color: white;
}

/* Error banner */
.error-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  background: var(--danger-bg);
  border: 1px solid rgba(209,67,67,.2);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: .875rem;
}

/* Table */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  flex: 1;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table thead {
  background: var(--off-white);
  border-bottom: 1px solid var(--border);
}
.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  white-space: nowrap;
}
.data-table th.right,
.data-table td.right { text-align: right; }
.data-table th.center,
.data-table td.center { text-align: center; }
.data-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background .15s;
}
.data-table tbody tr:hover { background: #F7FBFA; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table td {
  padding: 13px 16px;
  color: var(--text);
  vertical-align: middle;
}
.mono { font-family: var(--font-mono); font-size: .82rem; color: var(--text-2); }

/* Transaction amount coloring */
.amount-positive { color: var(--success); font-weight: 600; font-family: var(--font-mono); }
.amount-negative { color: var(--danger);  font-weight: 600; font-family: var(--font-mono); }
.amount-zero     { color: var(--text-3);  font-weight: 500; font-family: var(--font-mono); }

/* Type badge */
.tx-type {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tx-deposit    { background: #EBF7F3; color: var(--success); }
.tx-withdrawal { background: var(--danger-bg); color: var(--danger); }
.tx-buy        { background: #EEF4FD; color: #3B6DC9; }
.tx-sell       { background: #F5EDFD; color: #7B3FC9; }
.tx-adjustment { background: var(--surface-2); color: var(--text-2); }
.tx-other      { background: var(--surface-2); color: var(--text-2); }

/* Loading, empty states */
.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 64px 32px;
  color: var(--text-3);
  font-size: .9rem;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--teal-mid);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Page footer */
.page-footer {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-3);
  padding-top: 8px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-admin { background: rgba(61,110,105,.15); color: var(--teal-deep); }
.badge-user  { background: var(--surface-2);      color: var(--text-2); }

.status-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem;
}
.status-dot::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
}
.status-dot.active::before  { background: var(--success); }
.status-dot.inactive::before { background: var(--text-3); }

/* Token cell */
.token-cell { font-size: .78rem; color: var(--text-3); letter-spacing: .05em; }

/* Actions */
.actions-cell { white-space: nowrap; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.edit-btn   { background: #EEF4FD; color: #3B6DC9; }
.delete-btn { background: var(--danger-bg); color: var(--danger); }
.edit-btn:hover   { background: #D8E8FB; }
.delete-btn:hover { background: #FAD7D7; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20,40,36,.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: 16px;
  width: min(560px, 100%);
  box-shadow: 0 24px 60px rgba(20,40,36,.25);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--forest);
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--off-white);
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background .15s;
}
.modal-close:hover { background: var(--border); }
.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  background: var(--off-white);
}

/* Form grid */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--text);
  background: var(--off-white);
  outline: none;
  transition: border-color .2s, background .2s;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--teal-mid);
  background: var(--white);
}
.req { color: var(--danger); }
.hint { font-weight: 400; color: var(--text-3); font-size: .75rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 300;
  animation: slideUp .3s ease;
}
.toast.success { background: var(--success); color: white; }
.toast.error   { background: var(--danger);  color: white; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 800px) {
  .auth-container { grid-template-columns: 1fr; }
  .auth-left      { display: none; }
  .summary-grid   { grid-template-columns: 1fr 1fr; }
  .main-content   { padding: 20px 16px; }
  .form-row-2     { grid-template-columns: 1fr; }
  .sidebar        { display: none; }
  .main-content   { margin-left: 0; }
}