/* /assets/css/app.css
   App-wide styles for all pages (mobile-first).
   Browser compatibility: standards-based CSS, no experimental selectors.
   Assumes theme tokens are loaded from theme-light.css/theme-dark.css.
*/

/* ---------- Base Reset ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 10px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Layout Skeleton ---------- */
.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}

.main {
  flex: 1 1 auto;
  padding-top: 16px;
  padding-bottom: calc(16px + var(--bottom-nav-h));
}

/* Auth pages (no bottom nav) */
.main--auth {
  padding-bottom: 16px;
}

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  background: var(--surface);
}

.header__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}

.brand__name {
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.identity {
  display: none; /* shown on >= 420px */
  max-width: 46vw;
  text-align: right;
  line-height: 1.1;
}
.identity__label {
  font-size: 12px;
  color: var(--muted);
}
.identity__value {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 420px) {
  .identity { display: block; }
}

.header__pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.header__pill small {
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 0;
}
.footer__inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.footer__links a {
  text-decoration: underline;
  text-decoration-color: rgba(127, 127, 127, 0.35);
}

/* ---------- Bottom Nav (mobile-first) ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  box-shadow: var(--shadow-md);
}

.bottom-nav__inner {
  height: var(--bottom-nav-h);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  align-items: center;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: 14px;
  border: 1px solid transparent;
  color: var(--muted);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.nav-item__icon {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.nav-item__label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.nav-item--active {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-2);
}

/* Hide bottom nav on wider screens */
@media (min-width: 920px) {
  .bottom-nav { display: none; }
  .main { padding-bottom: 24px; }
}

/* ---------- Typography ---------- */
.h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 8px 0 12px; }
.h2 { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; margin: 14px 0 10px; }
.p  { font-size: 14px; color: var(--text-2); line-height: 1.5; margin: 0 0 10px; }
.small { font-size: 12px; color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card__title {
  font-weight: 800;
  letter-spacing: -0.01em;
}

.card__body { padding: 14px; }
.card__footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid transparent;
  font-weight: 750;
  letter-spacing: -0.01em;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  border-color: rgba(255, 255, 255, 0.10);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  box-shadow: none;
}

.btn--danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--danger);
}

.btn--full { width: 100%; }

.btn[disabled],
.btn.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ---------- Pills / Chips / Badges ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.pill--brand {
  background: var(--tag-bg);
  color: var(--tag-text);
  border-color: rgba(37, 99, 235, 0.20);
}

.pill--success { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.25); color: var(--success); }
.pill--warn    { background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.25); color: var(--warning); }
.pill--danger  { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.25); color: var(--danger); }
.pill--muted   { background: rgba(148, 163, 184, 0.14); border-color: rgba(148, 163, 184, 0.25); color: var(--muted); }

/* ---------- Forms ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label {
  font-size: 13px;
  font-weight: 750;
  color: var(--text);
}

.help {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--input-text);
  box-shadow: var(--shadow-sm);
}

.textarea {
  min-height: 110px;
  resize: vertical;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--input-placeholder);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 4px var(--focus);
}

/* ---------- Grid helpers ---------- */
.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 720px) {
  .row--2 { grid-template-columns: 1fr 1fr; }
}

/* Password strength meter */
.meter {
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}
.meter__bar {
  height: 100%;
  width: 25%;
  background: var(--warning);
}

/* ---------- Alerts / Notices ---------- */
.notice {
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 12px 12px;
  color: var(--text-2);
  line-height: 1.4;
}

.notice--info    { border-color: rgba(37, 99, 235, 0.25); background: rgba(37, 99, 235, 0.10); }
.notice--success { border-color: rgba(34, 197, 94, 0.25); background: rgba(34, 197, 94, 0.10); }
.notice--warn    { border-color: rgba(245, 158, 11, 0.25); background: rgba(245, 158, 11, 0.10); }
.notice--danger  { border-color: rgba(239, 68, 68, 0.25); background: rgba(239, 68, 68, 0.10); }

.notice strong { color: var(--text); }

/* ---------- Tables (simple, responsive) ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}
.table th, .table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}
.table th {
  color: var(--muted);
  font-weight: 800;
  background: var(--surface-2);
}

/* ---------- KPI Grid ---------- */
.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (min-width: 720px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

.kpi {
  padding: 14px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.kpi__label { font-size: 12px; color: var(--muted); font-weight: 750; }
.kpi__value { font-size: 18px; font-weight: 900; letter-spacing: -0.02em; margin-top: 6px; }

/* ---------- Lists (activity, results, comments) ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.item__meta {
  min-width: 0;
  flex: 1 1 auto;
}

.item__title {
  font-weight: 850;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.item__sub {
  font-size: 13px;
  color: var(--text-2);
  margin: 0 0 8px;
  line-height: 1.35;
}

.item__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.item__actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

/* ---------- Drawer / Modal Overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 40;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.overlay.is-open { display: flex; }

.drawer {
  width: 100%;
  max-width: 720px;
  background: var(--surface);
  border-radius: 22px 22px 16px 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.drawer__grab {
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}
.drawer__grab::before {
  content: "";
  width: 54px;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.55);
}

.drawer__header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drawer__title {
  font-weight: 900;
  letter-spacing: -0.02em;
}

.drawer__body {
  padding: 14px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.drawer__footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (min-width: 720px) {
  .overlay { align-items: center; }
  .drawer { border-radius: 22px; }
}

/* ---------- Simple chart bars ---------- */
.chart {
  display: grid;
  gap: 10px;
}

.bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.bar__label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 750;
}

.bar__track {
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--chart-1), var(--chart-2));
}

/* ---------- Utilities ---------- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 20px; }
.mt-5 { margin-top: 28px; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 20px; }
.mb-5 { margin-bottom: 28px; }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 16px; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }

.hr {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 14px 0;
}

.code {
  font-family: var(--mono);
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 12px;
}
