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

:root {
  --bg:         #0f0f13;
  --surface:    #1a1a24;
  --surface2:   #22222e;
  --border:     #2e2e3e;
  --text:       #e4e4f0;
  --text-muted: #7e7e9a;
  --accent:     #6366f1;
  --accent-h:   #4f52d6;
  --success:    #10b981;
  --danger:     #ef4444;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 4px 24px rgba(0,0,0,.4);
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 16px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }

/* === AUTH PAGE === */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: radial-gradient(ellipse at 60% 20%, #1e1b4b 0%, var(--bg) 60%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 48px;
  height: 48px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
}
.auth-logo svg { width: 28px; height: 28px; color: #fff; }

.auth-card h1 {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .25rem;
}
.auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
  margin-bottom: 1.5rem;
}

/* === TOPBAR === */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.05rem;
}
.topbar-brand svg { width: 22px; height: 22px; color: var(--accent); }

.topbar-nav { display: flex; align-items: center; gap: .25rem; }

.topbar-link {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.topbar-link svg { width: 16px; height: 16px; }
.topbar-link:hover, .topbar-link--active { background: var(--surface2); color: var(--text); }
.topbar-link--logout:hover { color: var(--danger); }

/* === DASHBOARD LAYOUT === */
.dashboard-page { display: flex; flex-direction: column; }

.dashboard-main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
}
.dashboard-header h2 { font-size: 1.6rem; font-weight: 700; }
.dashboard-header p  { color: var(--text-muted); font-size: .9rem; margin-top: .2rem; }

/* === APP GRID === */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  cursor: pointer;
}
.app-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(99,102,241,.15);
}
.app-card--inactive { opacity: .45; }

.app-card-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--app-color) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--app-color) 30%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.app-card-icon svg { width: 24px; height: 24px; color: var(--app-color); }

.app-card-body { flex: 1; min-width: 0; }
.app-card-body h3 { font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-card-body p  { font-size: .8rem; color: var(--text-muted); margin-top: .2rem; }
.app-card-body small { font-size: .75rem; color: var(--text-muted); }

.app-card-arrow svg { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.app-card:hover .app-card-arrow svg { color: var(--accent); }

.app-card-admin-actions {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  margin-left: auto;
}

/* === ADMIN OVERVIEW CARDS === */
.admin-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }

.admin-overview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color .15s;
}
.admin-overview-card:hover { border-color: var(--accent); }
.admin-overview-card h3 { font-size: 1rem; font-weight: 600; }
.admin-overview-card p  { font-size: .85rem; color: var(--text-muted); }

.admin-overview-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--app-color) 15%, transparent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.admin-overview-icon svg { width: 22px; height: 22px; color: var(--app-color); }

/* === CARD === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1.25rem; }

/* === FORMS === */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: .4rem; }
.field--full { grid-column: 1 / -1; }
.field--checkbox { margin-bottom: .5rem; }

label { font-size: .85rem; color: var(--text-muted); font-weight: 500; }

input[type=text],
input[type=email],
input[type=password],
input[type=url],
input[type=number],
select,
textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .9rem;
  font-family: var(--font);
  padding: .6rem .85rem;
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field--checkbox label {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  color: var(--text);
  font-size: .9rem;
}
.field--checkbox input[type=checkbox] { width: auto; }

small { font-size: .78rem; color: var(--text-muted); }

.form-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; }

/* === ICON PICKER === */
.icon-picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.icon-option { cursor: pointer; }
.icon-option input { display: none; }
.icon-option span {
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, background .15s;
}
.icon-option span svg { width: 20px; height: 20px; color: var(--text-muted); }
.icon-option input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.icon-option input:checked + span svg { color: var(--accent); }

/* === COLOR PICKER === */
.color-picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.color-option { cursor: pointer; }
.color-option input { display: none; }
.color-option span {
  display: block; width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color .15s, transform .15s;
}
.color-option input:checked + span { border-color: #fff; transform: scale(1.1); }

/* === CHECKBOX GRID === */
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; }
.checkbox-label {
  display: flex; align-items: center; gap: .5rem;
  font-size: .875rem; color: var(--text);
  cursor: pointer;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s;
}
.checkbox-label:hover { border-color: var(--accent); }
.checkbox-label input { accent-color: var(--accent); }

/* === TABLE === */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th {
  text-align: left;
  padding: .75rem 1rem;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

.table-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* === BADGES === */
.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: .2rem .6rem;
  border-radius: 999px;
}
.badge--admin   { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge--user    { background: color-mix(in srgb, #64748b 20%, transparent); color: #94a3b8; }
.badge--active  { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge--inactive{ background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost    { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-full     { width: 100%; justify-content: center; padding: .75rem; font-size: 1rem; }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon--danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); border-color: var(--danger); }

/* === ALERTS === */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert-error   { background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); color: #fca5a5; }
.alert-success { background: color-mix(in srgb, var(--success) 12%, transparent); border: 1px solid color-mix(in srgb, var(--success) 30%, transparent); color: #6ee7b7; }
.alert a { color: inherit; text-decoration: underline; }

/* === EMPTY STATE === */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 1rem; padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state svg { width: 56px; height: 56px; opacity: .4; }
.empty-state p { font-size: 1rem; }

/* === APP GRID ADMIN === */
.app-grid--admin .app-card { position: relative; }
