/* Appdation Core — Layout & base components
   Phone: header on top, nav as a bottom tab bar.
   Tablet/desktop (768px+): nav becomes a left sidebar. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.app {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: calc(var(--header-h) + var(--safe-top)) 1fr calc(var(--nav-h) + var(--safe-bottom));
  grid-template-areas: "header" "main" "nav";
}

.app-header {
  grid-area: header;
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: var(--safe-top) 16px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-logo { width: 32px; height: 32px; border-radius: 8px; }
.app-title { font-size: 1.1rem; font-weight: 650; margin: 0; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.install-btn {
  border: 0; border-radius: 999px; padding: 8px 16px;
  background: var(--primary); color: var(--on-primary);
  font-weight: 600; font-size: .9rem; cursor: pointer;
}

.app-main {
  grid-area: main;
  min-width: 0;
  width: 100%; max-width: 960px; margin: 0 auto;
  padding: 20px 16px 32px;
  outline: none;
}

.app-nav {
  grid-area: nav;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-decoration: none; color: var(--text-muted);
  font-size: .72rem; font-weight: 600;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--primary); }
.nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }

/* Tablet & desktop: sidebar nav */
@media (min-width: 768px) {
  .app {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header header" "nav main";
  }
  .app-nav {
    position: sticky; top: var(--header-h); bottom: auto;
    height: calc(100vh - var(--header-h));
    flex-direction: column; gap: 4px;
    padding: 16px 12px;
    border-top: 0; border-right: 1px solid var(--border);
  }
  .nav-item {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 12px 14px; border-radius: var(--radius-sm);
    font-size: .95rem;
  }
  .nav-item.active { background: var(--surface-2); }
  .app-main { padding: 28px 32px 48px; }
}

/* ---------- Typography ---------- */
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); margin: 0 0 20px; }
.section-label { font-size: .78rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted); margin: 24px 4px 8px; }

/* ---------- Components ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 0; border-radius: var(--radius-sm);
  background: var(--primary); color: var(--on-primary);
  font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-icon { min-height: 40px; width: 40px; padding: 0; background: transparent; color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%; min-height: 44px;
  padding: 10px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.textarea { min-height: 96px; resize: vertical; }

.list { list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list > li { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px; }
.list > li > .grow { min-width: 150px; }
.list > li + li { border-top: 1px solid var(--border); }

.empty { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

/* Toggle switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Segmented control */
.segmented { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.segmented button { flex: 1; white-space: nowrap; border: 0; background: transparent; border-radius: 8px; padding: 8px 10px; font-weight: 600; font-size: .88rem; color: var(--text-muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Toast */
.toast {
  position: fixed; left: 50%; z-index: 50;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 768px) { .toast { bottom: 24px; } }

/* Bottom sheet (iOS install hint, module dialogs) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 480px; background: var(--surface); color: var(--text);
  border-radius: 20px 20px 0 0; padding: 24px 20px calc(24px + var(--safe-bottom)); }
.sheet h2 { margin: 0 0 8px; font-size: 1.2rem; }
.sheet p { margin: 0 0 20px; color: var(--text-muted); line-height: 1.5; }
.sheet .btn { width: 100%; }
@media (min-width: 768px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 20px; } }

.boot-msg { padding: 48px 0; text-align: center; color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
