/* ============================================================
   Toolbox — design tokens & base styles
   Linear/Vercel-leaning: monochrome surfaces, sharp corners,
   indigo accent. Light + dark themes.
   ============================================================ */

:root {
  /* Light theme (default) */
  --bg:            #fafafa;
  --bg-elev:       #ffffff;
  --bg-sunken:     #f4f4f5;
  --panel:         #ffffff;
  --panel-hover:   #f8f8f9;
  --border:        #e6e6ea;
  --border-strong: #d4d4d8;
  --text:          #0a0a0b;
  --text-muted:    #6b6b75;
  --text-faint:    #a1a1aa;

  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-fg:     #ffffff;
  --accent-soft:   rgba(79, 70, 229, 0.08);
  --accent-ring:   rgba(79, 70, 229, 0.25);

  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 8px;

  --shadow-sm: 0 1px 0 rgba(0,0,0,0.02), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 1px 0 rgba(0,0,0,0.02), 0 4px 12px rgba(0,0,0,0.04);

  --font-sans: "Geist", ui-sans-serif, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  --header-h: 56px;
  --sidebar-w: 240px;
  --max-content: 1180px;
}

:root[data-theme="dark"] {
  --bg:            #08080a;
  --bg-elev:       #0f0f12;
  --bg-sunken:     #050507;
  --panel:         #0f0f12;
  --panel-hover:   #15151a;
  --border:        #1e1e23;
  --border-strong: #2a2a31;
  --text:          #f3f3f5;
  --text-muted:    #8a8a95;
  --text-faint:    #5a5a64;

  --accent:        #818cf8;
  --accent-hover:  #a5b4fc;
  --accent-fg:     #0a0a0b;
  --accent-soft:   rgba(129, 140, 248, 0.12);
  --accent-ring:   rgba(129, 140, 248, 0.32);

  --success:       #4ade80;
  --warning:       #fbbf24;
  --danger:        #f87171;

  --shadow-sm: 0 1px 0 rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.4);
  --shadow:    0 1px 0 rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  /* iOS: stop rubber-band scrolling from revealing the body background */
  overscroll-behavior-y: none;
  /* iOS: respect the safe area while still letting backgrounds bleed */
  min-height: 100dvh;
}

#root { min-height: 100dvh; }

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

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

code, kbd, pre {
  font-family: var(--font-mono);
}

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .08s ease;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--panel-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-color: var(--accent);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 500;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--panel-hover); color: var(--text); }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
}

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }

/* ---------- Inputs ---------- */
.input, .select {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
  font-size: 14px;
}
.input::placeholder { color: var(--text-faint); }
.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input-mono { font-family: var(--font-mono); font-size: 13px; }

.select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}

.label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: -0.005em;
}

/* ---------- Cards / Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-body { padding: 18px; }

/* ---------- Layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
  background: var(--bg);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: sticky;
  top: 0;
  /* iOS safe-area: respect the home indicator at the bottom */
  padding-bottom: env(safe-area-inset-bottom);
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.04em;
}
.sidebar-brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.sidebar-brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 1px;
  font-family: var(--font-mono);
}

.sidebar-section {
  padding: 16px 12px 8px;
}
.sidebar-section-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 450;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background .1s ease, color .1s ease;
}
.sidebar-link:hover { background: var(--panel-hover); color: var(--text); }
.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.sidebar-link .ico {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-foot .user {
  flex: 1;
  min-width: 0;
}
.sidebar-foot .user-name {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-foot .user-mail {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ---------- Main area ---------- */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
  gap: 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  position: sticky;
  top: 0;
  z-index: 20;
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
}
.topbar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar-crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}
.crumb-sep {
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.content {
  padding: 32px 24px 56px;
  flex: 1;
}
.content-inner {
  max-width: var(--max-content);
  margin: 0 auto;
}

.page-head { margin-bottom: 28px; }
.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.page-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

/* ---------- Tool grid (tile_style 2: flat squared cards) ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.tool-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .12s ease;
  min-height: 168px;
  position: relative;
  overflow: hidden;
}
.tool-card:hover {
  border-color: var(--border-strong);
  background: var(--panel-hover);
}
.tool-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.tool-card-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
[data-theme="dark"] .tool-card-icon {
  background: var(--bg);
}

.tool-card-name {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.tool-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}
.tool-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.tool-card-arrow {
  color: var(--text-faint);
  transition: transform .15s ease, color .15s ease;
}
.tool-card:hover .tool-card-arrow {
  color: var(--accent);
  transform: translateX(2px);
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 32px 24px;
  padding-top: max(32px, calc(env(safe-area-inset-top) + 32px));
  padding-bottom: max(32px, calc(env(safe-area-inset-bottom) + 32px));
  position: relative;
}
.login-form-col {
  position: static;
  display: contents;
}
.login-form {
  width: 100%;
  max-width: 340px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
}
.login-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.login-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  margin: 0 0 24px;
}
.login-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}
.login-hint {
  margin-top: 18px;
  padding: 10px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
}
.login-hint code {
  color: var(--text);
  background: var(--bg-elev);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-size: 11.5px;
}
.login-error {
  font-size: 12.5px;
  color: var(--danger);
  margin-top: -6px;
  margin-bottom: 4px;
}

.login-lang {
  position: absolute;
  top:   max(20px, calc(env(safe-area-inset-top) + 12px));
  right: max(20px, calc(env(safe-area-inset-right) + 12px));
  z-index: 2;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  margin-right: 6px;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

/* ---------- Tool detail ---------- */
.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.field-row.split {
  grid-template-columns: 2fr 1fr auto;
}

.kv-table {
  width: 100%;
  border-collapse: collapse;
}
.kv-table tr + tr td { border-top: 1px solid var(--border); }
.kv-table td {
  padding: 10px 0;
  font-size: 13px;
}
.kv-table .k {
  width: 40%;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}
.kv-table .v {
  font-family: var(--font-mono);
  color: var(--text);
  word-break: break-all;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 3px 7px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text-muted);
  text-transform: uppercase;
}

.rir-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.rir-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text);
  transition: border-color .1s ease, background .1s ease;
}
.rir-link:hover {
  border-color: var(--accent);
  background: var(--panel-hover);
  color: var(--text);
}
.rir-link .rir-name { font-weight: 500; }
.rir-link .rir-region {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
}

.dns-record {
  display: grid;
  grid-template-columns: 60px 1fr 80px;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  align-items: center;
}
.dns-record:first-child { border-top: none; }
.dns-record .type {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dns-record .data {
  font-family: var(--font-mono);
  word-break: break-all;
  color: var(--text);
}
.dns-record .ttl {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  text-align: right;
}

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

.pw-display {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pw-text {
  flex: 1;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 16px;
  word-break: break-all;
  letter-spacing: 0.02em;
  min-width: 0;
}
.pw-actions {
  display: flex;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}
.pw-actions button {
  height: 100%;
  padding: 0 14px;
  border: none;
  background: var(--bg-elev);
  color: var(--text-muted);
  transition: background .1s ease, color .1s ease;
  border-left: 1px solid var(--border);
}
.pw-actions button:first-child { border-left: none; }
.pw-actions button:hover { background: var(--panel-hover); color: var(--text); }

.pw-meter {
  height: 4px;
  background: var(--bg-sunken);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}
.pw-meter-fill {
  height: 100%;
  transition: width .3s ease, background .3s ease;
  border-radius: 2px;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  transition: border-color .1s ease, background .1s ease;
}
.check:hover { border-color: var(--border-strong); }
.check input { display: none; }
.check .box {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--bg);
  transition: background .1s ease, border-color .1s ease;
}
.check.on .box { background: var(--accent); border-color: var(--accent); }
.check.on .box svg { color: var(--accent-fg); }
.check .box svg { opacity: 0; }
.check.on .box svg { opacity: 1; }
.check .lbl { font-weight: 450; }

/* ---------- Toast / inline status ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 100;
  animation: toast-in 0.18s ease, toast-out 0.18s ease 1.4s forwards;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translate(-50%, -8px); }
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile toggle ---------- */
.mobile-menu-btn { display: none; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  /* (login-shell is now centered single-column at all widths) */
}

@media (max-width: 800px) {
  :root { --sidebar-w: 220px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 86vw;
    height: 100dvh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .mobile-menu-btn { display: inline-flex; }
  .content {
    padding: 24px 16px 48px;
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(48px, env(safe-area-inset-bottom));
  }
  .topbar {
    padding: 0 16px;
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-top: env(safe-area-inset-top);
  }
  .tool-grid { grid-template-columns: 1fr; }

  /* iOS Safari: prevent input zoom on focus by forcing >=16px */
  .input, .select, .pw-text { font-size: 16px; }
  .input[type="text"], .input[type="email"], .input[type="password"], .input[type="number"] {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .field-row.split { grid-template-columns: 1fr; }
  .pw-text { font-size: 14px; padding: 12px; }
  .dns-record { grid-template-columns: 50px 1fr; }
  .dns-record .ttl { display: none; }
}
