/* =========================================================
 * CSS VARIABLES (Light & Dark Theme System)
 * ========================================================= */
:root {
  /* Brand Colors */
  --primary: #4f46e5;
  /* Indigo 600 */
  --primary-hover: #4338ca;
  --primary-soft: #e0e7ff;

  /* Semantic Colors */
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  /* Light Mode Fundamentals */
  --bg-app: #f8fafc;
  /* Slate 50 */
  --bg-panel: #ffffff;
  --bg-sidebar: #0f172a;
  /* Slate 900 */
  --bg-glass: rgba(255, 255, 255, 0.7);

  /* Text */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-sidebar: #94a3b8;
  --text-sidebar-hover: #f8fafc;

  /* Borders & UI Elements */
  --border: #e2e8f0;
  /* Slate 200 */
  --input-bg: #f1f5f9;
  --input-border: #cbd5e1;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-glass: 0 4px 30px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  --primary: #6366f1;
  /* Indigo 500 */
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.15);

  --bg-app: #0f172a;
  /* Slate 900 */
  --bg-panel: #1e293b;
  /* Slate 800 */
  --bg-sidebar: #020617;
  /* Slate 950 */
  --bg-glass: rgba(30, 41, 59, 0.7);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sidebar: #64748b;

  --border: #334155;
  /* Slate 700 */
  --input-bg: #0f172a;
  --input-border: #475569;
}

/* =========================================================
   * BASE & RESET
   * ========================================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow: hidden;
  /* App takes full height, scroll inside */
}

.hidden {
  display: none !important;
}

.mt-8 {
  margin-top: 8px;
}

.mt-16 {
  margin-top: 16px;
}

.mt-24 {
  margin-top: 24px;
}

.mb-24 {
  margin-bottom: 24px;
}

.pt-16 {
  padding-top: 16px;
}

.pb-16 {
  padding-bottom: 16px;
}

.border-top {
  border-top: 1px solid var(--border);
}

.border-bottom {
  border-bottom: 1px solid var(--border);
}

.text-success {
  color: var(--success);
  font-weight: 600;
}

/* =========================================================
   * AUTHENTICATION VIEW
   * ========================================================= */
.auth-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  background: radial-gradient(circle at top left, var(--primary-soft), transparent 50%), var(--bg-app);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 30px;
  border-radius: 20px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
}

.brand-logo.small {
  width: 32px;
  height: 32px;
  font-size: 14px;
  margin-bottom: 0;
}

.auth-header h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.auth-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  padding: 4px;
  background: var(--input-bg);
  border-radius: 8px;
}

.auth-tabs .tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.2s;
}

.auth-tabs .tab.active {
  background: var(--bg-panel);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

/* =========================================================
   * LAYOUT: SIDEBAR & MAIN CONTENT
   * ========================================================= */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  width: 100vw;
}

.sidebar {
  background-color: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header {
  height: 70px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.brand-name {
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.5px;
}

.sidebar-nav {
  flex: 1;
  padding: 24px 12px;
  overflow-y: auto;
}

.nav-group {
  margin-bottom: 24px;
}

.nav-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 12px 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.4);
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-sidebar);
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-item:hover {
  color: var(--text-sidebar-hover);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.user-role {
  font-size: 12px;
  opacity: 0.7;
  text-transform: capitalize;
}

.main-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

.top-header {
  height: 70px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.breadcrumbs {
  font-weight: 600;
  font-size: 18px;
}

.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.page-view {
  max-width: 1200px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   * COMPONENTS: PANELS, FORMS, BUTTONS
   * ========================================================= */
.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  margin-bottom: 16px;
}

.panel-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.grid {
  display: grid;
  gap: 16px;
}

.two {
  grid-template-columns: 1fr 1fr;
}

.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.span-two {
  grid-column: span 2;
}

.span-three {
  grid-column: span 3;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  min-width: 0;
  /* Prevents long text from pushing the width wider than the grid cell */
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
  font-family: inherit;
  text-overflow: ellipsis;
  /* Gracefully truncates long text visual overflows */
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.form-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.form-checkbox label {
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  font-family: inherit;
}

.btn.primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn.primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn.secondary {
  background: var(--bg-app);
  border-color: var(--border);
  color: var(--text-main);
}

.btn.secondary:hover {
  background: var(--border);
}

.btn.small {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

header .icon-btn:hover {
  background: var(--border);
}

/* =========================================================
   * DASHBOARD SPECIFICS (Stats, Tables, Logs, Cards)
   * ========================================================= */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.stat-card {
  padding: 24px;
}

.stat-title {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
}

/* Tables */
.table-wrapper {
  padding: 0;
  overflow-x: auto;
}

.saas-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.saas-table th {
  padding: 16px 24px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  background: var(--bg-app);
}

.saas-table th:first-child {
  border-top-left-radius: 16px;
}

.saas-table th:last-child {
  border-top-right-radius: 16px;
}

.saas-table td {
  padding: 16px 24px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

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

.saas-table tbody tr:hover {
  background: var(--bg-app);
}

/* Badges */
.badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge.admin {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge.client {
  background: var(--border);
  color: var(--text-muted);
}

.badge.active {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.badge.expired {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

/* Service Cards (For Clients) */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.service-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.sc-title {
  font-weight: 600;
  font-size: 16px;
}

.sc-domain {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  margin-top: 4px;
  display: block;
  word-break: break-all;
}

.sc-domain:hover {
  text-decoration: underline;
}

/* Progress Bar */
.progress-wrapper {
  margin-top: auto;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-bar {
  height: 8px;
  background: var(--input-bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-fill.warning {
  background: var(--warning);
}

.progress-fill.danger {
  background: var(--danger);
}

.console-output {
  background: #0f172a;
  color: #10b981;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  padding: 16px;
  border-radius: 8px;
  height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* =========================================================
   * UX EFFECTS: SKELETONS & TOASTS
   * ========================================================= */
.skeleton-text {
  height: 20px;
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-app) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: pulse 1.5s infinite;
  border-radius: 4px;
  color: transparent !important;
  pointer-events: none;
  width: 60%;
}

.stat-value.skeleton-text {
  height: 40px;
  width: 40px;
  border-radius: 8px;
  margin-top: 8px;
}

@keyframes pulse {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  min-width: 300px;
  background: var(--bg-panel);
  color: var(--text-main);
  border-left: 4px solid var(--primary);
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.toast.success {
  border-left-color: var(--success);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}