/* ============================================================
   Cloudflare dashboard recreation — base layer
   Tokens, reset, typography, application shell (topbar/sidebar)
   ============================================================ */

:root {
  /* Brand */
  --orange: #f6821f;
  --orange-hover: #de6d0f;
  --orange-active: #c25e07;
  --orange-soft: #fdf1e7;
  --orange-gradient-a: #fbad41;
  --orange-gradient-b: #f6821f;
  --orange-dark: #ba5a0d;

  /* Blues */
  --blue: #0051c3;
  --blue-hover: #0046a8;
  --blue-soft: #eef4fc;
  --blue-light: #4d94e8;

  /* Grays (Cloudflare-style ramp) */
  --gray-0: #ffffff;
  --gray-05: #fafafa;
  --gray-1: #f8f8f8;
  --gray-2: #f1f2f3;
  --gray-3: #e3e5e6;
  --gray-4: #d4d6d8;
  --gray-5: #b8bdbc;
  --gray-6: #98a0a3;
  --gray-7: #6b6f71;
  --gray-8: #36393a;
  --gray-9: #1d1f20;

  /* Status */
  --green: #16a34a;
  --green-deep: #128040;
  --green-soft: #ecf7ef;
  --red: #c5221f;
  --red-soft: #fdeeee;
  --amber: #b45309;
  --amber-soft: #fdf5e3;
  --purple: #6e43c8;
  --purple-soft: #f3eefa;

  /* Text */
  --text: #36393a;
  --text-strong: #1d1f20;
  --text-muted: #6b6f71;
  --text-faint: #98a0a3;

  /* Surfaces */
  --bg: #f8f8f8;
  --surface: #ffffff;
  --border: #e3e5e6;
  --border-strong: #d4d6d8;

  /* Layout */
  --topbar-h: 56px;
  --sidebar-w: 244px;
  --radius: 6px;
  --radius-lg: 8px;
  --shadow-1: 0 1px 2px rgba(29, 31, 32, 0.06), 0 1px 3px rgba(29, 31, 32, 0.08);
  --shadow-2: 0 4px 10px rgba(29, 31, 32, 0.10), 0 2px 4px rgba(29, 31, 32, 0.06);
  --shadow-3: 0 12px 32px rgba(29, 31, 32, 0.18), 0 4px 10px rgba(29, 31, 32, 0.10);
  --focus-ring: 0 0 0 3px rgba(0, 81, 195, 0.22);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Cloudflare Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Motion */
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --speed: 160ms;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-hover); text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 3px; }
::selection { background: rgba(246, 130, 31, 0.25); }

.skip-link {
  position: fixed; left: 8px; top: -48px; z-index: 300;
  background: var(--gray-9); color: #fff; padding: 8px 14px; border-radius: 4px;
  transition: top 120ms var(--ease);
}
.skip-link:focus { top: 8px; }

/* ---------------- Topbar ---------------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 0 12px;
  z-index: 100;
}

.topbar-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; margin-right: 4px;
  border-radius: var(--radius);
  color: var(--gray-9); font-weight: 600;
}
.topbar-logo:hover { background: var(--gray-2); text-decoration: none; }

.topbar-logo .logo-word {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--gray-9);
  white-space: nowrap;
}

.topbar-divider {
  width: 1px; height: 24px; background: var(--border); margin: 0 6px; flex: none;
}

.context-chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 10px;
  border-radius: var(--radius);
  border: none; background: transparent;
  color: var(--text-strong); font-weight: 500; font-size: 14px;
  cursor: pointer;
  max-width: 320px;
}
.context-chip:hover { background: var(--gray-2); }
.context-chip .ctx-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-chip .chev { color: var(--gray-6); flex: none; }
.context-chip.is-zone .ctx-icon { color: var(--gray-7); }

.topbar-spacer { flex: 1 1 auto; }

.topbar-search-btn {
  display: flex; align-items: center; gap: 8px;
  height: 34px; min-width: 210px; padding: 0 10px;
  background: var(--gray-2);
  border: 1px solid transparent; border-radius: var(--radius);
  color: var(--gray-7); font-size: 13px; cursor: pointer;
}
.topbar-search-btn:hover { background: var(--gray-3); }
.topbar-search-btn .kbd { margin-left: auto; }

.topbar-icon-btn {
  position: relative;
  width: 36px; height: 36px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: var(--radius);
  color: var(--gray-8); cursor: pointer;
}
.topbar-icon-btn:hover { background: var(--gray-2); }

.badge-dot {
  position: absolute; top: 4px; right: 3px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--orange); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px;
  border-radius: 8px; text-align: center;
  border: 2px solid var(--surface);
}

.avatar-btn {
  width: 34px; height: 34px; flex: none;
  border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, #36393a, #6b6f71);
  color: #fff; font-size: 13px; font-weight: 600;
}
.avatar-btn:hover { box-shadow: 0 0 0 3px var(--gray-3); }

/* ---------------- Layout ---------------- */

.layout {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: var(--topbar-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 8px 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-4) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--gray-4); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.main {
  flex: 1 1 auto;
  margin-left: var(--sidebar-w);
  min-width: 0;
  padding: 24px 32px 64px;
  max-width: 1560px;
}

/* ---------------- Sidebar nav ---------------- */

.side-group { margin-top: 10px; }
.side-group-label {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px 4px;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--gray-6);
  cursor: default; user-select: none;
}
.side-group-label.is-expandable { cursor: pointer; }
.side-group-label.is-expandable:hover { color: var(--gray-7); }

.side-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none; background: transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px; font-weight: 400;
  text-align: left; cursor: pointer;
  position: relative;
}
.side-item:hover { background: var(--gray-2); text-decoration: none; color: var(--text); }
.side-item .side-icon { color: var(--gray-7); flex: none; display: inline-flex; }
.side-item .side-label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-item.is-active {
  background: var(--gray-2);
  color: var(--gray-9);
  font-weight: 600;
}
.side-item.is-active::before {
  content: "";
  position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px;
  background: var(--orange);
  border-radius: 2px;
}
.side-item.is-active .side-icon { color: var(--gray-9); }
.side-item.is-child { padding-left: 26px; font-size: 12.5px; }
.side-item .side-caret { color: var(--gray-6); transition: transform 140ms var(--ease); flex: none; }
.side-item[data-open="true"] .side-caret { transform: rotate(90deg); }
.side-item .side-count {
  font-size: 11px; color: var(--gray-6);
  background: var(--gray-2); border-radius: 8px; padding: 0 6px; line-height: 16px;
}
.side-children { overflow: hidden; }
.side-children.is-open { animation: side-expand 160ms var(--ease); }
@keyframes side-expand { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.side-plan-card {
  margin: 14px 8px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fff, #fffaf5);
}
.side-plan-card .plan-name { font-weight: 600; font-size: 13px; color: var(--gray-9); display: flex; gap: 6px; align-items: center; }
.side-plan-card .plan-note { font-size: 12px; color: var(--gray-7); margin-top: 2px; }

/* ---------------- Page scaffolding ---------------- */

.page { animation: page-in 180ms var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header {
  display: flex; align-items: flex-start; gap: 16px;
  margin: 4px 0 20px;
  flex-wrap: wrap;
}
.page-title {
  margin: 0;
  font-size: 22px; font-weight: 600; letter-spacing: -0.2px;
  color: var(--gray-9);
  display: flex; align-items: center; gap: 10px;
  overflow-wrap: anywhere;
}
.page-subtitle { margin: 4px 0 0; color: var(--gray-7); font-size: 13.5px; max-width: 720px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.section { margin-bottom: 24px; }
.section-title {
  font-size: 15px; font-weight: 600; color: var(--gray-9);
  margin: 0 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.section-title .section-hint { font-weight: 400; font-size: 12.5px; color: var(--gray-6); }

.muted { color: var(--gray-7); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.nowrap { white-space: nowrap; }
.break-all { overflow-wrap: anywhere; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack-8 > * + * { margin-top: 8px; }
.stack-12 > * + * { margin-top: 12px; }
.stack-16 > * + * { margin-top: 16px; }
.stack-24 > * + * { margin-top: 24px; }
.grow { flex: 1 1 auto; min-width: 0; }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: var(--font); font-size: 11px; font-weight: 500;
  color: var(--gray-7);
  background: var(--surface);
  border: 1px solid var(--gray-4);
  border-bottom-width: 2px;
  border-radius: 4px;
  line-height: 16px;
}

/* Scrollable tables inside cards */
.table-scroll { overflow-x: auto; }

@media (max-width: 1080px) {
  .topbar-search-btn { min-width: 0; }
  .topbar-search-btn .search-text { display: none; }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: fixed; z-index: 90; left: 0;
    width: 244px; box-shadow: var(--shadow-3);
    transform: translateX(-100%);
    transition: transform 180ms var(--ease);
  }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; padding: 16px 16px 48px; }
  .sidebar-toggle { display: inline-flex !important; }
}
.sidebar-toggle {
  display: none;
  width: 36px; height: 36px; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: var(--radius);
  color: var(--gray-8); cursor: pointer;
}
.sidebar-toggle:hover { background: var(--gray-2); }
