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

:root {
  --orange: #FF9900;
  --dark:   #1a1a2e;
  --mid:    #16213e;
  --light:  #0f3460;
  --text:   #e0e0e0;
  --muted:  #888;
  --green:  #28a745;
  --red:    #dc3545;
  --bg:     #0d1117;
  --card:   #161b22;
  --border: #30363d;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Auth pages ─────────────────────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card-wide { max-width: 700px; }

.logo { text-align: center; margin-bottom: 16px; }
h1 { font-size: 1.5rem; text-align: center; margin-bottom: 4px; }
.subtitle { color: var(--muted); text-align: center; margin-bottom: 24px; font-size: .9rem; }

/* ── Form fields ────────────────────────────────────────────────────────── */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="email"],
textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: .95rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--orange); }
textarea { resize: vertical; font-family: monospace; font-size: .8rem; }

.checkbox-field label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.checkbox-field input[type="checkbox"] { width: auto; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: 8px; font-size: .9rem;
  font-weight: 500; cursor: pointer; border: none; text-decoration: none;
  transition: opacity .15s, transform .1s; gap: 6px;
}
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--orange); color: #000; }
.btn-success  { background: var(--green);  color: #fff; }
.btn-danger   { background: var(--red);    color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-full     { width: 100%; }
.btn-sm       { padding: 5px 12px; font-size: .8rem; }

/* ── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
  padding: 12px 16px; border-radius: 8px; font-size: .875rem; margin-bottom: 16px;
}
.alert-error   { background: rgba(220,53,69,.15);  border: 1px solid rgba(220,53,69,.4); color: #f88; }
.alert-success { background: rgba(40,167,69,.15);  border: 1px solid rgba(40,167,69,.4); color: #8f8; }
.alert-info    { background: rgba(255,153,0,.1);   border: 1px solid rgba(255,153,0,.3); color: #ffa; }

.back-link { text-align: center; margin-top: 20px; }
.back-link a { color: var(--muted); font-size: .85rem; text-decoration: none; }
.back-link a:hover { color: var(--orange); }

.btn-microsoft {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; padding: 12px 20px; border-radius: 4px; font-size: .95rem;
  font-weight: 600; cursor: pointer; text-decoration: none;
  background: #0078d4; color: #fff; border: none;
  transition: background .15s;
}
.btn-microsoft:hover { background: #106ebe; }

/* ── Navbar ─────────────────────────────────────────────────────────────── */

.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; position: sticky; top: 0; z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1rem; }
.nav-right  { display: flex; align-items: center; gap: 16px; }
.nav-user   { color: var(--muted); font-size: .85rem; }
.nav-link   { color: var(--text); text-decoration: none; font-size: .85rem; }
.nav-link:hover { color: var(--orange); }

/* ── Dashboard layout ───────────────────────────────────────────────────── */

.main-content { max-width: 1600px; margin: 32px auto; padding: 0 24px; }

.status-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 24px;
}

.status-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.status-dot {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.connected    { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.disconnected { background: var(--muted); }

.status-card h2 { font-size: 1.2rem; margin-bottom: 4px; }
.status-sub { color: var(--muted); font-size: .875rem; }

.action-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* ── SG cards ───────────────────────────────────────────────────────────── */

.sg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.sg-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.sg-header { margin-bottom: 10px; }
.sg-id { color: var(--muted); font-size: .75rem; display: block; margin-top: 2px; }
.sg-ports { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  background: rgba(255,153,0,.15);
  border: 1px solid rgba(255,153,0,.3);
  color: var(--orange);
  padding: 2px 8px; border-radius: 4px; font-size: .75rem; font-weight: 500;
}
.badge-active  { background: rgba(40,167,69,.15);  border-color: rgba(40,167,69,.3);  color: #28a745; }
.badge-pending { background: rgba(253,126,20,.15); border-color: rgba(253,126,20,.3); color: #fd7e14; }
.badge-disabled{ background: rgba(220,53,69,.12);  border-color: rgba(220,53,69,.3);  color: #dc3545; }
.badge-admin   { background: rgba(111,66,193,.15); border-color: rgba(111,66,193,.3); color: #9b6dff; }
.row-disabled td { opacity: .55; }

/* ── Session banner ─────────────────────────────────────────────────────── */

.session-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 20px;
  font-size: .875rem; margin-bottom: 16px; color: var(--muted);
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-on  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-off { background: var(--muted); }

.nav-ip {
  font-size: .78rem; font-family: monospace;
  background: rgba(255,153,0,.15); color: var(--orange);
  padding: 2px 8px; border-radius: 4px;
}

.disconnect-all-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.hint { color: var(--muted); font-size: .8rem; }

/* ── Environment cards ───────────────────────────────────────────────────── */

.env-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.env-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--env-color, var(--orange));
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color .2s, box-shadow .2s;
}
.env-card.env-connected {
  box-shadow: 0 0 0 1px var(--env-color, var(--orange)),
              0 0 16px rgba(40,167,69,.1);
}

.env-card-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.env-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--border); flex-shrink: 0; transition: background .2s;
}
.env-dot.env-dot-on { background: var(--green); box-shadow: 0 0 6px var(--green); }

.env-name   { font-weight: 600; font-size: 1rem; }
.env-status { font-size: .78rem; color: var(--muted); margin-top: 2px; }

.env-sgs { margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.sg-row  { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sg-id-small { font-size: .72rem; color: var(--muted); }
.sg-desc { font-size: .8rem; color: var(--text); }
.sg-ports { display: flex; gap: 4px; flex-wrap: wrap; }

.env-actions { display: flex; justify-content: flex-end; }
.card-actions-row { margin-bottom: 32px; }

.resource-label {
  font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  margin: 10px 0 5px; padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.resource-label:first-child { margin-top: 0; }
.resource-label-eks { color: #4fc3f7; border-bottom-color: rgba(79,195,247,.25); }

.badge-eks {
  background: rgba(79,195,247,.12);
  border: 1px solid rgba(79,195,247,.3);
  color: #4fc3f7;
  padding: 2px 8px; border-radius: 4px; font-size: .75rem; font-weight: 500;
}

/* ── Sidebar layout ─────────────────────────────────────────────── */

.sidebar-layout {
  display: flex;
  gap: 0;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  min-height: 500px;
}

/* Left sidebar */
.sidebar {
  width: 140px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
  background: rgba(0,0,0,.2);
  border-right: 1px solid var(--border);
  align-self: stretch;
}

.sidebar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s;
  width: 100%;
}
.sidebar-btn:hover { background: rgba(255,255,255,.05); }
.sidebar-btn.active {
  background: rgba(255,153,0,.12);
  border-color: rgba(255,153,0,.3);
}

.sidebar-icon { font-size: 1.6rem; }
.sidebar-label { display: flex; flex-direction: column; gap: 2px; }
.sidebar-name  { font-size: .8rem; font-weight: 600; color: var(--text); }
.sidebar-count { font-size: .68rem; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 4px; }
.sidebar-dot-on {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--green);
  box-shadow: 0 0 4px var(--green);
}

/* Right content area */
.sidebar-content { flex: 1; min-width: 0; }

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.panel-sub   { font-size: .75rem; color: var(--muted); margin-top: 2px; }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 16px;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}
.panel-grid::-webkit-scrollbar { width: 4px; }
.panel-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Cards inside panels — no SG detail section shown */
.panel-grid .env-card  { border-radius: 10px; }
.panel-grid .env-sgs   { display: none; }

@media (max-width: 768px) {
  .sidebar-layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-btn { flex-direction: row; padding: 10px 14px; }
  .panel-grid { max-height: none; }
}

/* ── Legacy section divider ─────────────────────────────────────── */
.section-divider {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.section-label { font-size: 1rem; font-weight: 700; color: var(--text); }
.section-hint  { font-size: .75rem; color: var(--muted); }

.env-instance  { font-size: .72rem; color: var(--muted); margin-top: 1px; font-family: monospace; }
.env-warning   {
  font-size: .75rem; color: #ffc107; background: rgba(255,193,7,.08);
  border: 1px solid rgba(255,193,7,.25); border-radius: 4px;
  padding: 4px 8px; margin-bottom: 8px;
}

.env-others {
  font-size: .72rem; color: var(--muted);
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 8px; white-space: nowrap;
  cursor: default;
}
.env-others:empty { display: none; }

/* ── Admin section ──────────────────────────────────────────────────────── */

.admin-section { margin-top: 16px; }
.admin-section h3 { font-size: 1.1rem; margin-bottom: 16px; color: var(--muted); }

.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 16px; font-size: .875rem; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--orange); border-bottom-color: var(--orange); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.admin-toolbar { margin-bottom: 12px; }

.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th {
  text-align: left; color: var(--muted); padding: 8px 12px;
  border-bottom: 1px solid var(--border); font-weight: 500;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table code { font-size: .75rem; color: var(--orange); }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.text-red { color: var(--red); }

/* ── Modal ──────────────────────────────────────────────────────────────── */

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: 100%; max-width: 440px;
}
.modal-box h3 { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; }

/* ── TOTP setup layout ──────────────────────────────────────────────────── */

.totp-setup {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin: 24px 0;
}
@media (max-width: 600px) { .totp-setup { grid-template-columns: 1fr; } }

.totp-qr { text-align: center; }
.totp-qr p { margin-bottom: 12px; font-size: .875rem; }
.secret-fallback { margin-top: 12px; font-size: .75rem; color: var(--muted); word-break: break-all; }
.secret-fallback code { color: var(--orange); }

/* ── Info box ───────────────────────────────────────────────────────────── */

.info-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  font-size: .85rem;
}
.info-box strong { display: block; margin-bottom: 6px; color: var(--orange); }
.info-box p { margin-bottom: 8px; color: var(--muted); }
.info-box pre {
  background: #0d1117; border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; overflow-x: auto;
  font-size: .78rem; margin: 6px 0;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .auth-card { padding: 24px; }
  .main-content { padding: 0 16px; margin: 16px auto; }
  .status-card { padding: 20px; }
  .action-row { flex-direction: column; }
  .navbar { padding: 12px 16px; }
}
