/* =============================================
   ADMIN PANEL – APP SHELL + CORE UI
   Sidebar + topbar layout, cards, stats, tables, charts.
   ============================================= */

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button { font-family: inherit; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* =============================================
   APP GRID (sidebar + main)
   ============================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.2s ease;
}

.app.is-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) 1fr;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 40;
}

.sidebar__brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--color-sidebar-border);
  flex-shrink: 0;
}

.sidebar__logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar__brand-name {
  color: var(--color-sidebar-text-active);
  font-weight: 700;
  font-size: var(--font-size-lg);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar__section {
  padding: 14px 12px 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--color-sidebar-text);
  font-size: var(--font-size-sm);
  font-weight: 400;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar__link svg { flex-shrink: 0; }

.sidebar__link:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-text-active);
}

.sidebar__link.is-active {
  background: var(--color-sidebar-active);
  color: var(--color-sidebar-text-active);
  font-weight: 600;
}

.sidebar__link--danger { color: var(--color-danger); }
.sidebar__link--danger:hover { background: var(--color-sidebar-hover); color: #f87171; }

.sidebar__label { overflow: hidden; }

.sidebar__foot {
  padding: 12px 8px;
  border-top: 1px solid var(--color-sidebar-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Collapsed state: hide text, center icons */
.app.is-collapsed .sidebar__brand-name,
.app.is-collapsed .sidebar__label,
.app.is-collapsed .sidebar__section {
  display: none;
}

.app.is-collapsed .sidebar__brand { padding: 0 22px; }
.app.is-collapsed .sidebar__link { justify-content: center; padding: 10px 14px; }

/* =============================================
   TOPBAR
   ============================================= */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar__toggle,
.topbar__mobile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s ease;
}

.topbar__toggle:hover,
.topbar__mobile:hover { background: var(--color-surface-hover); }

.topbar__mobile { display: none; }

.topbar__search {
  position: relative;
  display: flex;
  align-items: center;
}

.topbar__search svg {
  position: absolute;
  left: 10px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.topbar__search input {
  width: 240px;
  height: 36px;
  padding: 0 12px 0 34px;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.topbar__search input:focus {
  background: var(--color-surface);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

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

.topbar__icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s ease;
}

.topbar__icon-btn:hover { background: var(--color-surface-hover); }

.topbar__dot {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-danger);
  border: 2px solid var(--color-surface);
}

.topbar__user {
  position: relative;
}

.topbar__user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease;
}

.topbar__user-btn:hover { background: var(--color-surface-hover); }

.topbar__user-name {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text);
}

.topbar__user-caret { color: var(--color-text-muted); transition: transform 0.15s ease; }
.topbar__user.is-open .topbar__user-caret { transform: rotate(180deg); }

@media (max-width: 640px) {
  .topbar__user-name { display: none; }
  .topbar__search input { width: 160px; }
}

/* =============================================
   PAGE CONTENT
   ============================================= */
.content {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-head__title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  margin-bottom: 4px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.breadcrumb a:hover { color: var(--color-text-secondary); }
.breadcrumb__sep { opacity: 0.6; }

.page-head__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Layout helpers */
.grid { display: grid; gap: 20px; }
.grid--stats { grid-template-columns: repeat(4, 1fr); }
.grid--charts { grid-template-columns: 1.6fr 1fr; }

@media (max-width: 1100px) {
  .grid--stats { grid-template-columns: repeat(2, 1fr); }
  .grid--charts { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid--stats { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

/* =============================================
   CARD
   ============================================= */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border-light);
}

.card__title { font-size: var(--font-size-base); font-weight: 600; }
.card__subtitle { font-size: var(--font-size-sm); color: var(--color-text-muted); margin-top: 2px; }
.card__body { padding: 20px 24px; }
.card--hover { transition: box-shadow 0.2s ease, border-color 0.2s ease; }
.card--hover:hover { box-shadow: var(--shadow-md); border-color: var(--color-primary); }

/* =============================================
   STAT CARD
   ============================================= */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.stat-card__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.stat-card__value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  margin: 4px 0;
}

.stat-card__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-xs);
  font-weight: 500;
}

.stat-card__delta .muted { color: var(--color-text-muted); font-weight: 400; }
.stat-card__delta.is-up { color: var(--color-success); }
.stat-card__delta.is-down { color: var(--color-danger); }

.stat-card__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--accent-blue-light);
  color: var(--accent-blue);
}

.stat-card__icon--blue    { background: var(--accent-blue-light);    color: var(--accent-blue); }
.stat-card__icon--violet  { background: var(--accent-violet-light);  color: var(--accent-violet); }
.stat-card__icon--emerald { background: var(--accent-emerald-light); color: var(--accent-emerald); }
.stat-card__icon--amber   { background: var(--accent-amber-light);   color: var(--accent-amber); }

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.5rem 1rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.5;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn svg { width: 16px; height: 16px; }

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

.btn--secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn--secondary:hover { background: var(--color-surface-hover); border-color: var(--color-text-muted); }

.btn--danger { background: var(--color-danger); color: #fff; }
.btn--danger:hover { background: var(--color-danger-hover); }

.btn--ghost { background: transparent; color: var(--color-text-secondary); }
.btn--ghost:hover { background: var(--color-surface-hover); color: var(--color-text); }

.btn--sm { padding: 0.3125rem 0.75rem; font-size: var(--font-size-xs); }
.btn--lg { padding: 0.6875rem 1.5rem; font-size: var(--font-size-base); }
.btn--icon { padding: 0.5rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* =============================================
   BADGE / STATUS PILL
   ============================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.125rem 0.625rem;
  font-size: var(--font-size-xs);
  font-weight: 500;
  line-height: 1.5;
  border-radius: 9999px;
}

.badge--success { background: var(--color-success-light); color: var(--color-success-text); }
.badge--warning { background: var(--color-warning-light); color: var(--color-warning-text); }
.badge--danger  { background: var(--color-danger-light);  color: var(--color-danger-hover); }
.badge--info    { background: var(--color-primary-light); color: var(--color-primary); }
.badge--neutral { background: var(--color-bg);            color: var(--color-text-secondary); }

.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* =============================================
   TABLE
   ============================================= */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.table thead th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 500;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}

.table th.is-sortable { cursor: pointer; }

.table th.is-sortable .th-inner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.table th.is-sortable .th-inner::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid var(--color-text-muted);
  opacity: 0.5;
}

.table th.is-sortable:hover .th-inner::after { opacity: 1; }

.table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  white-space: nowrap;
  color: var(--color-text-secondary);
}

.table tbody tr { transition: background 0.1s ease; }
.table tbody tr:hover { background: var(--color-surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }

.table__user { display: flex; align-items: center; gap: 10px; }
.table__user-name { color: var(--color-text); font-weight: 500; }
.table__user-mail { color: var(--color-text-muted); font-size: var(--font-size-xs); }

.table__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-light);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* =============================================
   CHART (inline SVG)
   ============================================= */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }

.chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.chart__legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart__swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.chart-line { fill: none; stroke: var(--color-primary); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#areaGradient); }
.chart-grid { stroke: var(--color-border-light); stroke-width: 1; }
.chart-axis { fill: var(--color-text-muted); font-size: 11px; }
.chart-dot { fill: var(--color-surface); stroke: var(--color-primary); stroke-width: 2.5; }
.chart-bar { fill: var(--color-primary); rx: 4; transition: fill 0.15s ease; }
.chart-bar:hover { fill: var(--color-primary-hover); }
.chart-bar--muted { fill: var(--color-primary-light); }

/* =============================================
   FOOTER + BADGE LINE
   ============================================= */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 4px 4px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border-light);
}

.app-footer a:hover { color: var(--color-text-secondary); }

/* =============================================
   REVEAL (optional entrance)
   ============================================= */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .reveal { opacity: 1; transform: none; }
}

/* =============================================
   MOBILE SIDEBAR
   ============================================= */
.sidebar__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 45;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .app.is-collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 50;
  }
  .app.is-mobile-open .sidebar { transform: translateX(0); }
  .app.is-mobile-open .sidebar__backdrop { display: block; }
  /* On mobile the collapsed rules must not hide labels */
  .app.is-collapsed .sidebar__brand-name,
  .app.is-collapsed .sidebar__label,
  .app.is-collapsed .sidebar__section { display: revert; }
  .app.is-collapsed .sidebar__link { justify-content: flex-start; padding: 10px 12px; }
  .topbar__toggle { display: none; }
  .topbar__mobile { display: inline-flex; }
}
