@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #0B0F1A;
  --bg-grid: #5c606a99;
  --surface: #141B2C;
  --surface-2: #1B2438;
  --surface-3: #232E47;
  --border: #2A3452;
  --text: #EDEFF7;
  --text-dim: #8891A8;
  --text-faint: #5B6480;
  --accent: #d59bff;
  --accent-dim: #FFB45422;
  --accent-2: #5EEAD4;
  --danger: #FF6B6B;
  --danger-dim: #FF6B6B22;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-lg: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 6px 20px -8px rgba(0, 0, 0, 0.5);
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 1px 1px, var(--bg-grid) 1px, transparent 0);
  background-size: 28px 28px;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0;
  letter-spacing: -0.01em;
}

a { color: inherit; text-decoration: none; }
button { font-family: var(--font-body); }

::selection { background: var(--accent-dim); color: var(--accent); }

.mono { font-family: var(--font-mono); letter-spacing: -0.02em; }

/* -------------------- Buttons -------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #1A1200;
  box-shadow: 0 8px 24px -8px rgba(255, 180, 84, 0.5);
}
.btn-primary:hover { background: #ffc478; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { border-color: var(--text-dim); background: var(--surface-2); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: #ff6b6b44;
}
.btn-danger:hover { background: #ff6b6b33; }

.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-icon { padding: 8px; width: 34px; height: 34px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* -------------------- Inputs -------------------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field input,
.field select,
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  background: var(--surface-3);
}
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.hint { font-size: 12.5px; color: var(--text-faint); margin-top: -8px; margin-bottom: 16px; }

/* -------------------- Alerts / toasts -------------------- */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 16px;
  border: 1px solid transparent;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: var(--danger-dim); color: #ffb0b0; border-color: #ff6b6b44; }
.alert-success { background: #5eead422; color: var(--accent-2); border-color: #5eead444; }

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: #ff6b6b66; color: #ffb0b0; }

/* -------------------- Login page -------------------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-wrap::before {
  content: '';
  position: absolute;
  width: 700px;
  height: 700px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 180, 84, 0.14), transparent 70%);
  top: -280px;
  left: -200px;
  pointer-events: none;
}
.login-wrap::after {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(94, 234, 212, 0.10), transparent 70%);
  bottom: -260px;
  right: -180px;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--surface), var(--surface) 60%, var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #1a1200;
  font-size: 15px;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.brand-name span { color: var(--accent); }

.login-card h1 { font-size: 23px; margin-bottom: 6px; }
.login-card .sub { color: var(--text-dim); font-size: 14px; margin-bottom: 26px; }

.login-card .btn-primary { width: 100%; padding: 13px; margin-top: 4px; }

.demo-note {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.6;
}
.demo-note code { color: var(--text-dim); font-family: var(--font-mono); }

/* -------------------- App shell (dashboard + admin) -------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(11, 15, 26, 0.85);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.topbar .brand-name { font-size: 16px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 6px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.user-chip .u-name { font-size: 13px; font-weight: 600; }
.user-chip .u-role {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 32px 80px;
}

.page-head { margin-bottom: 32px; }
.page-head .eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.page-head h1 { font-size: 28px; }
.page-head p { color: var(--text-dim); margin-top: 8px; font-size: 14.5px; }

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
}
.search-bar input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

.token-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.token-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.token-value {
  font-size: 13.5px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.token-actions { display: flex; gap: 8px; }

.category-group { margin-bottom: 36px; }
.category-title {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
  padding-left: 2px;
}

/* -------------------- App tiles (the signature element) -------------------- */

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.app-tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  overflow: hidden;
}
.app-tile:hover {
  transform: translateY(-3px);
  border-color: var(--tile-color, var(--accent));
  box-shadow: var(--shadow-sm);
}
.app-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--tile-color, var(--accent)) 0%, transparent 55%);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}
.app-tile:hover::after { opacity: 0.06; }

.app-tile-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}
.app-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: color-mix(in srgb, var(--tile-color, var(--accent)) 18%, var(--surface-2));
}
.app-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  margin-top: 6px;
  box-shadow: 0 0 0 3px #5eead41a;
}
.app-tile h3 { font-size: 15.5px; margin-bottom: 4px; }
.app-tile p {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
  min-height: 32px;
}
.app-tile .launch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.app-tile .launch-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--tile-color, var(--accent));
  display: flex;
  align-items: center;
  gap: 5px;
}
.app-tile .category-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-dim);
}
.empty-state .eb { font-size: 34px; margin-bottom: 14px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; font-size: 17px; }
.empty-state p { font-size: 14px; max-width: 340px; margin: 0 auto; }

/* -------------------- Admin layout -------------------- */

.admin-shell { display: flex; min-height: calc(100vh - 65px); }

.admin-sidebar {
  width: 220px;
  border-right: 1px solid var(--border);
  padding: 28px 14px;
  flex-shrink: 0;
}
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}
.admin-nav-item:hover { background: var(--surface); color: var(--text); }
.admin-nav-item.active { background: var(--surface-2); color: var(--accent); }
.admin-nav-item .n { font-family: var(--font-mono); font-size: 11px; opacity: 0.6; }

.admin-main { flex: 1; padding: 32px 40px; max-width: 1100px; }

.admin-panel { display: none; }
.admin-panel.active { display: block; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.panel-head h2 { font-size: 21px; }
.panel-head p { color: var(--text-dim); font-size: 13.5px; margin-top: 4px; }

.stat-row { display: flex; gap: 14px; margin-bottom: 28px; }
.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card .v { font-family: var(--font-display); font-size: 26px; font-weight: 700; }
.stat-card .l { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Table */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
}
.data-table td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }

.row-name { font-weight: 600; }
.row-sub { color: var(--text-faint); font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-admin { background: var(--accent-dim); color: var(--accent); }
.badge-user { background: var(--surface-3); color: var(--text-dim); }
.badge-active { background: #5eead422; color: var(--accent-2); }
.badge-disabled { background: var(--danger-dim); color: #ffb0b0; }

.mini-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  margin-right: 4px;
}
.chip-stack { display: flex; align-items: center; gap: -6px; }
.chip-stack .mini-icon { margin-left: -6px; border: 2px solid var(--surface); }
.chip-stack .mini-icon:first-child { margin-left: 0; }
.chip-more {
  font-size: 11px;
  color: var(--text-faint);
  margin-left: 6px;
  font-family: var(--font-mono);
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* -------------------- Modal -------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.7);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.show { display: flex; }

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  max-height: 88vh;
  overflow-y: auto;
}
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .modal-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.modal.modal-wide { max-width: 620px; }

.icon-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-swatch {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  cursor: pointer;
}
.icon-swatch.selected { border-color: var(--accent); background: var(--accent-dim); }

.color-swatches { display: flex; gap: 8px; }
.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected { border-color: var(--text); }

.assign-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.assign-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.assign-row .u {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
}
.assign-row .u-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-3); font-family: var(--font-mono);
  font-size: 11px; display: flex; align-items: center; justify-content: center;
  color: var(--accent-2);
}

.switch {
  position: relative;
  width: 38px;
  height: 21px;
  background: var(--surface-3);
  border-radius: 100px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-faint);
  top: 2px;
  left: 2px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.switch.on { background: var(--accent-dim); border-color: #ffb45455; }
.switch.on::after { transform: translateX(17px); background: var(--accent); }

.empty-cell { color: var(--text-faint); font-size: 12.5px; }

/* -------------------- Webmail (My Webmail) -------------------- */

.mail-shell {
  display: grid;
  grid-template-columns: 220px 320px 1fr;
  height: calc(100vh - 65px);
}

.mail-sidebar {
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  overflow-y: auto;
}
.mail-section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
  padding-left: 4px;
}
.mail-account-list, .mail-folder-list { display: flex; flex-direction: column; gap: 2px; }
.mail-account-item, .mail-folder-item {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease;
}
.mail-account-item:hover, .mail-folder-item:hover { background: var(--surface); color: var(--text); }
.mail-account-item.active, .mail-folder-item.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.mail-account-name { font-weight: 600; color: inherit; }
.mail-account-email { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.mail-account-item.active .mail-account-email { color: var(--accent); opacity: 0.75; }

.mail-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mail-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mail-list-head h2 { font-size: 17px; }
.mail-list { overflow-y: auto; flex: 1; }

.mail-item {
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}
.mail-item:hover { background: var(--surface); }
.mail-item.active { background: var(--surface-2); }
.mail-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.mail-item-from { font-size: 13px; font-weight: 500; color: var(--text-dim); }
.mail-item.unread .mail-item-from { color: var(--text); font-weight: 700; }
.mail-item-date { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }
.mail-item-subject { font-size: 13.5px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.mail-item.unread .mail-item-subject { color: var(--text); font-weight: 600; }
.mail-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}

.mail-reading-pane { overflow-y: auto; padding: 0; }
.mail-message-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border);
}
.mail-message-header h2 { font-size: 20px; margin-bottom: 12px; }
.mail-meta-row { font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.mail-meta-sub { color: var(--text-faint); font-size: 12.5px; }
.mail-reply-row { margin-top: 16px; }
.mail-message-body { padding: 24px 32px 40px; }
.mail-plain-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  margin: 0;
}
.mail-html-frame {
  width: 100%;
  min-height: 200px;
  border: none;
  background: #fff;
  border-radius: var(--radius-sm);
}

.mail-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.mail-empty .eb { font-size: 30px; margin-bottom: 12px; }
.mail-empty h3 { color: var(--text); font-size: 15px; margin-bottom: 6px; }
.mail-empty p { font-size: 13px; max-width: 280px; margin: 0; }

@media (max-width: 900px) {
  .mail-shell { grid-template-columns: 1fr; height: auto; }
  .mail-sidebar, .mail-list-pane, .mail-reading-pane { border-right: none; border-bottom: 1px solid var(--border); }
}

@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; display: flex; padding: 12px; gap: 4px; overflow-x: auto; }
  .admin-nav-item { white-space: nowrap; }
  .admin-main { padding: 24px 18px; }
  .page { padding: 28px 18px 60px; }
  .topbar { padding: 14px 18px; }
  .field-row { flex-direction: column; gap: 0; }
}
