/* ============================================================
   getdesign-md viewer — Linear-inspired theme
   Tokens (and their values) are taken directly from
   getdesign-md/linear/DESIGN.md. Dark-mode-first.
   ============================================================ */

/* ---------- Tokens: Light (Linear's light-context neutrals) ---------- */
:root {
  --bg:          #f7f8f8;          /* Linear light background */
  --surface:     #ffffff;          /* Pure white card */
  --surface-2:  #f3f4f5;
  --surface-3:  #e9eaec;
  --hover:       rgba(8, 9, 10, .04);
  --selected:    rgba(94, 106, 210, .10);

  --text:        #08090a;
  --text-2:      #3c3f45;
  --text-3:      #62666d;
  --text-4:      #8a8f98;

  --border:      rgba(8, 9, 10, .08);
  --border-2:    rgba(8, 9, 10, .12);
  --line-tint:   rgba(8, 9, 10, .04);

  --accent:      #5e6ad2;          /* Linear brand indigo */
  --accent-2:    #7170ff;          /* Brighter interactive */
  --accent-3:    #828fff;          /* Hover */
  --accent-soft: rgba(94, 106, 210, .14);
  --accent-fg:   #ffffff;

  --success:     #10b981;
  --shadow-sm:   0 1px 0 rgba(8, 9, 10, .03), 0 1px 2px rgba(8, 9, 10, .04);
  --shadow-md:   0 1px 0 rgba(8, 9, 10, .04), 0 8px 24px rgba(8, 9, 10, .06);
  --shadow-lg:   0 1px 0 rgba(8, 9, 10, .04), 0 24px 60px -12px rgba(8, 9, 10, .12);
  --glow-accent: 0 0 0 1px rgba(94, 106, 210, .35), 0 0 24px -4px rgba(94, 106, 210, .35);

  --sans:  "Inter Variable", "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display",
           "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
           "Microsoft YaHei", sans-serif;
  --mono:  "Berkeley Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --feat:  "cv01", "ss03";
}

/* ---------- Tokens: Dark (Linear's native medium) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #08090a;        /* Marketing black */
    --surface:     #0f1011;        /* Panel */
    --surface-2:   #191a1b;        /* Elevated */
    --surface-3:   #28282c;        /* Hover surface */
    --hover:       rgba(255, 255, 255, .04);
    --selected:    rgba(113, 112, 255, .12);

    --text:        #f7f8f8;        /* Primary near-white */
    --text-2:      #d0d6e0;        /* Cool silver */
    --text-3:      #8a8f98;        /* Muted */
    --text-4:      #62666d;        /* Quaternary */

    --border:      rgba(255, 255, 255, .06);
    --border-2:    rgba(255, 255, 255, .10);
    --line-tint:   rgba(255, 255, 255, .03);

    --accent:      #5e6ad2;
    --accent-2:    #7170ff;
    --accent-3:    #828fff;
    --accent-soft: rgba(113, 112, 255, .16);
    --accent-fg:   #ffffff;

    --shadow-sm:   0 1px 0 rgba(0, 0, 0, .4);
    --shadow-md:   0 1px 0 rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg:   0 1px 0 rgba(0, 0, 0, .4), 0 30px 80px -12px rgba(0, 0, 0, .55);
    --glow-accent: 0 0 0 1px rgba(113, 112, 255, .45), 0 0 28px -2px rgba(113, 112, 255, .45);
  }
}

/* ---------- Reset / Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  font-feature-settings: var(--feat);
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  overflow: hidden;
}
button { font-family: inherit; font-feature-settings: var(--feat); }
::selection { background: var(--accent-soft); color: var(--text); }

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: 100vh;
  min-height: 0;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
  isolation: isolate;
}
/* Subtle "starlight" gradient — Linear's signature */
.sidebar::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(80% 40% at 50% 0%,  rgba(113, 112, 255, .08), transparent 70%),
    radial-gradient(60% 30% at 0% 100%, rgba(113, 112, 255, .05), transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.sidebar-header {
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--line-tint);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 510;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 14px;
}
.brand-mark {
  width: 18px; height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--accent) 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 1px 0 rgba(0,0,0,.2);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 4px;
  border-left: 1.5px solid rgba(255,255,255,.85);
  border-bottom: 1.5px solid rgba(255,255,255,.85);
  border-radius: 0 0 0 2px;
}
.brand-tag {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search {
  position: relative;
  display: flex; align-items: center;
}
.search input {
  width: 100%;
  height: 30px;
  padding: 0 30px 0 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: 510 13px/1 var(--sans);
  font-feature-settings: var(--feat);
  letter-spacing: -0.005em;
  outline: none;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.search input::placeholder { color: var(--text-4); font-weight: 400; }
.search input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-icon {
  position: absolute; left: 9px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-4);
  pointer-events: none;
}
.search .kbd {
  position: absolute; right: 7px;
  font-family: var(--mono); font-size: 10.5px; color: var(--text-3);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; background: var(--surface-2);
  line-height: 1.4;
}

.meta {
  padding: 10px 16px 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex; gap: 6px; align-items: baseline;
}
.meta #count {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 14px;
  scrollbar-gutter: stable;
}
.list-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 6px 14px;
  margin: 1px 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 510;
  letter-spacing: -0.005em;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  transition: background .12s ease, color .12s ease;
}
.list-item:hover {
  background: var(--hover);
  color: var(--text);
}
.list-item.is-active {
  background: var(--selected);
  color: var(--text);
}
.list-item.is-active::before {
  content: "";
  position: absolute;
  left: 3px; top: 7px; bottom: 7px;
  width: 2px;
  background: var(--accent-2);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--accent-2);
}
.list-item .label {
  overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.list-item .badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text-4);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .15s ease;
}
.list-item:hover .badge,
.list-item.is-active .badge { opacity: 1; }
.list-item.is-active .badge { color: var(--accent-2); }

.sidebar-footer {
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-4);
  border-top: 1px solid var(--line-tint);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-footer a { color: inherit; text-decoration: none; transition: color .15s; }
.sidebar-footer a:hover { color: var(--text-2); }

/* ============================================================
   Main column
   ============================================================ */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  gap: 16px;
  z-index: 5;
}
/* Linear-style hairline glow under topbar */
.topbar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-2) 30%, var(--border-2) 70%, transparent);
}

.title { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.title h1 {
  font-size: 13.5px;
  font-weight: 590;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.012em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title .sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-4);
  letter-spacing: 0;
}

.actions { display: flex; align-items: center; gap: 8px; }

/* ----- Theme switch ----- */
.theme-switch {
  position: relative;
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  height: 30px;
}
.theme-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px;
  border: 0; background: transparent; color: var(--text-3);
  font-size: 12px; font-weight: 510;
  letter-spacing: -0.005em;
  border-radius: 5px;
  cursor: pointer;
  transition: color .15s ease;
  z-index: 1;
}
.theme-btn:hover { color: var(--text-2); }
.theme-btn.is-active {
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border);
}

/* ----- Buttons ----- */
.ghost-btn, .primary-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border-radius: 7px;
  font-size: 12px; font-weight: 510;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background .15s ease, color .15s ease,
              border-color .15s ease, box-shadow .15s ease,
              transform .08s ease;
  white-space: nowrap;
}
.ghost-btn {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.ghost-btn:hover {
  color: var(--text);
  border-color: var(--border-2);
  background: var(--surface-3);
}
.ghost-btn:active { transform: translateY(0.5px); }

.primary-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid color-mix(in srgb, var(--accent) 80%, #000);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.18),
    0 1px 2px rgba(0,0,0,.18),
    0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}
.primary-btn:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.20),
    0 4px 14px -4px color-mix(in srgb, var(--accent-2) 70%, transparent),
    0 0 0 1px color-mix(in srgb, var(--accent-2) 40%, transparent);
}
.primary-btn:active { transform: translateY(0.5px); }
.primary-btn.is-success {
  background: var(--success);
  border-color: var(--success);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 0 0 1px color-mix(in srgb, var(--success) 30%, transparent);
}

/* ============================================================
   Preview
   ============================================================ */
.preview-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(50% 35% at 50% 0%, color-mix(in srgb, var(--accent-2) 6%, transparent), transparent 70%),
    var(--bg);
  overflow: hidden;
}
/* Faint dot grid in the canvas */
.preview-wrap::before {
  content: "";
  position: absolute; inset: 0;
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: 0 0;
  opacity: .35;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(120% 80% at 50% 50%, #000 50%, transparent 100%);
          mask-image: radial-gradient(120% 80% at 50% 50%, #000 50%, transparent 100%);
}

.frame {
  position: relative;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  display: block;
  z-index: 1;
}
/* Re-key animation each load via .is-entering */
.frame.is-entering {
  animation: frame-in 480ms cubic-bezier(.2, .7, .2, 1) both;
  transform-origin: 50% 30%;
}
@keyframes frame-in {
  0%   { opacity: 0; transform: translateY(8px) scale(.985); filter: blur(6px); }
  60%  { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: translateY(0)   scale(1);     filter: blur(0); }
}

/* Loading shimmer overlay (visible only while iframe is loading) */
.loader {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
  z-index: 2;
}
.loader.is-visible { opacity: 1; }
.loader-bar {
  position: absolute; left: 0; right: 0; top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: loader-slide 1.2s ease-in-out infinite;
}
@keyframes loader-slide {
  0%   { background-position: -40% 0; }
  100% { background-position: 140% 0; }
}

.empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  z-index: 2;
}
.empty[hidden], .frame[hidden] { display: none !important; }

.empty-card {
  position: relative;
  max-width: 480px;
  text-align: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-lg);
  animation: fade-up 600ms cubic-bezier(.2,.7,.2,1) both;
}
.empty-card::before {
  content: "";
  position: absolute; inset: -1px;
  border-radius: 15px;
  padding: 1px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent-2) 35%, transparent), transparent 60%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none;
}
.empty-icon {
  width: 44px; height: 44px;
  margin: 0 auto 14px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  display: grid; place-items: center;
  color: #fff;
  box-shadow: var(--glow-accent);
}
.empty-card h2 {
  font-size: 16px;
  font-weight: 590;
  margin: 0 0 6px;
  color: var(--text);
  letter-spacing: -0.012em;
}
.empty-card p {
  margin: 0;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.65;
  letter-spacing: -0.005em;
}
.empty-card code {
  font-family: var(--mono); font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 4px;
}
.empty-hint {
  margin-top: 16px;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px;
  color: var(--text-4);
}
.empty-hint .kbd {
  font-family: var(--mono); font-size: 10.5px;
  border: 1px solid var(--border-2);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--surface-2);
  color: var(--text-3);
}

@keyframes fade-up {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translate(-50%, 8px);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 510;
  letter-spacing: -0.005em;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .2s ease, transform .25s cubic-bezier(.2,.7,.2,1);
  pointer-events: none;
  z-index: 1000;
  display: inline-flex; align-items: center; gap: 8px;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast .toast-dot {
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* ============================================================
   Scrollbar
   ============================================================ */
.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 4px;
  border: 2px solid var(--surface);
  background-clip: padding-box;
}
.list::-webkit-scrollbar-thumb:hover { background: var(--text-4); background-clip: padding-box; }
.list::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .frame.is-entering, .empty-card { animation: none !important; }
  * { transition-duration: .01ms !important; }
}
