/* ===== CSS Variables ===== */
:root {
  --primary: #0ea56b;
  --primary-light: #e6f6ef;
  --primary-dark: #0b8a59;
  --bg: #f7f8fa;
  --white: #fff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0 0 0.5rem; font-weight: 600; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== App Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  overflow-y: auto;
}

.brand {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand__title {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.brand__sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav__item:hover {
  background: var(--bg);
  text-decoration: none;
}

.nav__item.is-active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav__item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav__divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.nav__label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 14px 4px;
}

/* ===== Main Content ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-height);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar__spacer { flex: 1; }

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

.iconbtn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.iconbtn:hover { background: var(--bg); }
.iconbtn svg { width: 20px; height: 20px; color: var(--text); }

.userpill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  background: var(--bg);
  border-radius: 50px;
  border: 1px solid var(--border);
}

.userpill__avatar {
  width: 36px;
  height: 36px;
  background: var(--primary-light);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--primary);
}

.userpill__avatar svg { width: 18px; height: 18px; }

.userpill__email {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.userpill__role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Content Area ===== */
.content {
  padding: 24px;
  flex: 1;
}

/* ===== Page Title ===== */
.page-title {
  margin-bottom: 24px;
}

.page-title h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ===== Grid System ===== */
.grid {
  display: grid;
  gap: 20px;
}

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

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

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

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

/* ===== Cards ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.card-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card-actions {
  display: flex;
  gap: 8px;
}

/* Stat Card Variants */
.card--stat {
  position: relative;
  overflow: hidden;
}

.card--stat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius) 0 0 var(--radius);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg);
  text-decoration: none;
  border-color: #d1d5db;
}

.btn--primary {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.btn--primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn--sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  margin: 0 -20px -20px;
  padding: 0 20px 20px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
}

.table tbody tr:hover {
  background: #fafbfc;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 50px;
  text-transform: capitalize;
  background: var(--bg);
  color: var(--text-muted);
}

.badge.paid,
.badge.success,
.badge.active {
  background: #dcfce7;
  color: #166534;
}

.badge.used {
  background: #dbeafe;
  color: #1e40af;
}

.badge.pending,
.badge.processing {
  background: #fef3c7;
  color: #92400e;
}

.badge.failed,
.badge.cancelled,
.badge.expired {
  background: #fee2e2;
  color: #991b1b;
}

/* ===== Code ===== */
code {
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.8125rem;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}

/* ===== Utilities ===== */
.mt-16 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.text-center { text-align: center; }
.hidden { display: none; }

/* ===== Mobile Overlay ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

/* ===== Responsive Styles ===== */

/* Tablet */
@media (max-width: 1024px) {
  .grid--5 {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-open .sidebar-overlay {
    display: block;
  }

  .main {
    margin-left: 0;
  }

  .iconbtn {
    display: flex;
  }

  .topbar {
    padding: 12px 16px;
  }

  .content {
    padding: 16px;
  }

  .page-title h2 {
    font-size: 1.5rem;
  }

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

  .card {
    padding: 16px;
  }

  .card-value {
    font-size: 1.75rem;
  }

  .userpill__email,
  .userpill__role {
    display: none;
  }

  .userpill {
    padding: 6px;
    border-radius: 50%;
  }

  .btn-row {
    flex-direction: column;
  }

  .btn-row .btn {
    width: 100%;
  }

  .table-wrap {
    margin: 0 -16px -16px;
    padding: 0 16px 16px;
  }

  .table th,
  .table td {
    padding: 10px 12px;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .grid--5,
  .grid--4,
  .grid--3,
  .grid--2 {
    grid-template-columns: 1fr;
  }

  .card-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-actions {
    width: 100%;
  }

  .card-actions .btn {
    flex: 1;
  }

  .table {
    font-size: 0.8125rem;
  }

  .table th,
  .table td {
    padding: 8px 10px;
  }

  /* Hide less important columns on very small screens */
  .table th:nth-child(4),
  .table td:nth-child(4) {
    display: none;
  }
}

/* ===== Platform Layout Responsive ===== */
.platform-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: 80;
}

.platform-menu-toggle:hover { background: var(--bg); }

.platform-menu-toggle svg {
  width: 20px;
  height: 20px;
  color: var(--text);
}

.platform-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

.platform-sidebar {
  transition: transform 0.3s ease;
}

@media (max-width: 768px) {
  .platform-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    overflow-y: auto;
  }

  .platform-sidebar-open .platform-sidebar {
    transform: translateX(0);
  }

  .platform-sidebar-open .platform-sidebar-overlay {
    display: block;
  }

  .platform-menu-toggle {
    display: flex;
  }

  .platform-header {
    padding: 12px 16px 12px 68px !important;
    gap: 12px;
  }

  .platform-header h2 {
    font-size: 1.25rem;
  }

  .platform-content {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }

  .user-menu .user-name,
  .user-menu .user-role {
    display: none;
  }

  .filter-tabs {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .platform-header {
    flex-wrap: wrap;
  }
}

/* ===== Print Styles ===== */
@media print {
  .sidebar,
  .topbar,
  .btn-row {
    display: none;
  }

  .main {
    margin-left: 0;
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
