/*
 * ClassCloud Design System — v3.0
 * Dark-only. All pages import this file.
 */

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

/* ─── Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-base:        #0d1117;
  --bg-sidebar:     #13131c;
  --bg-surface:     #191923;
  --bg-elevated:    #1e1e2e;
  --bg-hover:       #242436;

  /* Brand Purple */
  --purple-deep:    #3b0087;
  --purple-primary: #6B00CC;
  --purple-mid:     #7c3aed;
  --purple-bright:  #9B4DFF;
  --purple-light:   #C084FC;

  /* Text */
  --text-primary:   #ffffff;
  --text-secondary: #a1a1c0;
  --text-muted:     #5c5c7a;

  /* Borders */
  --border-default: rgba(255, 255, 255, 0.07);
  --border-purple:  rgba(107, 0, 204, 0.4);
  --border-strong:  rgba(255, 255, 255, 0.12);

  /* Status */
  --status-running: #22c55e;
  --status-pending: #f59e0b;
  --status-error:   #ef4444;
  --status-stopped: #64748b;

  /* Animation */
  --ease-default:   cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast:  150ms;
  --duration-base:  250ms;
  --duration-slow:  400ms;

  /* Spacing */
  --sidebar-width:  240px;
  --topbar-height:  56px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

/* ─── Base ───────────────────────────────────────────────────────── */
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--purple-bright); text-decoration: none; }
a:hover { color: var(--purple-light); }

:focus-visible {
  outline: 2px solid var(--purple-bright);
  outline-offset: 2px;
}

/* ─── Sidebar Shell ──────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--duration-base) var(--ease-default);
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo { height: 28px; width: auto; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  padding: .25rem;
}

.sidebar-nav {
  flex: 1;
  padding: .75rem .5rem;
  display: flex;
  flex-direction: column;
  gap: .125rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: .875rem;
  font-weight: 500;
  transition: background var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
  border-left: 3px solid transparent;
  text-decoration: none;
}

.sidebar-nav a:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-left-color: var(--purple-primary);
}

.sidebar-nav .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; }
.sidebar-nav a.active .nav-icon,
.sidebar-nav a:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: .75rem 1rem 1.25rem;
  border-top: 1px solid var(--border-default);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .6rem;
}

.sidebar-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--purple-primary), var(--purple-bright));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-username { display: block; font-size: .8rem; font-weight: 600; color: var(--text-primary); }
.sidebar-role     { display: block; font-size: .7rem;  color: var(--text-muted); }

.sidebar-logout {
  display: block;
  font-size: .8rem;
  color: var(--text-muted);
  padding: .4rem .75rem;
  border-radius: 6px;
  transition: background var(--duration-fast), color var(--duration-fast);
  text-decoration: none;
}
.sidebar-logout:hover { background: var(--bg-elevated); color: var(--status-error); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 199;
  backdrop-filter: blur(2px);
}

/* ─── App Main Content ───────────────────────────────────────────── */
.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  background: var(--bg-surface);
}

.app-topbar {
  display: none;
  height: var(--topbar-height);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-default);
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-topbar-logo { height: 24px; }

.menu-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: .4rem;
  border-radius: 6px;
  transition: background var(--duration-fast);
}
.menu-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.menu-btn svg { display: block; }

.app-content { padding: 1.75rem 2rem; }

/* ─── Top Nav (public pages) ─────────────────────────────────────── */
.topnav {
  height: var(--topbar-height);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  padding: 0 2rem;
  gap: 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topnav-logo { height: 28px; }

.topnav-links {
  display: flex;
  gap: 1.5rem;
  flex: 1;
}

.topnav-links a {
  font-size: .875rem;
  color: var(--text-secondary);
  transition: color var(--duration-fast);
  text-decoration: none;
}
.topnav-links a:hover { color: var(--text-primary); }

.topnav-actions { display: flex; gap: .75rem; align-items: center; }

.topnav-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: .4rem;
  margin-left: auto;
}

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .55rem 1.1rem;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--purple-primary), var(--purple-bright));
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--purple-mid), var(--purple-bright));
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(107,0,204,.35);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-danger {
  background: rgba(239,68,68,.12);
  color: var(--status-error);
  border: 1px solid rgba(239,68,68,.25);
}
.btn-danger:hover { background: rgba(239,68,68,.2); }

.btn-success {
  background: rgba(34,197,94,.12);
  color: var(--status-running);
  border: 1px solid rgba(34,197,94,.25);
}
.btn-success:hover { background: rgba(34,197,94,.2); }

.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }

/* ─── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  padding: 1.25rem;
}

.card-accent {
  border-left: 3px solid var(--purple-primary);
  box-shadow: 0 0 0 1px var(--border-purple), 0 4px 24px rgba(107,0,204,.12);
}

/* ─── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.badge-running  { background: rgba(34,197,94,.12);   color: var(--status-running); }
.badge-running::before  { background: var(--status-running); animation: pulse-green 2s infinite; }
.badge-pending  { background: rgba(245,158,11,.12);  color: var(--status-pending); }
.badge-pending::before  { background: var(--status-pending); animation: pulse-green 2s infinite; }
.badge-error    { background: rgba(239,68,68,.12);   color: var(--status-error); }
.badge-error::before    { background: var(--status-error); }
.badge-stopped  { background: rgba(100,116,139,.12); color: var(--status-stopped); }
.badge-stopped::before  { background: var(--status-stopped); }

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* ─── GradientAlert (flash messages) ─────────────────────────────── */
.alert {
  position: relative;
  width: 100%;
  border-radius: 10px;
  border: 1px solid;
  padding: .8rem 2.4rem .8rem 3rem;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .855rem;
  line-height: 1.5;
  animation: alertIn .4s cubic-bezier(.34,1.56,.64,1) both;
}
.alert + .alert { margin-top: .5rem; }

/* radial glow */
.alert::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 40px 50%, var(--alert-glow,transparent) 0%, transparent 45%);
  opacity: .18;
  pointer-events: none;
}

/* left icon column */
.alert-icon {
  position: absolute;
  left: 0; top: 0; height: 100%; width: 2.6rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; margin-bottom: .05rem; }
.alert-msg   { opacity: .88; }

/* dismiss button */
.alert-close {
  position: absolute; top: .55rem; right: .55rem;
  background: none; border: none; cursor: pointer;
  padding: .25rem; border-radius: 50%; color: inherit;
  opacity: .45; transition: opacity .15s, background .15s;
  display: flex; align-items: center; justify-content: center;
  line-height: 0;
}
.alert-close:hover { opacity: 1; background: rgba(255,255,255,.08); }

/* variants */
.alert-error   { border-color: rgba(239,68,68,.35);   background: rgba(239,68,68,.06);   color: #fca5a5; --alert-glow: rgb(239,68,68); }
.alert-error   .alert-icon { background: rgba(239,68,68,.12);   color: #f87171; }
.alert-success { border-color: rgba(34,197,94,.35);   background: rgba(34,197,94,.06);   color: #86efac; --alert-glow: rgb(34,197,94); }
.alert-success .alert-icon { background: rgba(34,197,94,.12);   color: #4ade80; }
.alert-warning { border-color: rgba(245,158,11,.35);  background: rgba(245,158,11,.06);  color: #fcd34d; --alert-glow: rgb(245,158,11); }
.alert-warning .alert-icon { background: rgba(245,158,11,.12);  color: #fbbf24; }
.alert-info    { border-color: rgba(107,0,204,.35);   background: rgba(107,0,204,.06);   color: var(--purple-light); --alert-glow: rgb(107,0,204); }
.alert-info    .alert-icon { background: rgba(107,0,204,.12);   color: var(--purple-bright); }

/* animations */
@keyframes alertIn  { from { opacity:0; transform:translateX(20px) scale(.96); } to { opacity:1; transform:none; } }
@keyframes alertOut { to   { opacity:0; transform:translateX(20px) scale(.96); } }
.alert.dismissing { animation: alertOut .18s ease-in forwards; }

/* ─── Form Inputs ────────────────────────────────────────────────── */
.input,
.form-input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: .6rem .9rem;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: .875rem;
  transition: border-color var(--duration-fast);
  outline: none;
}
.input:focus,
.form-input:focus { border-color: var(--purple-primary); box-shadow: 0 0 0 3px rgba(107,0,204,.15); }
.input::placeholder,
.form-input::placeholder { color: var(--text-muted); }
.form-input option,
.input option { background: var(--bg-elevated); color: var(--text-primary); }

.label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: .35rem;
}

.form-group { margin-bottom: 1rem; }

/* ─── Page Header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.page-title   { font-size: 1.5rem; font-weight: 700; margin: 0 0 .25rem; }
.page-subtitle { font-size: .875rem; color: var(--text-secondary); margin: 0; }

/* ─── Stats Strip ────────────────────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1.75rem;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}
.stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; margin-bottom: .35rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.stat-value.purple { color: var(--purple-bright); }
.stat-value.green  { color: var(--status-running); }
.stat-value.amber  { color: var(--status-pending); }

/* ─── Table ──────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  overflow: hidden;
}
.table-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--border-default);
  flex-wrap: wrap;
}
.table-search {
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: .6rem 1rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
}
td {
  padding: .75rem 1rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-secondary);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Toast ──────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: .8rem 1.1rem;
  font-size: .875rem;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  animation: fadeUp var(--duration-base) var(--ease-default) both;
  max-width: 340px;
}
.toast.success { border-left: 3px solid var(--status-running); }
.toast.error   { border-left: 3px solid var(--status-error); }
.toast.info    { border-left: 3px solid var(--purple-bright); }

/* ─── Animations ─────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up   { animation: fadeUp var(--duration-slow) var(--ease-default) both; }
.fade-up-1 { animation-delay:  50ms; }
.fade-up-2 { animation-delay: 100ms; }
.fade-up-3 { animation-delay: 150ms; }
.fade-up-4 { animation-delay: 200ms; }
.fade-up-5 { animation-delay: 250ms; }

@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .app-main { margin-left: 0; }
  .app-topbar { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .sidebar-overlay.visible { display: block; }
}

@media (max-width: 767px) {
  .topnav-links { display: none; }
  .topnav-hamburger { display: block; }
  .topnav-actions .btn-ghost { display: none; }
  .app-content { padding: 1rem; }
  .stats-strip { grid-template-columns: 1fr 1fr; }
  th, td { padding: .5rem .6rem; font-size: .8rem; }
}

@media (max-width: 480px) {
  .stats-strip { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .page-header .btn { width: 100%; justify-content: center; }
}

/* ─── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
