:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  --btn: #1f2937;
  --btnHover: #273449;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}

.brand-title { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.topbar-actions { display: flex; gap: 10px; align-items: center; }
.search {
  width: min(520px, 46vw);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: var(--btnHover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tabs {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}

.tab {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.tab.active { background: var(--panel); }

.container { padding: 16px; }

.subtabs { display: flex; gap: 8px; margin-bottom: 12px; }
.subtab {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.subtab.active { background: var(--panel); }

.tabpane { display: none; }
.tabpane.active { display: block; }

.meta { color: var(--muted); font-size: 13px; margin: 10px 0; }

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
}
.row:hover { background: #131f35; }

.row-title { font-weight: 650; }
.row-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.row-right { color: var(--muted); font-size: 12px; align-self: center; }

.pager { margin-top: 12px; display: flex; justify-content: center; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal {
  width: min(980px, 95vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; }

.modal-body { padding: 14px; }

.kv {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(31,41,55,0.6);
}
.k { color: var(--muted); }
.v { text-align: right; }

.pre {
  margin-top: 12px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1222;
  color: #d1d5db;
  overflow: auto;
  font-size: 12px;
}

.cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 840px) {
  .cols { grid-template-columns: 1fr; }
}

.col-title {
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

.card {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
}
.card:hover { background: #131f35; }
/* =========================
   Mobile fixes
   ========================= */

/* Allow flex children to actually shrink (critical on mobile) */
.topbar,
.topbar-actions,
.tabs,
.subtabs,
.row,
.row-main {
  min-width: 0;
}

/* Make header wrap + stack on small screens */
@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .topbar-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Search should take full width on mobile */
  .search {
    width: 100%;
    flex: 1 1 100%;
  }

  /* Buttons sit under/next to search without squeezing it to death */
  .topbar-actions .btn {
    flex: 1 1 calc(50% - 4px);
    padding: 10px 10px;
  }

  .container { padding: 12px; }
}

/* Tabs/subtabs: horizontal scroll instead of squishing */
.tabs,
.subtabs {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar,
.subtabs::-webkit-scrollbar {
  display: none;
}
.tab,
.subtab {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Rows: prevent text from blowing out layout */
.row {
  align-items: flex-start;
}
.row-main {
  flex: 1 1 auto;
  min-width: 0;
}
.row-title,
.row-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}
.row-title {
  -webkit-line-clamp: 2;  /* title can wrap to 2 lines */
}
.row-sub {
  -webkit-line-clamp: 2;  /* subtitle can wrap to 2 lines */
}

/* Make modal usable on phones (not tiny centered box) */
@media (max-width: 640px) {
  .modal-overlay {
    padding: 10px;
    align-items: flex-end; /* "bottom sheet" feel */
  }

  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .modal-header {
    position: sticky;
    top: 0;
    background: var(--panel2);
    z-index: 1;
  }

  /* Easier tapping */
  .btn, .tab, .subtab {
    touch-action: manipulation;
  }
}

/* Optional: reduce motion for mobile perf */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
.topbar-actions { flex-wrap: wrap; }
/* =========================
   2x3 tile layout (desktop)
   ========================= */

/* 3 columns => shows as 2 rows when you have 6 items (2x3) */
.list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* Make each row look/act like a tile */
.row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  min-height: 120px;            /* tweak */
  padding: 14px;
}

/* Optional: tighten subtitle + prevent crazy tall tiles */
.row-sub {
  margin-top: 6px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;        /* tweak */
  overflow: hidden;
}

/* If you use .row-right anywhere, push it to bottom */
.row-right {
  margin-top: 10px;
}

/* Responsive: 2 columns on tablets */
@media (max-width: 980px) {
  .list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Responsive: 1 column on phones */
@media (max-width: 640px) {
  .list {
    grid-template-columns: 1fr;
  }
}