/* ============================================================
   Shovel OS — chrome layer (drawer, app host, apps)
   Design: handheld operator / field OS. Relief via light:
   lit top edge + deep shadow. Reactive spring physics.
   ============================================================ */

:root {
  --ink:        #0a0c10;
  --surface:    #12151c;
  --surface-hi: #171b24;
  --surface-2:  #1b1f28;
  --row:        #14171f;
  --line:       #262b36;
  --line-soft:  #1b202a;

  --text:  #e6e9ef;
  --muted: #8b93a3;
  --dim:   #5b6474;

  --signal:     #4ade80;   /* system alive / live data — used sparingly */
  --signal-glow: rgba(74,222,128,.45);
  --amber:      #f2b24c;   /* terminal phosphor */
  --amber-glow: rgba(242,178,76,.40);

  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 11px;

  --e-card:   0 12px 30px rgba(0,0,0,.55), 0 2px 6px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.07);
  --e-card-lo:0 6px 16px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.05);
  --e-drawer: 0 -24px 70px rgba(0,0,0,.62), inset 0 1px 0 rgba(255,255,255,.09);

  --spring: cubic-bezier(.22,1,.36,1);
  --ease-out: cubic-bezier(.16,.84,.44,1);

  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* Living base: faint grain + soft top vignette so the ink is never dead-flat */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(126,150,190,.10), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
}
main.home { position: relative; z-index: 1; }

/* ---------- Edge handle (drag up from the bottom) ---------- */
#edge {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(30px + var(--safe-b));
  padding: 0 0 var(--safe-b);
  margin: 0; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  cursor: grab;
  touch-action: none;
}
#edge:active { cursor: grabbing; }
.edge-pill {
  width: 42px; height: 5px; border-radius: 999px;
  background: linear-gradient(180deg, #3a4150, #232833);
  box-shadow: 0 1px 0 rgba(255,255,255,.10), 0 6px 14px var(--signal-glow);
  transition: width .25s var(--spring), box-shadow .25s var(--ease-out);
}
#edge:active .edge-pill { width: 58px; box-shadow: 0 1px 0 rgba(255,255,255,.12), 0 6px 18px var(--signal-glow); }

/* ---------- Scrim ---------- */
#scrim {
  position: fixed; inset: 0;
  background: rgba(4,6,10,.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity .3s var(--ease-out), visibility .3s;
  z-index: 45;
}
#scrim.show { opacity: 1; visibility: visible; }

/* ---------- Drawer (frosted glass sheet) ---------- */
#drawer {
  position: fixed;
  left: 50%; bottom: 0;
  width: min(100%, 560px);
  transform: translate(-50%, 100%);
  z-index: 50;
  padding: 10px 18px calc(20px + var(--safe-b));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background:
    linear-gradient(180deg, rgba(23,27,36,.86), rgba(16,19,26,.82));
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  border-top: 1px solid rgba(255,255,255,.08);
  box-shadow: var(--e-drawer);
  touch-action: none;
  will-change: transform;
}
#drawer.animate { transition: transform .42s var(--spring); }

#drawer-grip { display: flex; justify-content: center; padding: 4px 0 12px; }
.grip-bar {
  width: 44px; height: 5px; border-radius: 999px;
  background: rgba(255,255,255,.16);
}

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 14px;
}
.os-name {
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700; letter-spacing: .22em;
  color: var(--muted);
}
.os-status {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 12px; color: var(--dim);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 10px var(--signal-glow);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.55} 50%{opacity:1} }

/* ---------- App grid (machined modules) ---------- */
#app-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.app-tile {
  position: relative;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px;
  min-height: 118px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-hi), var(--surface));
  box-shadow: var(--e-card);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .14s var(--ease-out), box-shadow .14s var(--ease-out);
}
.app-tile:active { transform: scale(.955); box-shadow: var(--e-card-lo); }
.app-tile .glyph {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 17px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
}
.app-tile[data-accent="amber"] .glyph { color: var(--amber); box-shadow: inset 0 0 16px rgba(242,178,76,.12), 0 0 0 1px rgba(242,178,76,.10); }
.app-tile[data-accent="signal"] .glyph { color: var(--signal); box-shadow: inset 0 0 16px rgba(74,222,128,.12), 0 0 0 1px rgba(74,222,128,.10); }
.app-tile .t-name {
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  letter-spacing: .04em;
}
.app-tile .t-sub { font-size: 11px; color: var(--dim); margin-top: -6px; }

/* ---------- Fullscreen app host ---------- */
#app-host {
  position: fixed; inset: 0;
  z-index: 60;
  transform: translateY(100%);
  transition: transform .4s var(--spring);
  background: var(--ink);
}
#app-host.open { transform: translateY(0); }

.app-screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--ink);
}
.app-screen.active { display: flex; }

.app-bar {
  position: relative;
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, var(--surface), rgba(18,21,28,.4));
}
.app-bar .back {
  appearance: none; border: 0; background: transparent;
  color: var(--muted); font-size: 20px; line-height: 1;
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center;
}
.app-bar .back:active { background: rgba(255,255,255,.05); }
.app-bar .app-title {
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  letter-spacing: .12em; color: var(--text);
}
.app-bar .badge {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em;
  color: var(--dim);
  padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.25);
  white-space: nowrap;
}
.app-bar .app-live {
  width: 7px; height: 7px; border-radius: 50%; margin-left: 10px;
  background: var(--signal); box-shadow: 0 0 10px var(--signal-glow);
}
.app-bar[data-accent="amber"] .app-live { background: var(--amber); box-shadow: 0 0 10px var(--amber-glow); }

/* Boot flash: phosphor sweep across the bar accent line on open */
.app-bar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--signal), transparent);
  transform: scaleX(0); transform-origin: left; opacity: 0;
}
.app-bar[data-accent="amber"]::after { background: linear-gradient(90deg, transparent, var(--amber), transparent); }
.app-screen.booting .app-bar::after { animation: boot .55s var(--ease-out); }
@keyframes boot {
  0%   { transform: scaleX(0); opacity: 1; }
  70%  { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}

.app-body { flex: 1 1 auto; overflow: hidden; position: relative; }

/* ---------- Flip Machine: category tree ---------- */
.tree {
  height: 100%; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  padding: 6px 0 calc(24px + var(--safe-b));
}
.tree-node > .row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 6px 16px;
  border: 0; background: transparent;
  color: var(--text);
  text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid var(--line-soft);
}
.tree-node > .row:active { background: rgba(255,255,255,.035); }
.tri {
  flex: 0 0 auto;
  width: 14px; height: 14px;
  color: var(--dim);
  transition: transform .2s var(--ease-out), color .2s;
  display: grid; place-items: center;
}
.tree-node.open > .row .tri { transform: rotate(90deg); color: var(--signal); }
.tri.leaf { visibility: hidden; }
.row .label { font-size: 13.5px; line-height: 1.35; letter-spacing: .01em; }
.row .count { margin-left: auto; font-size: 11px; color: var(--dim); }

/* depth tint: deeper = quieter */
.tree-node[data-depth="0"] > .row .label { color: var(--text); font-weight: 500; }
.tree-node[data-depth="1"] > .row .label { color: #c7ccd8; }
.tree-node[data-depth="2"] > .row .label { color: var(--muted); }

.children { display: none; }
.tree-node.open > .children { display: block; }

/* ---------- Terminal (agent launcher) ---------- */
.term-wrap { display: flex; flex-direction: column; height: 100%; }
.term-launch {
  flex: 0 0 auto;
  display: flex; gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #14120c, #0e0d09);
}
.agent-btn {
  flex: 1 1 0;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
  min-height: 60px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid rgba(242,178,76,.22);
  background: linear-gradient(180deg, rgba(242,178,76,.09), rgba(242,178,76,.03));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 8px 20px rgba(0,0,0,.45);
  color: var(--amber);
  cursor: pointer; text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: transform .14s var(--ease-out), box-shadow .14s var(--ease-out), border-color .2s;
}
.agent-btn:active { transform: scale(.97); }
.agent-btn.active {
  border-color: var(--amber);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 0 0 1px rgba(242,178,76,.5), 0 0 22px var(--amber-glow);
}
.agent-btn:disabled { opacity: .4; cursor: not-allowed; }
.agent-btn .ab-cmd { font-family: var(--font-mono); font-size: 15px; font-weight: 700; letter-spacing: .02em; }
.agent-btn .ab-cmd::before { content: "▸ "; opacity: .7; }
.agent-btn.active .ab-cmd::before { content: "▾ "; }
.agent-btn .ab-desc { font-size: 11px; color: var(--dim); }

.term-stage { flex: 1 1 auto; position: relative; background: #0b0b0a; }
.term-frame { width: 100%; height: 100%; border: 0; display: block; background: #0b0b0a; }
.term-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-mono); padding: 24px; text-align: center;
}
.term-empty .box { max-width: 340px; font-size: 13px; line-height: 1.7; color: var(--muted); }
.term-empty .box b { color: var(--amber); font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  *, *::after, *::before { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
