:root {
  --bg: #0b1020;
  --bg-raised: #131a2e;
  --bg-hover: #1b2440;
  --border: #263052;
  --text: #e8ecf6;
  --text-dim: #9aa5c3;
  --accent: #4f7cff;
  --accent-hover: #658df5;
  --danger: #e5484d;
  --danger-hover: #f06267;
  --ok: #30a46c;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1100px 500px at 80% -10%, rgba(79, 124, 255, .14), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.small { font-size: .85rem; }
.center { display: flex; min-height: 100dvh; align-items: center; justify-content: center; padding: 24px; }
.center-line { text-align: center; padding: 40px 16px; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

/* Cards ---------------------------------------------------------------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.login-card {
  width: min(92vw, 360px);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card label { text-align: left; }

.login-icon { width: 56px; height: 56px; border-radius: 12px; margin: 0 auto; }

/* Forms ------------------------------------------------------------------ */

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .9rem;
  color: var(--text-dim);
}

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  min-width: 0;
}

input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input::placeholder { color: var(--text-dim); opacity: .8; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row input { flex: 1 1 120px; }
.form-row select { flex: 0 0 auto; }
.form-col { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.form-hint { font-size: .8rem; margin: 8px 0 0; }

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

.btn {
  font: inherit;
  font-size: .9rem;
  padding: 8px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--bg-hover);
  color: var(--text);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-hover); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: rgba(229, 72, 77, .12); }
.btn.small { padding: 4px 10px; font-size: .8rem; }
.btn.wide { width: 100%; }

a.btn { text-decoration: none; display: inline-block; }

/* Top bar ------------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 38px; height: 38px; border-radius: 9px; }
.brand { font-size: 1.15rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.whoami {
  font-size: .85rem;
  color: var(--text-dim);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
}

.net-status {
  font-size: .8rem;
  color: #ffb454;
  border: 1px solid rgba(255, 180, 84, .4);
  padding: 4px 10px;
  border-radius: 999px;
}

/* Tiles ------------------------------------------------------------------ */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 22px clamp(16px, 4vw, 40px) 60px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: center;
  transition: transform .12s, border-color .12s, background .12s;
}
.tile:hover { transform: translateY(-3px); border-color: var(--accent); background: var(--bg-hover); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile-icon {
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px;
  background: rgba(79, 124, 255, .14);
  overflow: hidden;
}
.tile-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 18px; }
.tile-text-icon { font-size: 34px; line-height: 1; }

.tile-name { font-weight: 600; font-size: .95rem; }
.tile-desc {
  font-size: .78rem; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; max-width: 100%;
}

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

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 22px clamp(16px, 4vw, 40px) 80px;
  align-items: start;
}
@media (max-width: 900px) { .admin-grid { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
td:last-child { text-align: right; }

.role-select { font-size: .85rem; padding: 5px 8px; width: 88px; }
.row-actions { display: inline-flex; gap: 6px; }

.apps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.app-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.app-row:last-child { border-bottom: none; }
.app-row.disabled { opacity: .5; }

.app-icon {
  width: 42px; height: 42px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px;
  background: rgba(79, 124, 255, .14);
  font-size: 22px;
  overflow: hidden;
}
.app-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 11px; }

.app-info { flex: 1; min-width: 0; }
.app-name { font-weight: 600; }
.app-url { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Dialog ------------------------------------------------------------------ */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
  width: min(92vw, 380px);
}
dialog::backdrop { background: rgba(4, 7, 15, .6); backdrop-filter: blur(2px); }

.dialog-card { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Flash / errors ---------------------------------------------------------- */

.flash {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--ok);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  z-index: 10;
  max-width: 92vw;
}
.flash.error-flash { border-color: var(--danger); }

.error { color: var(--danger); font-size: .85rem; min-height: 1.2em; margin: 0; }
