/* ============================================================
   GRE Manager – Stylesheet  (Light Mode Only)
   Font: Plus Jakarta Sans + DM Mono
   ============================================================ */

/* Force light mode regardless of OS/browser preference */
:root {
  color-scheme: light;

  --bg:         #ffffff;
  --bg-2:       #f8fafc;
  --bg-3:       #f1f5f9;
  --bg-4:       #e2e8f0;
  --border:     #e2e8f0;
  --border-2:   #cbd5e1;
  --text:       #0f172a;
  --text-2:     #475569;
  --text-3:     #94a3b8;
  --accent:     #2563eb;
  --accent-dim: rgba(37,99,235,.08);
  --accent-2:   #0891b2;
  --green:      #059669;
  --green-dim:  rgba(5,150,105,.09);
  --red:        #dc2626;
  --red-dim:    rgba(220,38,38,.09);
  --yellow:     #d97706;
  --yellow-dim: rgba(217,119,6,.09);
  --shadow-sm:  0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);
  --shadow:     0 2px 8px rgba(15,23,42,.08), 0 1px 3px rgba(15,23,42,.05);
  --shadow-lg:  0 8px 32px rgba(15,23,42,.12), 0 2px 8px rgba(15,23,42,.06);
  --radius:     10px;
  --radius-sm:  6px;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', 'Fira Code', Consolas, monospace;
  --sidebar-w:  230px;
  --header-h:   57px;
  --transition: .15s cubic-bezier(.4,0,.2,1);
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  /* Prevent Chrome forced-dark-mode from recolouring our page */
  background-color: #ffffff;
}

body {
  font-family: var(--font-body);
  background: var(--bg-2);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  /* Lock to light colour scheme at the element level too */
  color-scheme: light;
}

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


/* ── App Shell ────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sidebar-w);
  z-index: 100;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}
.brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,.28);
}
.brand-icon svg { width: 16px; height: 16px; color: #fff; }
.brand-name { font-size: .95rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); white-space: nowrap; }
.brand-accent { color: var(--accent); }

/* ── Sidebar Nav ─────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: .84rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none !important;
  cursor: pointer;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }

/* ── Sidebar Footer ──────────────────────────────────────── */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-badge { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: .71rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: .78rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .68rem; color: var(--text-3); }
.logout-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0; text-decoration: none !important;
  /* Reset für <button>-Element (Logout-Formular) */
  background: none; border: none; cursor: pointer; padding: 0;
  font: inherit;
}
.logout-btn svg { width: 14px; height: 14px; }
.logout-btn:hover { background: var(--red-dim); color: var(--red); }

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;          /* prevent flex child from overflowing */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
}

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}
.page-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}

/* ── Content Body ────────────────────────────────────────── */
.content-body {
  padding: 24px 28px;
  flex: 1;
  width: 100%;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  width: 100%;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  gap: 12px;
}
.card-title { font-size: .84rem; font-weight: 600; color: var(--text); }
.card-body { padding: 18px; }

/* ── Stats ───────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card.blue::after   { background: var(--accent); }
.stat-card.green::after  { background: var(--green); }
.stat-card.yellow::after { background: var(--yellow); }
.stat-card.red::after    { background: var(--red); }
.stat-label { font-size: .68rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 6px; }
.stat-value { font-family: var(--font-mono); font-size: 1.75rem; font-weight: 400; color: var(--text); line-height: 1; }
.stat-sub   { font-size: .72rem; color: var(--text-3); margin-top: 5px; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th {
  text-align: left; padding: 9px 16px;
  background: var(--bg-2);
  color: var(--text-3);
  font-size: .67rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-2); }
tbody td { padding: 10px 16px; color: var(--text-2); vertical-align: middle; }
.td-mono { font-family: var(--font-mono); font-size: .78rem; color: var(--text); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .68rem; font-weight: 600; letter-spacing: .03em; white-space: nowrap;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.badge-green  { background: var(--green-dim);  color: var(--green);  } .badge-green::before  { background: var(--green); }
.badge-red    { background: var(--red-dim);    color: var(--red);    } .badge-red::before    { background: var(--red); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); } .badge-yellow::before { background: var(--yellow); }
.badge-blue   { background: var(--accent-dim); color: var(--accent); } .badge-blue::before   { background: var(--accent); }
.badge-neutral { background: var(--bg-3); color: var(--text-3); } .badge-neutral::before { background: var(--border-2); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: .835rem; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  transition: all var(--transition); white-space: nowrap; text-decoration: none !important;
  line-height: 1;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 1px 3px rgba(37,99,235,.25);
}
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.btn-ghost {
  background: var(--bg); color: var(--text-2); border-color: var(--border-2);
  box-shadow: var(--shadow-sm);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text); border-color: var(--border-2); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: rgba(220,38,38,.2); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .775rem; }
.btn-icon { padding: 6px; }

/* ── Forms ───────────────────────────────────────────────── */
.form-grid { display: grid; gap: 14px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.col-span-2 { grid-column: span 2; }
.form-group.col-span-3 { grid-column: span 3; }

label { font-size: .75rem; font-weight: 600; color: var(--text-2); letter-spacing: .01em; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
select, textarea {
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-family: var(--font-body); font-size: .875rem; color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%; outline: none; -webkit-appearance: none;
  box-shadow: var(--shadow-sm);
  /* Prevent browser dark-mode from inverting form elements */
  color-scheme: light;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
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='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; cursor: pointer;
}
textarea { resize: vertical; min-height: 80px; font-family: var(--font-mono); font-size: .8rem; }
.form-hint { font-size: .71rem; color: var(--text-3); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* ── Toggle ──────────────────────────────────────────────── */
.toggle-group { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.toggle { position: relative; width: 38px; height: 21px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-4); border: 1px solid var(--border-2);
  border-radius: 999px; cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute; left: 2px; top: 50%;
  transform: translateY(-50%); width: 15px; height: 15px;
  border-radius: 50%; background: var(--text-3);
  transition: left var(--transition), background var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { left: 19px; background: #fff; }
.toggle-label { font-size: .84rem; color: var(--text-2); }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  font-size: .84rem; margin-bottom: 16px; border: 1px solid transparent;
}
.alert svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; }
.alert-success { background: var(--green-dim);  color: var(--green);  border-color: rgba(5,150,105,.2);  }
.alert-error   { background: var(--red-dim);    color: var(--red);    border-color: rgba(220,38,38,.2);  }
.alert-warning { background: var(--yellow-dim); color: var(--yellow); border-color: rgba(217,119,6,.2);  }
.alert-info    { background: var(--accent-dim); color: var(--accent); border-color: rgba(37,99,235,.15); }

/* ── Modals ──────────────────────────────────────────────── */
/*
 * IMPORTANT: Modals are hidden by default in CSS.
 * Inline style="display:none" in HTML is the first layer.
 * This CSS rule is the second layer — belt AND suspenders.
 * The .modal-open class (set by JS) overrides both.
 * Never use display:flex in the default rule, as it can flash
 * briefly on page load before inline styles are applied.
 */
.modal-backdrop {
  display: none;          /* hidden by default — JS adds .modal-open */
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(2px);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.modal-open {
  display: flex;
  animation: modalFadeIn .14s ease;
}
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  animation: modalSlideUp .16s ease;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal-wide { max-width: 680px; }
@keyframes modalSlideUp { from { transform: translateY(8px); opacity: 0; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 1;
}
.modal-title { font-size: .94rem; font-weight: 700; color: var(--text); }
.modal-close {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--text-3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition); font-size: 1rem; line-height: 1;
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--bg-2);
}

/* ── Section actions row ─────────────────────────────────── */
.section-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty-state svg { width: 36px; height: 36px; margin: 0 auto 12px; opacity: .35; display: block; }
.empty-state p { font-size: .88rem; }

/* ── Misc helpers ────────────────────────────────────────── */
.section-sep { height: 1px; background: var(--border); margin: 16px 0; }
.delete-confirm { color: var(--text-2); font-size: .875rem; line-height: 1.65; }
.delete-confirm strong { color: var(--red); }
.tunnel-iface {
  font-family: var(--font-mono); font-size: .67rem; color: var(--text-3);
  background: var(--bg-3); padding: 2px 6px;
  border-radius: 4px; border: 1px solid var(--border);
}

/* ── Rate limit msg ──────────────────────────────────────── */
.rate-limit-msg {
  background: var(--red-dim); border: 1px solid rgba(220,38,38,.2);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: .82rem; color: var(--red); margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}

/* ── Tunnel Cards (customer view) ────────────────────────── */
.tunnel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 16px;
}
.tunnel-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.tunnel-card:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.tunnel-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-2);
  border-bottom: 1px solid var(--border); gap: 12px;
}
.tunnel-name { font-weight: 700; font-size: .9rem; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tunnel-body { padding: 16px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.info-item { display: flex; flex-direction: column; gap: 3px; }
.info-label { font-size: .66rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; }
.info-value { font-family: var(--font-mono); font-size: .8rem; color: var(--text); }
.ip-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.ip-chip {
  font-family: var(--font-mono); font-size: .72rem;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid rgba(37,99,235,.15); border-radius: var(--radius-sm); padding: 2px 8px;
}

/* ── API URL box ─────────────────────────────────────────── */
.api-url-box {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
  font-family: var(--font-mono); font-size: .71rem; color: var(--text-2);
  word-break: break-all; position: relative;
}
.api-url-box .placeholder { color: var(--accent); font-weight: 600; }
.copy-btn {
  position: absolute; top: 7px; right: 7px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-2); cursor: pointer;
  font-size: .68rem; padding: 2px 7px; font-family: var(--font-body);
  transition: all var(--transition);
}
.copy-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Public / Login pages ────────────────────────────────── */
.public-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eff6ff 0%, #f8fafc 45%, #fafafa 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 390px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.login-header { padding: 26px 28px 20px; text-align: center; border-bottom: 1px solid var(--border); }
.login-logo {
  width: 46px; height: 46px; background: var(--accent);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px; box-shadow: 0 4px 14px rgba(37,99,235,.28);
}
.login-logo svg { width: 22px; height: 22px; color: #fff; }
.login-title { font-size: 1.25rem; font-weight: 800; letter-spacing: -.03em; margin-bottom: 3px; color: var(--text); }
.login-sub   { font-size: .8rem; color: var(--text-3); }
.login-body  { padding: 22px 28px; }
.login-footer { padding: 12px 28px; background: var(--bg-2); border-top: 1px solid var(--border); text-align: center; font-size: .73rem; color: var(--text-3); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .form-group.col-span-2, .form-group.col-span-3 { grid-column: span 1; }
  .content-body { padding: 16px 14px; }
  .page-header { padding: 0 14px; }
  .tunnel-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
