/**
 * miniapps.css — Mini-app system for JackyOS.
 *
 * Replaces multi-tab navigation with a single app grid home screen.
 * Each mini-app has a unique color accent, topbar with back button,
 * and self-contained full-screen experience.
 */

/* ═══════════════════════════════════════════════════════════════════
   Launcher Grid — The JackyOS Desktop
   ═══════════════════════════════════════════════════════════════════ */

.launcher {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px calc(env(safe-area-inset-bottom, 0px) + 32px);
  position: relative;
  overflow: hidden;
}

.launcher::before {
  content: '';
  position: absolute;
  top: -30%;
  left: 50%;
  transform: translateX(-50%);
  width: 200%;
  height: 80%;
  background: radial-gradient(ellipse at center, rgba(51, 161, 153, 0.06) 0%, transparent 60%);
  pointer-events: none;
}

/* ── Launcher Header ─────────────────────────────────────────────── */

.launcher-header {
  text-align: center;
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
  width: 100%;
}

/* Toolbar row — search + settings top-right (fixed to viewport) */
.launcher-toolbar {
  position: fixed;
  top: 12px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 50;
}

.launcher-tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--hint, rgba(255,255,255,0.5));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.launcher-tool-btn:active {
  background: rgba(255,255,255,0.12);
  color: var(--color-cream, #F5F0E1);
}

.launcher-logo {
  margin: 0 auto 14px;
  filter: drop-shadow(0 4px 16px rgba(180, 138, 60, 0.3));
  display: flex;
  justify-content: center;
}

.launcher-logo svg {
  width: 56px;
  height: 56px;
}

.launcher-greeting {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: var(--color-cream, #F5F0E1);
}

.launcher-date {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--hint, rgba(255,255,255,0.5));
}

/* ── Home Widget Cards ───────────────────────────────────────────── */

.hw-container {
  display: flex;
  gap: 8px;
  padding: 0 16px 8px;
  width: 100%;
  max-width: 420px;
  box-sizing: border-box;
}

.hw-card {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.78rem;
}

.hw-card--teal  { background: rgba(51,161,153,.1);  border: 1px solid rgba(51,161,153,.2); }
.hw-card--gold  { background: rgba(180,138,60,.1);  border: 1px solid rgba(180,138,60,.2); }
.hw-card--green { background: rgba(94,126,98,.1);   border: 1px solid rgba(94,126,98,.2); }

.hw-card-label {
  opacity: 0.55;
  font-size: 0.68rem;
  margin-bottom: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hw-card-value {
  font-weight: 500;
  opacity: 0.4;
}

/* progress-ring widget */
.hw-progress-ring {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hw-progress-pct {
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0.9;
}

/* ── Focus Cards ─────────────────────────────────────────────────── */

.focus-section {
  padding: 0 16px 8px;
  width: 100%;
  max-width: 420px;
  box-sizing: border-box;
}

.focus-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 6px;
  scrollbar-width: none;
}
.focus-strip::-webkit-scrollbar { display: none; }

.focus-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--chip-bg, var(--color-teal)) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip-bg, var(--color-teal)) 19%, transparent);
  color: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}

.pulse-indicators {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--hint);
  padding: 2px 0;
}

/* ── Quick Actions ───────────────────────────────────────────────── */

.launcher-quick-actions {
  display: flex;
  gap: 8px;
  padding: 0 16px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  width: 100%;
  max-width: 420px;
  box-sizing: border-box;
}
.launcher-quick-actions::-webkit-scrollbar { display: none; }

.launcher-quick-actions .jacky-ask-btn--secondary {
  flex: 0 0 auto;
  font-size: 0.78rem;
  padding: 4px 10px;
  white-space: nowrap;
}

/* ── App Grid ────────────────────────────────────────────────────── */

.launcher-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 16px;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
}

@media (min-width: 500px) {
  .launcher-grid {
    grid-template-columns: repeat(5, 1fr);
    max-width: 520px;
  }
}

/* ── App Icon ────────────────────────────────────────────────────── */

.ma-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 8px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.ma-icon:active {
  transform: scale(0.88);
}

/* App icon thumbnail — the rounded-rect "app tile" */
.ma-thumb {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 2px 8px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.08);
  transition: box-shadow 0.2s, transform 0.2s;
}

.ma-icon:active .ma-thumb {
  box-shadow:
    0 1px 4px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

/* Subtle shine overlay for glass effect */
.ma-thumb::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, transparent 100%);
  border-radius: 16px 16px 0 0;
  pointer-events: none;
}

.ma-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

/* SVG icon inside the app tile */
.ma-svg-icon {
  display: flex;
  color: #fff;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.35));
}
.ma-svg-icon .jb-icon {
  width: 32px;
  height: 32px;
}

/* App name label */
.ma-name {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary, rgba(255,255,255,0.7));
  text-align: center;
  line-height: 1.2;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Badge on app icon */
.ma-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  background: #e74c3c;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

/* ── Per-app color themes ────────────────────────────────────────── */

.ma-thumb[data-app="meteo"]    { background: linear-gradient(135deg, #1a6fca, #4da6ff); }
.ma-thumb[data-app="medicine"] { background: linear-gradient(135deg, #b83a3a, #e8665a); }
.ma-thumb[data-app="fitness"]  { background: linear-gradient(135deg, #2e8b57, #5dca88); }
.ma-thumb[data-app="calendario"] { background: linear-gradient(135deg, #c47a20, #f0b252); }
.ma-thumb[data-app="spesa"]   { background: linear-gradient(135deg, #6b4fa0, #9b7fd4); }
.ma-thumb[data-app="news"]    { background: linear-gradient(135deg, #1a6fca, #5295d6); }
.ma-thumb[data-app="finanza"] { background: linear-gradient(135deg, #1a7a5c, #33c98e); }
.ma-thumb[data-app="persone"] { background: linear-gradient(135deg, #b4632e, #e8956a); }
.ma-thumb[data-app="diario"]  { background: linear-gradient(135deg, #5c465c, #9b7d9b); }
.ma-thumb[data-app="spese"]   { background: linear-gradient(135deg, #8a6a2e, #d9c49a); }

/* ═══════════════════════════════════════════════════════════════════
   Briefing Strip — scrollable pills under the header
   ═══════════════════════════════════════════════════════════════════ */

.launcher-briefing {
  width: 100%;
  max-width: 420px;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
}

.briefing-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.briefing-scroll::-webkit-scrollbar { display: none; }

.briefing-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(255,255,255,0.06);
  color: var(--color-cream, #F5F0E1);
  border: 1px solid rgba(255,255,255,0.06);
  line-height: 1.3;
}

.briefing-event    { border-color: rgba(51, 161, 153, 0.3); background: rgba(51, 161, 153, 0.08); }
.briefing-reminder { border-color: rgba(217, 196, 154, 0.3); background: rgba(217, 196, 154, 0.08); }
.briefing-bill     { border-color: rgba(231, 76, 60, 0.25); background: rgba(231, 76, 60, 0.06); }
.briefing-birthday { border-color: rgba(255, 200, 50, 0.3); background: rgba(255, 200, 50, 0.08); }
.briefing-habits   { border-color: rgba(46, 139, 87, 0.3); background: rgba(46, 139, 87, 0.08); }
.briefing-signal   { border-color: rgba(231, 76, 60, 0.3); background: rgba(231, 76, 60, 0.08); }
.briefing-kb       { border-color: rgba(90, 130, 210, 0.3); background: rgba(90, 130, 210, 0.08); }

@media (min-width: 500px) {
  .launcher-briefing { max-width: 520px; }
}

/* ═══════════════════════════════════════════════════════════════════
   Launcher Footer — Library link
   ═══════════════════════════════════════════════════════════════════ */

.launcher-footer {
  margin-top: 28px;
  position: relative;
  z-index: 1;
}

.launcher-library-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--color-teal, #33A199);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.launcher-library-btn:active {
  background: rgba(51, 161, 153, 0.1);
  border-color: rgba(51, 161, 153, 0.3);
}
.launcher-library-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* ═══════════════════════════════════════════════════════════════════
   Reorder Mode — jiggle + done button
   ═══════════════════════════════════════════════════════════════════ */

.reorder-mode .ma-icon {
  animation: jiggle 0.25s ease-in-out infinite alternate;
}
.reorder-mode .ma-icon:nth-child(even) {
  animation-delay: 0.12s;
}
.reorder-mode .ma-icon.dragging {
  opacity: 0.4;
  animation: none;
}

@keyframes jiggle {
  0%   { transform: rotate(-1.5deg); }
  100% { transform: rotate(1.5deg); }
}

.reorder-done {
  display: block;
  margin: 16px auto 0;
  padding: 8px 28px;
  border-radius: 20px;
  border: none;
  background: var(--color-teal, #33A199);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.reorder-done:active { opacity: 0.8; }

@media (prefers-reduced-motion: reduce) {
  .reorder-mode .ma-icon {
    animation: none;
    outline: 2px dashed var(--color-teal, #33A199);
    outline-offset: 2px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Mini-App Topbar — Back + Title
   ═══════════════════════════════════════════════════════════════════ */

.ma-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg, #0B1917);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.ma-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--color-cream, #F5F0E1);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  flex-shrink: 0;
}

.ma-back:active {
  background: rgba(255,255,255,0.12);
}

.ma-back svg {
  width: 18px;
  height: 18px;
}

.ma-topbar-info {
  flex: 1;
  min-width: 0;
}

.ma-topbar-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.2;
}

.ma-topbar-sub {
  font-size: 0.72rem;
  color: var(--hint, rgba(255,255,255,0.5));
  font-weight: 500;
  margin: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   Mini-App Color Accents — topbar tinting
   ═══════════════════════════════════════════════════════════════════ */

.ma-topbar[data-app="meteo"]    { border-bottom-color: rgba(26, 111, 202, 0.2); }
.ma-topbar[data-app="medicine"] { border-bottom-color: rgba(184, 58, 58, 0.2); }
.ma-topbar[data-app="fitness"]  { border-bottom-color: rgba(46, 139, 87, 0.2); }
.ma-topbar[data-app="calendario"] { border-bottom-color: rgba(196, 122, 32, 0.2); }
.ma-topbar[data-app="spesa"]   { border-bottom-color: rgba(107, 79, 160, 0.2); }
.ma-topbar[data-app="news"]    { border-bottom-color: rgba(26, 111, 202, 0.2); }
.ma-topbar[data-app="finanza"] { border-bottom-color: rgba(26, 122, 92, 0.2); }
.ma-topbar[data-app="persone"] { border-bottom-color: rgba(180, 99, 46, 0.2); }
.ma-topbar[data-app="diario"]  { border-bottom-color: rgba(92, 70, 92, 0.2); }
.ma-topbar[data-app="spese"]   { border-bottom-color: rgba(138, 106, 46, 0.2); }

/* Accent bar — thin colored line under topbar */
.ma-topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 16px;
  right: 16px;
  height: 2px;
  border-radius: 1px;
  opacity: 0.5;
}

.ma-topbar[data-app="meteo"]::after    { background: #4da6ff; }
.ma-topbar[data-app="medicine"]::after { background: #e8665a; }
.ma-topbar[data-app="fitness"]::after  { background: #5dca88; }
.ma-topbar[data-app="calendario"]::after { background: #f0b252; }
.ma-topbar[data-app="spesa"]::after   { background: #9b7fd4; }
.ma-topbar[data-app="news"]::after    { background: #5295d6; }
.ma-topbar[data-app="finanza"]::after { background: #33c98e; }
.ma-topbar[data-app="persone"]::after { background: #e8956a; }
.ma-topbar[data-app="diario"]::after  { background: #9b7d9b; }
.ma-topbar[data-app="spese"]::after   { background: #d9c49a; }

/* ═══════════════════════════════════════════════════════════════════
   Mini-App Body — padded content area
   ═══════════════════════════════════════════════════════════════════ */

.ma-body {
  padding: 16px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 100px);
}

/* ═══════════════════════════════════════════════════════════════════
   Dock Override — hide tabs, keep only FAB
   ═══════════════════════════════════════════════════════════════════ */

body.miniapp-mode #tabbar {
  display: none !important;
}

body.miniapp-mode {
  padding-bottom: 0 !important;
}

/* FAB always visible even in miniapp mode */
body.miniapp-mode > .tabbar-fab {
  display: flex !important;
}

/* ═══════════════════════════════════════════════════════════════════
   Responsive — Tablets & Desktop
   ═══════════════════════════════════════════════════════════════════ */

@media (min-width: 640px) {
  .launcher-grid {
    grid-template-columns: repeat(5, 1fr);
    max-width: 540px;
    gap: 24px 20px;
  }

  .ma-thumb {
    width: 68px;
    height: 68px;
    border-radius: 18px;
  }

  .ma-body {
    max-width: 640px;
    margin: 0 auto;
  }

  /* Re-show tabbar on tablet as side rail */
  body.miniapp-mode #tabbar {
    display: none !important;
  }
}
