:root {
  --sidebar-width: 260px;
  --sidebar-bg: #0f172a;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #94a3b8;
  --sidebar-active: #2563eb;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --topbar-height: 4rem;
  --content-bg: #f1f5f9;
  --surface: #ffffff;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  --text-muted: #64748b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 0.75rem;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--content-bg);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* -------------------------------------------------------------------------- */
/* Brand                                                                      */
/* -------------------------------------------------------------------------- */

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: #fff;
}

.app-brand-lg .app-brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.95rem;
}

.app-brand-lg .app-brand-text {
  font-size: 1.125rem;
}

.app-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.625rem;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.app-brand-text {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* -------------------------------------------------------------------------- */
/* App shell                                                                  */
/* -------------------------------------------------------------------------- */

.app-layout {
  min-height: 100vh;
}

.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--content-bg);
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1010;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--topbar-height);
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.app-topbar-start,
.app-topbar-end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-page-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.app-user-name {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.app-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.app-menu-icon {
  display: inline-block;
  width: 0.875rem;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
}

.app-content {
  flex: 1;
  padding: 1.5rem;
}

.app-footer {
  padding: 1rem 1.5rem 1.5rem;
}

@media (min-width: 992px) {
  .app-content {
    padding: 1.75rem 2rem;
  }

  .app-footer {
    padding: 1rem 2rem 2rem;
  }
}

@media (max-width: 991.98px) {
  .app-main {
    margin-left: 0;
    width: 100%;
  }
}

/* -------------------------------------------------------------------------- */
/* Sidebar                                                                    */
/* -------------------------------------------------------------------------- */

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  z-index: 1020;
  overflow-y: auto;
}

.app-sidebar-header {
  padding: 0 0.5rem 1.25rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.app-sidebar-section {
  margin-bottom: 0.5rem;
}

.app-sidebar-label {
  display: block;
  padding: 0.5rem 0.75rem 0.375rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-text-muted);
}

.app-sidebar .nav-link,
.app-sidebar-offcanvas .nav-link {
  display: flex;
  align-items: center;
  color: var(--sidebar-text);
  border-radius: 0.5rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.925rem;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar .nav-link:hover,
.app-sidebar-offcanvas .nav-link:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.app-sidebar .nav-link.active,
.app-sidebar-offcanvas .nav-link.active {
  color: #fff;
  background: var(--sidebar-active);
}

.app-sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--sidebar-border);
}

.app-sidebar-offcanvas {
  width: min(var(--sidebar-width), 85vw);
  background: var(--sidebar-bg);
  color: #fff;
}

.app-sidebar-offcanvas .offcanvas-header {
  border-bottom: 1px solid var(--sidebar-border);
}

.app-sidebar-offcanvas .offcanvas-title,
.app-sidebar-offcanvas .btn-close {
  color: #fff;
}

.app-sidebar-offcanvas .btn-close {
  filter: invert(1) grayscale(1);
  opacity: 0.75;
}

/* -------------------------------------------------------------------------- */
/* Auth layout                                                                */
/* -------------------------------------------------------------------------- */

.auth-layout {
  min-height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 28%, var(--content-bg) 28%);
}

.auth-layout-header .app-brand {
  justify-content: center;
}

.auth-layout-main {
  max-width: 28rem;
}

/* -------------------------------------------------------------------------- */
/* Dashboard stat cards                                                       */
/* -------------------------------------------------------------------------- */

.stat-card {
  height: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card-body {
  padding: 1.25rem 1.5rem;
}

.stat-card-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.stat-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.stat-card-meta {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stat-card-accent {
  width: 0.25rem;
  border-radius: var(--radius) 0 0 var(--radius);
}

.stat-card-accent-primary { background: #3b82f6; }
.stat-card-accent-success { background: #22c55e; }
.stat-card-accent-warning { background: #f59e0b; }
.stat-card-accent-info { background: #06b6d4; }

/* -------------------------------------------------------------------------- */
/* Cards & tables                                                             */
/* -------------------------------------------------------------------------- */

.card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 1.25rem;
}

.card-table .table {
  margin-bottom: 0;
}

.card-table .table > :not(caption) > * > * {
  padding: 0.875rem 1.25rem;
}

.table {
  --bs-table-bg: transparent;
  color: var(--text-primary);
}

.table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom-width: 1px;
  white-space: nowrap;
}

.table-hover > tbody > tr:hover > * {
  background-color: #f8fafc;
}

.table code {
  font-size: 0.8rem;
  color: #334155;
  background: #f1f5f9;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
}

.badge {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.page-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.page-section-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

.breadcrumb {
  --bs-breadcrumb-divider-color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}

.breadcrumb-item a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb-item a:hover {
  color: #2563eb;
}

/* -------------------------------------------------------------------------- */
/* Forms & buttons                                                            */
/* -------------------------------------------------------------------------- */

.form-control,
.form-select {
  border-color: var(--border-color);
  border-radius: 0.5rem;
}

.form-control:focus,
.form-select:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.15);
}

.btn {
  border-radius: 0.5rem;
  font-weight: 500;
}

.btn-primary {
  background-color: #2563eb;
  border-color: #2563eb;
}

.btn-primary:hover,
.btn-primary:focus {
  background-color: #1d4ed8;
  border-color: #1d4ed8;
}

.alert {
  border-radius: var(--radius);
  border: 1px solid transparent;
}

/* -------------------------------------------------------------------------- */
/* Log output                                                                 */
/* -------------------------------------------------------------------------- */

.log-output {
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 32rem;
  overflow: auto;
  border-radius: 0.5rem;
}

code {
  color: #334155;
}
