/* ═══════════════════════════════════════════
   ConfigFlow — Apple Design System
   ═══════════════════════════════════════════ */

:root {
  --bg: #f5f5f7;
  --card: rgba(255, 255, 255, 0.74);
  --card-solid: #ffffff;
  --fill: rgba(0, 0, 0, 0.045);
  --fill-2: rgba(0, 0, 0, 0.07);
  --border: rgba(0, 0, 0, 0.09);
  --sep: rgba(0, 0, 0, 0.06);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #aeaeb2;
  --accent: #0a84ff;
  --accent-strong: #0071e3;
  --accent-soft: rgba(10, 132, 255, 0.13);
  --green: #34c759;
  --green-strong: #248a3d;
  --green-soft: rgba(52, 199, 89, 0.15);
  --red: #ff3b30;
  --red-soft: rgba(255, 59, 48, 0.13);
  --orange: #ff9500;
  --orange-soft: rgba(255, 149, 0, 0.15);
  --code-bg: rgba(0, 0, 0, 0.045);
  --code-fg: #0a84ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

html.dark {
  --bg: #000000;
  --card: rgba(28, 28, 30, 0.72);
  --card-solid: #1c1c1e;
  --fill: rgba(255, 255, 255, 0.06);
  --fill-2: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.1);
  --sep: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --text-2: #98989d;
  --text-3: #636366;
  --accent: #0a84ff;
  --accent-strong: #409cff;
  --accent-soft: rgba(10, 132, 255, 0.2);
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.18);
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.18);
  --orange: #ff9f0a;
  --orange-soft: rgba(255, 159, 10, 0.18);
  --code-bg: rgba(255, 255, 255, 0.055);
  --code-fg: #64d2ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

::selection { background: var(--accent-soft); }

/* ── Cards ── */
.glass-card {
  background: var(--card);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  min-height: 40px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease, opacity 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { font-size: 12px; padding: 6px 14px; min-height: 30px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-soft { background: var(--accent-soft); color: var(--accent-strong); }
.btn-soft:hover { filter: brightness(1.05); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger-soft { background: var(--red-soft); color: var(--red); }
.btn-danger-soft:hover { filter: brightness(1.05); }

.btn-success-soft { background: var(--green-soft); color: var(--green-strong); }

.btn-ghost { background: var(--fill-2); color: var(--text-2); }
.btn-ghost:hover { background: var(--fill); color: var(--text); }

/* ── Inputs ── */
.label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }

.input {
  width: 100%;
  background: var(--fill);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.input::placeholder { color: var(--text-3); }
textarea.input { resize: vertical; }

select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2386868b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* ── Segmented control ── */
.segmented {
  display: inline-flex;
  background: var(--fill);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 34px;
  white-space: nowrap;
}
.segmented button.active {
  background: var(--card-solid);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ── iOS Switch ── */
.switch { position: relative; width: 46px; height: 28px; flex-shrink: 0; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--fill-2);
  transition: background 0.25s ease;
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track .switch-knob { transform: translateX(18px); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge-blue { background: var(--accent-soft); color: var(--accent-strong); }
.badge-green { background: var(--green-soft); color: var(--green-strong); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-gray { background: var(--fill-2); color: var(--text-2); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-apple { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 600px; }
.table-apple thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--sep);
  white-space: nowrap;
}
.table-apple tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--sep);
  color: var(--text-2);
  vertical-align: middle;
}
.table-apple tbody tr:last-child td { border-bottom: none; }
.table-apple tbody tr { transition: background 0.15s; }
.table-apple tbody tr:hover { background: var(--fill); }
.table-apple .mono { font-family: "SF Mono", SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* Mobile: tabel jadi kartu */
@media (max-width: 767px) {
  .table-apple { min-width: 0; }
  .table-apple thead { display: none; }
  .table-apple, .table-apple tbody { display: block; }
  .table-apple tbody tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 10px;
    padding: 12px 14px;
  }
  .table-apple tbody tr:hover { background: var(--card); }
  .table-apple tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: none;
    padding: 6px 0;
    text-align: right;
  }
  .table-apple tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    text-align: left;
    flex-shrink: 0;
  }
  .table-apple tbody td[data-label=""]::before { display: none; }
  .table-apple tbody td[data-label=""] { justify-content: flex-end; }
  .table-apple tbody tr td:first-child { padding-top: 8px; }
  .table-apple tbody tr td:last-child { padding-bottom: 8px; }
}

/* ── Modal / Bottom Sheet ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.modal-overlay.show .modal-backdrop { opacity: 1; }
.sheet {
  position: relative;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 26px 26px 0 0;
  padding: 8px 20px 28px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  overscroll-behavior: contain;
}
.modal-overlay.show .sheet { transform: translateY(0); }
.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: var(--fill-2);
  margin: 6px auto 12px;
}
.sheet-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

@media (min-width: 1024px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .sheet {
    max-width: 540px;
    border-radius: 22px;
    border-bottom: 1px solid var(--border);
    transform: scale(0.94) translateY(10px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
  }
  .modal-overlay.show .sheet { transform: none; opacity: 1; }
  .sheet-handle { display: none; }
}

/* ── Sidebar ── */
.sidebar-fixed { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  border-left: 3px solid transparent;
  user-select: none;
}
.nav-item:hover { background: var(--fill); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-item.active svg { color: var(--accent); }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Bottom Tab Bar (mobile) ── */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  background: var(--card);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-top: 1px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 6px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.15s ease;
  user-select: none;
  border: none;
  background: none;
}
.tab-btn svg { width: 24px; height: 24px; }
.tab-btn.active { color: var(--accent); }

.main-offset { margin-left: 260px; }
.content-bottom-safe { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

@media (max-width: 1023px) {
  .main-offset { margin-left: 0; }
  .sidebar-fixed { display: none; }
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 45;
  background: var(--card);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-bottom: 1px solid var(--sep);
  min-height: 52px;
}

/* ── Toast ── */
.toast-pill {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  z-index: 90;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  max-width: calc(100vw - 32px);
}
.toast-pill.show { transform: translateX(-50%) translateY(0); }
.toast-pill.success { color: var(--green-strong); }
.toast-pill.error { color: var(--red); }

/* ── Status dot ── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background 0.3s;
}
.status-dot.connected { background: var(--green); }
.status-dot.disconnected { background: var(--red); }
.status-dot.notconfigured { background: var(--orange); }

/* ── Misc ── */
pre {
  font-family: "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.code-box {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 14px;
  padding: 14px;
  font-size: 12px;
  overflow-x: auto;
  max-height: 60vh;
  overflow-y: auto;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--fill-2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner-lg { width: 34px; height: 34px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-3); font-size: 13px; }

.checkbox-apple {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.divider { height: 1px; background: var(--sep); border: none; margin: 0; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--fill-2); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

.letter-spacing-2 { letter-spacing: 0.2em; }

/* Terminal window (vpn-generator) */
.terminal-window {
  background: #0d1117;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.terminal-header {
  background: #161b22;
  padding: 8px 12px;
  display: flex;
  gap: 6px;
}
.terminal-window pre {
  margin: 0;
  padding: 14px;
  color: #58a6ff;
  font-size: 11px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-red { background: #ff5f56; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #27c93f; }

/* Status pulse */
.status-dot.online { background: #22c55e; box-shadow: 0 0 8px #22c55e; animation: pulse 2s infinite; }
.status-dot.offline { background: #475569; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Loading overlay */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 14px;
}

/* Lock screen */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 99999;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.app-content { filter: blur(10px); pointer-events: none; transition: all 0.5s; }
.app-content.unlocked { filter: blur(0); pointer-events: all; }

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 60;
  min-width: 160px;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}
.dropdown-menu button:hover { background: var(--fill); }
.dropdown-menu button.danger { color: var(--red); }
.dropdown-menu button:disabled { opacity: 0.35; cursor: not-allowed; }
.dropdown-menu .divider { margin: 6px 4px; }
