@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --sidebar-w: 260px;
  --sidebar-bg: #0b1437;
  --sidebar-text: #8f9bba;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active-bg: rgba(255,255,255,0.08);
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --primary-dark: #5b21b6;
  --bg: #f4f7fe;
  --card: #fff;
  --card-shadow: 0 2px 12px rgba(112,144,176,0.12);
  --card-radius: 16px;
  --text: #1b2559;
  --text-secondary: #8f9bba;
  --border: #e2e8f0;
  --input-bg: #f8f9fc;
  --success: #01b574;
  --success-bg: #f0fff4;
  --danger: #ee5d50;
  --danger-bg: #fff5f5;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.5rem; }
h2 { font-size: 1.15rem; font-weight: 700; margin: 1.75rem 0 0.75rem; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.35rem; }
p { margin-bottom: 0.75rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ===================== FORMS ===================== */

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 0.75rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
select,
textarea {
  display: block;
  width: 100%;
  font-family: var(--font);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.625rem 0.875rem;
  margin-bottom: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
  background: #fff;
}

input::placeholder, textarea::placeholder { color: var(--text-secondary); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238f9bba' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  cursor: pointer;
}

textarea { min-height: 80px; resize: vertical; }

input[type="checkbox"] {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}

small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: -0.5rem;
  margin-bottom: 0.75rem;
}

/* ===================== BUTTONS ===================== */

button,
[role="button"],
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.6rem 1.25rem;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}

button:hover, [role="button"]:hover, input[type="submit"]:hover {
  opacity: 0.92;
  transform: translateY(-1px);
  text-decoration: none;
}

button:active, [role="button"]:active { transform: translateY(0); }

/* Outline */
button.outline, [role="button"].outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--border);
}
button.outline:hover, [role="button"].outline:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  opacity: 1;
}

/* Secondary */
button.secondary, [role="button"].secondary {
  background: var(--input-bg);
  color: var(--text-secondary);
  border-color: var(--border);
}
button.secondary:hover, [role="button"].secondary:hover {
  background: var(--border);
  color: var(--text);
  opacity: 1;
}

/* Secondary outline */
button.secondary.outline, [role="button"].secondary.outline {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
button.secondary.outline:hover, [role="button"].secondary.outline:hover {
  background: var(--input-bg);
  color: var(--text);
  opacity: 1;
}

/* Contrast (danger) */
button.contrast, [role="button"].contrast {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}
button.contrast:hover, [role="button"].contrast:hover { opacity: 0.9; }

button.contrast.outline, [role="button"].contrast.outline {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
button.contrast.outline:hover, [role="button"].contrast.outline:hover {
  background: var(--danger);
  color: #fff;
  opacity: 1;
}

/* Small */
.btn-sm {
  padding: 0.3rem 0.65rem !important;
  font-size: 0.75rem !important;
  border-radius: 8px !important;
  border-width: 1.5px !important;
}

.btn-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}
.btn-row form { margin: 0; }

/* ===================== DETAILS / SUMMARY ===================== */

details { margin-bottom: 1rem; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

details > summary[role="button"] {
  display: inline-flex;
  margin-bottom: 0;
}

details[open] > summary[role="button"].outline {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

details:not([style]) > :not(summary) {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 1.25rem;
  margin-top: 0.5rem;
  box-shadow: var(--card-shadow);
}

details[style*="inline"] {
  display: inline-block;
  position: relative;
  margin: 0;
}

details[style*="inline"] > form {
  position: absolute;
  right: 0; top: calc(100% + 4px);
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 300px;
  padding: 1.25rem;
}

/* ===================== TABLES ===================== */

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

thead th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: transparent;
}

tbody td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(124,58,237,0.015); }

.audit-table { font-size: 0.8125rem; }

/* ===================== STAT CARDS ===================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--card);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 1.15rem 1.25rem;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 0.65rem;
  overflow: hidden;
}

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

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

/* ===================== BADGES ===================== */

mark {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #e9d8fd;
  color: var(--primary-dark);
}

/* ===================== ALERTS ===================== */

.alert {
  padding: 0.75rem 1.15rem;
  margin-bottom: 1.25rem;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
}

.alert-error {
  background: var(--danger-bg);
  color: #c53030;
  border: 1px solid #fed7d7;
}

.alert-success {
  background: var(--success-bg);
  color: #276749;
  border: 1px solid #9ae6b4;
}

.alert-warn {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

/* ===================== SIDEBAR ===================== */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}

.sidebar-brand { padding: 0 0.75rem 1.75rem; }

.sidebar-brand a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
}
.sidebar-brand a:hover { text-decoration: none; }
.sidebar-brand svg { opacity: 0.9; }
.sidebar-brand .brand-accent { color: var(--primary-light); font-weight: 400; }

.sidebar::before {
  content: '';
  position: absolute;
  top: 4.5rem; left: 1.5rem; right: 1.5rem;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 1rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 12px;
  transition: all 0.15s ease;
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item svg { flex-shrink: 0; opacity: 0.6; }
.nav-item:hover svg { opacity: 1; }

.nav-section {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.25);
  padding: 1.25rem 0.85rem 0.5rem;
}

.sidebar-footer {
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 0.5rem;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 12px;
  cursor: pointer;
  list-style: none;
  border: none;
  background: none;
  width: 100%;
  transition: all 0.15s;
}
.user-menu:hover { background: var(--sidebar-hover); color: #fff; }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase;
}

.sidebar-footer details { margin: 0; }
.sidebar-footer details[open] summary { background: var(--sidebar-hover); color: #fff; }

.sidebar-footer ul {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.35rem;
  margin: 0.25rem 0 0;
  list-style: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.sidebar-footer ul li { list-style: none; }

.sidebar-footer ul a,
.sidebar-footer ul button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.85rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.8125rem;
  font-family: var(--font);
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.1s;
}
.sidebar-footer ul a:hover,
.sidebar-footer ul button:hover { background: var(--bg); color: var(--primary); }

.logout-form { margin: 0; }

/* ===================== MAIN CONTENT ===================== */

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  gap: 1rem;
}

.top-bar-left { display: flex; flex-direction: column; gap: 0.15rem; }

.breadcrumb { font-size: 0.75rem; color: var(--text-secondary); }
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--primary); }

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 0;
}

.top-bar-right { display: flex; align-items: center; gap: 0.75rem; }

.search-box {
  border: none !important;
  border-radius: 30px !important;
  padding: 0.55rem 1rem 0.55rem 2.25rem !important;
  width: 200px;
  box-shadow: var(--card-shadow);
  background-color: var(--card) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238f9bba' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.75rem center;
  margin: 0 !important;
  transition: width 0.2s;
}
.search-box:focus { width: 280px; box-shadow: var(--card-shadow) !important; }

.content-area {
  flex: 1;
  padding: 0 2rem 2rem;
}
.content-area hgroup { margin-bottom: 1.25rem; }
.content-area hgroup h1 { display: none; }
.content-area hgroup p { color: var(--text-secondary); font-size: 0.875rem; margin: 0; }
.content-area h2 { font-size: 1.1rem; font-weight: 700; margin: 1.75rem 0 0.75rem; color: var(--text); }

/* ===================== CARDS ===================== */

.card {
  background: var(--card);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 1.25rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.dashboard-card { text-decoration: none; color: inherit; }
.dashboard-card:hover { text-decoration: none; }

.dashboard-card .card {
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.15s, box-shadow 0.15s;
  padding: 1.1rem 1.25rem;
  height: 100%;
}

.dashboard-card:hover .card {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(112,144,176,0.18);
}

.card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.card-info h3 { font-size: 0.875rem; font-weight: 700; margin: 0; }
.card-info p { font-size: 0.75rem; color: var(--text-secondary); margin: 0.15rem 0 0; }

/* ===================== GRID LAYOUT ===================== */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  align-items: start;
}

/* ===================== LOGIN ===================== */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: var(--bg);
}

.login-center {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  background: var(--card);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  text-align: center;
}

.login-center .login-brand-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.25rem;
}

.login-center h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }

.login-center .login-sub {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

.login-center form { text-align: left; }

.login-center button[type="submit"] {
  width: 100%;
  padding: 0.7rem;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.login-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===================== SETUP ===================== */

.setup-container { max-width: 460px; margin: 2rem auto; }

.setup-container article {
  background: var(--card);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 2rem;
}

.setup-container article header { margin-bottom: 0.5rem; }

/* ===================== SUB NAV ===================== */

.sub-nav {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  background: var(--card);
  border-radius: 12px;
  padding: 0.3rem;
  box-shadow: var(--card-shadow);
  width: fit-content;
}

.sub-nav a {
  padding: 0.45rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.15s;
}
.sub-nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.sub-nav a strong {
  color: #fff;
  background: var(--primary);
  border-radius: 10px;
  padding: 0.45rem 1rem;
  margin: -0.45rem -1rem;
  display: block;
  font-weight: 600;
}

/* ===================== MISC ===================== */

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

code {
  font-size: 0.8em;
  padding: 0.15em 0.45em;
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--primary-dark);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

pre code {
  display: block;
  padding: 1rem;
  border-radius: var(--card-radius);
  background: var(--sidebar-bg);
  color: #e2e8f0;
  font-size: 0.8125rem;
  overflow-x: auto;
}

article { margin-bottom: 1rem; }

/* ===================== RESPONSIVE ===================== */

@media (max-width: 768px) {
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.75rem;
  }
  .sidebar::before { display: none; }
  .sidebar-brand { padding: 0 0.5rem 0; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 0; gap: 0; }
  .nav-item { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
  .nav-section { display: none; }
  .sidebar-footer { margin-left: auto; padding: 0; }
  .main-content { margin-left: 0; }
  .top-bar { padding: 1rem; }
  .content-area { padding: 0 1rem 1rem; }
  .login-center { margin: 1rem; }
  .search-box { width: 140px !important; }
  .search-box:focus { width: 180px !important; }
}

.badge {
  display: inline-block;
  padding: 0.15em 0.55em;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  line-height: 1.4;
}
.badge-success { background: rgba(1,181,116,0.12); color: #01b574; }
.badge-muted { background: rgba(143,155,186,0.15); color: #8f9bba; }
.badge-warn { background: rgba(255,183,77,0.15); color: #e8a317; }

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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