/* ==========================================================================
   KubaOS mobile.css - v1.1 M6 (Workstream G)
   The PHONE SHELL: status bar, app grid, page dots, bottom nav, action sheets,
   notifications shade, recents, and the fullscreen-activity chrome. Shares the
   desktop.css tokens (--navy / --amber / --paper ...). Active only when
   <body class="kt-mobile">; the desktop layout is untouched at >=820px.
   Reduced-motion blanket rule at the bottom (16.7).
   Safe-area insets via env(safe-area-inset-*); content fills 100dvh minus bars.
   ========================================================================== */

/* the shell takes over the whole viewport; the desktop surfaces stay hidden */
body.kt-mobile #kt-desktop,
body.kt-mobile #kt-widgets,
body.kt-mobile #kt-windows,
body.kt-mobile #kt-taskbar,
body.kt-mobile #kt-wallpaper-live {
  display: none !important;
}

.kt-mobile-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  background: var(--navy-deep, #0f172a);
  color: var(--paper, #f6f3ec);
  overflow: hidden;
  /* the shell carries its own wallpaper class (kt-wp-*) painted by mobile.js */
  background-size: cover;
  background-position: center;
}

/* wallpaper class hooks mirror the desktop ones, scoped to the shell */
.kt-mobile-shell.kt-wp-floorplan { background-image: url("../img/wallpapers/floorplan.svg"); }
.kt-mobile-shell.kt-wp-dawn { background-image: url("../img/wallpapers/dawn.svg"); }
.kt-mobile-shell.kt-wp-nightshift { background-image: url("../img/wallpapers/nightshift.svg"); }
.kt-mobile-shell.kt-wp-crt { background-image: url("../img/wallpapers/crt.svg"); }
.kt-mobile-shell.kt-wp-custom { background-image: var(--kt-custom-wp); }
.kt-mobile-shell.kt-wp-solid-1 { background-image: none; background-color: #1e293b; }
.kt-mobile-shell.kt-wp-solid-2 { background-image: none; background-color: #0f172a; }
.kt-mobile-shell.kt-wp-solid-3 { background-image: none; background-color: #2c3344; }
.kt-mobile-shell.kt-wp-solid-4 { background-image: none; background-color: #34302a; }
.kt-mobile-shell.kt-wp-solid-5 { background-image: none; background-color: #1a2230; }
.kt-mobile-shell.kt-wp-solid-6 { background-image: none; background-color: #122; }

/* ---- status bar ---- */
.kt-m-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  padding: env(safe-area-inset-top) 14px 0 14px;
  padding-top: calc(env(safe-area-inset-top) + 2px);
  box-sizing: content-box;
  font-size: 13px;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  cursor: pointer;
  user-select: none;
  flex: 0 0 auto;
}
.kt-m-status-right { display: flex; align-items: center; gap: 8px; }
.kt-m-status-sig { display: inline-flex; align-items: center; gap: 4px; }
.kt-m-sig-label { font-size: 10px; opacity: 0.85; }
.kt-m-sig-bars { width: 16px; height: 11px; }
.kt-m-sig-bars rect { fill: var(--amber, #e8a020); }
.kt-m-status-batt { display: inline-flex; align-items: center; gap: 3px; }
.kt-m-batt-pct { font-size: 11px; opacity: 0.9; }
.kt-m-batt-glyph { width: 24px; height: 11px; color: var(--paper, #f6f3ec); }

/* ---- live wallpaper (LEDs only) ---- */
.kt-m-wallpaper-live {
  position: absolute;
  inset: 30px 0 60px 0;
  pointer-events: none;
  z-index: 0;
}
.kt-m-wl-block {
  position: absolute;
  border: 1px solid rgba(232, 160, 32, 0.16);
  border-radius: 4px;
  background: rgba(232, 160, 32, 0.04);
}
.kt-m-wl-led {
  position: absolute;
  left: 5px; top: 5px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #7dd87d;
  animation: kt-m-led 4.5s ease-in-out infinite;
  animation-delay: var(--led-delay, 0s);
}
@keyframes kt-m-led {
  0%, 44% { background: #7dd87d; box-shadow: 0 0 4px #7dd87d; }
  50%, 94% { background: #e8a020; box-shadow: 0 0 4px #e8a020; }
  100% { background: #7dd87d; box-shadow: 0 0 4px #7dd87d; }
}

/* ---- home (grid + dots) ---- */
.kt-m-home {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.kt-m-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: min-content;
  gap: 6px 2px;
  align-content: start;
  padding: 14px 8px 6px 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.kt-m-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 4px 2px;
  background: none;
  border: 0;
  color: var(--paper, #f6f3ec);
  cursor: pointer;
  border-radius: 12px;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.kt-m-icon:active { background: rgba(255, 255, 255, 0.08); }
.kt-m-icon.kt-m-icon-dragging { background: rgba(232, 160, 32, 0.18); opacity: 0.85; }
.kt-m-icon-glyph {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}
.kt-m-icon-glyph .kt-glyph { width: 52px; height: 52px; }
.kt-m-icon-label {
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
  max-width: 76px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
/* B1 hue ramp carries through on phone too */
.kt-m-icon[data-tool="cic-maker"] { --tool-accent: #e8732a; }
.kt-m-icon[data-tool="sop-maker"] { --tool-accent: #6fa83a; }
.kt-m-icon[data-tool="panel-instructions"] { --tool-accent: #4f7bb0; }
.kt-m-icon[data-tool="panel-measurement"] { --tool-accent: #3aa6a0; }
.kt-m-icon[data-tool="sop-studio"] { --tool-accent: #8b6fc0; }
.kt-m-icon[data-tool="kpscan"] { --tool-accent: #e8902a; }
.kt-m-icon[data-tool="mentid"] { --tool-accent: #4fb0a8; }

.kt-m-dots {
  display: flex;
  justify-content: center;
  gap: 7px;
  padding: 8px 0 6px 0;
  flex: 0 0 auto;
}
.kt-m-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transition: background 0.18s;
}
.kt-m-dot.kt-on { background: var(--amber, #e8a020); }

/* ---- bottom nav ---- */
.kt-m-nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 56px;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid rgba(232, 160, 32, 0.2);
  z-index: 3;
  flex: 0 0 auto;
}
.kt-m-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: 0;
  color: var(--paper, #f6f3ec);
  cursor: pointer;
  padding: 4px 18px;
  border-radius: 10px;
  font: inherit;
}
.kt-m-nav-btn:active { background: rgba(255, 255, 255, 0.08); }
.kt-m-nav-btn .kt-glyph { width: 24px; height: 24px; }
.kt-m-nav-label { font-size: 10px; }

/* ---- fullscreen activities ---- */
.kt-m-activities {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
}
.kt-m-activities.kt-m-activities-on { display: block; }
.kt-m-activity {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--paper, #f6f3ec);
  color: var(--ink, #1c2433);
}
.kt-m-activity.kt-m-activity-on { display: flex; }
.kt-m-appbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: env(safe-area-inset-top) 8px 0 4px;
  padding-top: calc(env(safe-area-inset-top));
  background: var(--navy, #1e293b);
  color: var(--paper, #f6f3ec);
  flex: 0 0 auto;
}
.kt-m-appbar-back,
.kt-m-appbar-overflow {
  background: none;
  border: 0;
  color: var(--paper, #f6f3ec);
  cursor: pointer;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
.kt-m-appbar-back:active,
.kt-m-appbar-overflow:active { background: rgba(255, 255, 255, 0.12); }
.kt-m-appbar-back .kt-glyph { width: 22px; height: 22px; transform: rotate(180deg); }
.kt-m-appbar-title {
  flex: 1 1 auto;
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kt-m-dot3 { font-weight: 800; letter-spacing: 1px; }
.kt-m-activity-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-overflow-scrolling: touch;
}

/* ---- bottom sheet (action / overflow / custom) ---- */
.kt-m-sheet-backdrop {
  position: fixed; inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
}
.kt-m-sheet {
  width: 100%;
  background: var(--surface, #fff);
  color: var(--ink, #1c2433);
  border-radius: 16px 16px 0 0;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom)) 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
  transform: translateY(100%);
  transition: transform 0.2s ease;
  max-height: 70vh;
  overflow-y: auto;
}
.kt-m-sheet.kt-m-sheet-in { transform: translateY(0); }
.kt-m-sheet-grip {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.2);
  margin: 4px auto 8px auto;
}
.kt-m-sheet-title {
  font-weight: 800;
  font-size: 15px;
  padding: 4px 18px 10px 18px;
  color: var(--ink, #1c2433);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.kt-m-sheet-list { display: flex; flex-direction: column; padding: 4px 0; }
.kt-m-sheet-item {
  text-align: left;
  background: none;
  border: 0;
  padding: 14px 18px;
  font: inherit;
  font-size: 15px;
  color: var(--ink, #1c2433);
  cursor: pointer;
}
.kt-m-sheet-item:active { background: rgba(0, 0, 0, 0.06); }
.kt-m-sheet-item.kt-danger { color: var(--danger, #c0392b); }
.kt-m-sheet-item.kt-disabled { color: var(--ink-muted, #5b6578); opacity: 0.6; }
.kt-m-sheet-sep { height: 1px; background: rgba(0, 0, 0, 0.08); margin: 4px 0; }
.kt-m-sheet-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 18px 4px 18px;
}
.kt-m-rename { padding: 6px 18px 4px 18px; }
.kt-m-rename-label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--ink-muted, #5b6578); }
.kt-m-rename-input {
  width: 100%; box-sizing: border-box;
  padding: 10px 12px; font: inherit; font-size: 15px;
  border: 1px solid rgba(0, 0, 0, 0.2); border-radius: 8px;
}

/* ---- notifications shade ---- */
.kt-m-shade-backdrop {
  position: fixed; inset: 0;
  z-index: 65;
  background: rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column;
}
.kt-m-shade {
  background: var(--navy, #1e293b);
  color: var(--paper, #f6f3ec);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 16px 14px;
  border-radius: 0 0 18px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  transform: translateY(-100%);
  transition: transform 0.22s ease;
  max-height: 85vh;
  overflow-y: auto;
}
.kt-m-shade.kt-m-shade-in { transform: translateY(0); }
.kt-m-shade-toggles { display: flex; gap: 10px; margin-bottom: 14px; }
.kt-m-toggle {
  flex: 1 1 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(232, 160, 32, 0.3);
  background: rgba(255, 255, 255, 0.05);
  color: var(--paper, #f6f3ec);
  font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer;
}
.kt-m-toggle.kt-on { background: var(--amber, #e8a020); color: var(--navy-deep, #0f172a); border-color: var(--amber, #e8a020); }
.kt-m-shade-head { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.7; margin: 12px 0 6px 0; }
.kt-m-shade-list { display: flex; flex-direction: column; gap: 4px; }
.kt-m-shade-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  font-size: 13px;
}
.kt-m-shade-item .kt-glyph { width: 18px; height: 18px; flex: 0 0 auto; }
.kt-m-shade-empty { padding: 10px 12px; font-size: 13px; opacity: 0.6; }
.kt-m-shade-close {
  display: block; width: 100%;
  background: none; border: 0; cursor: pointer;
  padding: 10px 0 2px 0;
}
.kt-m-shade-grip {
  display: block; width: 44px; height: 4px;
  border-radius: 2px; margin: 0 auto;
  background: rgba(255, 255, 255, 0.3);
}

/* ---- recents (card stack) ---- */
.kt-m-recents-backdrop {
  position: fixed; inset: 0;
  z-index: 62;
  background: rgba(15, 23, 42, 0.9);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(70px + env(safe-area-inset-bottom)) 16px;
  overflow-y: auto;
}
.kt-m-recents { display: flex; flex-direction: column; gap: 14px; }
.kt-m-recents-empty { color: var(--paper, #f6f3ec); opacity: 0.6; text-align: center; margin-top: 40px; }
.kt-m-recent-card {
  background: var(--paper, #f6f3ec);
  color: var(--ink, #1c2433);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s, opacity 0.15s;
  touch-action: pan-y;
}
.kt-m-recent-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.kt-m-recent-top .kt-glyph { width: 30px; height: 30px; }
.kt-m-recent-title { font-weight: 700; font-size: 15px; }
.kt-m-recent-actions { display: flex; gap: 10px; }

/* ---- pull-to-refresh spinner ---- */
.kt-m-refresh {
  position: absolute;
  top: 40px; left: 50%;
  width: 26px; height: 26px;
  margin-left: -13px;
  border: 3px solid rgba(232, 160, 32, 0.3);
  border-top-color: var(--amber, #e8a020);
  border-radius: 50%;
  z-index: 4;
  animation: kt-m-spin 0.7s linear infinite;
}
@keyframes kt-m-spin { to { transform: rotate(360deg); } }

/* ---- low-power amber tint (battery hits 0% / <=12%) ---- */
body.kt-m-lowpower .kt-mobile-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(232, 160, 32, 0.12);
  z-index: 5;
  animation: kt-m-lowpulse 3s ease-in-out infinite;
}
@keyframes kt-m-lowpulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

/* ==========================================================================
   M6b per-app adaptations. Apps render through their SHARED mount(); these
   rules adapt the layout for the phone via [data-m-app] on the body and the
   activity content host. No app code forks per platform.
   ========================================================================== */

/* Deep Clean: cell size >= 40px on phone (the flag toggle button is added by
   the game when it sees presenterKind mobile / a coarse pointer). */
body.kt-mobile .kt-dc-cell { min-width: 40px; min-height: 40px; }

/* About viewer: pages stack full-width; zoom controls hidden (pinch is cut). */
body.kt-mobile .kt-pdf-zoom { display: none; }
body.kt-mobile .kt-pdf-page { width: 100% !important; max-width: 100%; }

/* Commander: it already stacks under 820px; make the active pane fill width. */
body.kt-mobile .kt-mc-pane { width: 100%; }

/* Paint full-bleed canvas inside the activity */
body.kt-mobile .kt-paint-stage { width: 100%; }

/* generic: any windowed app host inside an activity fills the area */
.kt-m-activity-content .kt-app-host,
.kt-m-activity-content > * { max-width: 100%; }

/* ==========================================================================
   Reduced-motion blanket rule (16.7): all ambient/decorative motion OFF.
   Battery/clock values still update (JS), but LEDs, sheet/shade slides, the
   low-power pulse, the refresh spinner and card transitions are static.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .kt-m-wl-led { animation: none; }
  .kt-m-sheet { transition: none; }
  .kt-m-shade { transition: none; }
  .kt-m-recent-card { transition: none; }
  .kt-m-refresh { animation: none; }
  body.kt-m-lowpower .kt-mobile-shell::after { animation: none; opacity: 0.8; }
  .kt-m-dot { transition: none; }
}
body.kt-reduce-fx .kt-m-wl-led,
body.kt-reduce-fx .kt-m-refresh { animation: none; }
body.kt-reduce-fx .kt-m-sheet,
body.kt-reduce-fx .kt-m-shade,
body.kt-reduce-fx .kt-m-recent-card { transition: none; }
