/* ============================================================
   CricBata v3.0 — Layout Module
   Grid, flexbox, positioning, spacing utilities
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-root);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  line-height: 1.4;
  font-feature-settings: "tnum" 1, "kern" 1;
  -webkit-font-smoothing: antialiased;
}

/* Numbers always tabular */
.num, td, .amount, .rate, .stake {
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* --- App Shell --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh; /* Android WebView fix */
  overflow: hidden;
  position: relative;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

/* ============================================================
   HEADER & NAVIGATION LAYOUT
   ============================================================ */

.header {
  flex-shrink: 0;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  height: 44px;
  min-height: 44px;
  gap: 8px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.header-buttons {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* --- Navigation --- */
.nav-bar {
  display: flex;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}

.nav-item {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
  scroll-snap-align: start;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* --- Match Tabs Bar (second nav row) --- */
#match-tabs-bar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  align-items: center;
  min-height: 36px;
}

.match-quick-tab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg-chip);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.match-quick-tab:hover {
  background: var(--bg-chip-hover);
  border-color: var(--border);
}

.match-quick-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* --- Main Content --- */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.views-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: none;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* --- Scrollable Content Area --- */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
}

.content-inner {
  padding: 12px;
  max-width: 100%;
}

/* ============================================================
   GRID & FLEX UTILITIES
   ============================================================ */

.flex {
  display: flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gap-xs { gap: 4px; }
.gap-sm { gap: 8px; }
.gap-md { gap: 12px; }
.gap-lg { gap: 16px; }
.gap-xl { gap: 20px; }

.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

/* ============================================================
   SPACING UTILITIES
   ============================================================ */

.p-0 { padding: 0; }
.p-xs { padding: 4px; }
.p-sm { padding: 8px; }
.p-md { padding: 12px; }
.p-lg { padding: 16px; }
.p-xl { padding: 20px; }

.px-sm { padding-left: 8px; padding-right: 8px; }
.px-md { padding-left: 12px; padding-right: 12px; }
.px-lg { padding-left: 16px; padding-right: 16px; }

.py-sm { padding-top: 8px; padding-bottom: 8px; }
.py-md { padding-top: 12px; padding-bottom: 12px; }
.py-lg { padding-top: 16px; padding-bottom: 16px; }

.m-0 { margin: 0; }
.m-xs { margin: 4px; }
.m-sm { margin: 8px; }
.m-md { margin: 12px; }

.mx-auto { margin-left: auto; margin-right: auto; }
.my-auto { margin-top: auto; margin-bottom: auto; }

/* ============================================================
   SIZING
   ============================================================ */

.w-full { width: 100%; }
.h-full { height: 100%; }
.w-screen { width: 100vw; }
.h-screen { height: 100vh; }

/* ============================================================
   POSITIONING
   ============================================================ */

.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

.inset-0 { inset: 0; }
.top-0 { top: 0; }
.bottom-0 { bottom: 0; }
.left-0 { left: 0; }
.right-0 { right: 0; }

/* ============================================================
   LIST & TABLE LAYOUTS
   ============================================================ */

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

.list-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.15s ease;
}

.list-item:hover {
  background: var(--bg-hover);
}

.list-item:active {
  background: var(--bg-active);
}

.list-item.is-edited {
  background: var(--edit-highlight-color, rgba(255, 193, 7, 0.08));
  border-left: 3px solid var(--warning, #ffc107);
  padding-left: 9px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  background: var(--table-header-bg);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  font-size: 12px;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.table tr:hover {
  background: var(--bg-hover);
}

/* ============================================================
   SECTIONS & CONTAINERS
   ============================================================ */

.section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 0 6px 0;
  margin-top: 8px;
}

.section-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 0;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-header {
  font-weight: 600;
  font-size: 14px;
}

.card-content {
  font-size: 13px;
}

/* ============================================================
   EMPTY STATES
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  opacity: 0.5;
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================
   HIDDEN & VISIBILITY
   ============================================================ */

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================================
   OVERFLOW & TEXT
   ============================================================ */

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
