:root {
  --bg: #f9fafb;
  --panel: #ffffff;
  --muted: #6b7280;
  --border: #e6eef6;
  --accent: #258b96;
  --sidebar-bg: #eaeef5;
}

html,
body {
  height: 100%;
}
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial;
  margin: 0;
  background: var(--bg);
  color: #0f1724;
}

/* Prevent iOS Safari auto-zoom by ensuring controls aren't smaller than 16px */
@media (max-width: 640px) {
  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }
}

/* App layout */
.app-root {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 28px;
  box-shadow: 0 2px 8px rgba(15, 23, 36, 0.03);
  border-radius: 12px 0 0 12px;
}
.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: #254047;
  text-decoration: none;
  margin-top: 6px;
}
.sidebar nav a svg {
  width: 18px;
  height: 18px;
  flex: none;
  display: inline-block;
}
.sidebar nav a span {
  display: inline-block;
}
.sidebar nav a.active,
.sidebar nav a:hover {
  background: var(--accent);
  color: white;
}

.app-main {
  flex: 1;
  padding: 28px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.page-title {
  font-size: 20px;
  font-weight: 600;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Ensure language tab controls stay left-aligned when they wrap on small screens */
.tab-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-start; /* force left alignment instead of centering */
  gap: 8px;
}

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 6px 18px rgba(20, 30, 40, 0.04);
  border: 1px solid var(--border);
}
.controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Table styles */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}

/* Responsive table wrapper */
.data-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Sort indicators: use pseudo-elements via classes to avoid text arrows in JS */
th[data-key] {
  position: relative;
  cursor: pointer;
}
th[data-key]::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  margin-top: -6px;
  opacity: 0.25;
}
th[data-key].sorted-asc::after {
  border-bottom: 8px solid #374151; /* dark triangle down */
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  opacity: 0.9;
}
th[data-key].sorted-desc::after {
  border-top: 8px solid #374151; /* triangle up */
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  opacity: 0.9;
}

@media (max-width: 640px) {
  .data-table thead th,
  .data-table tbody td {
    padding: 8px 6px;
  }
  .sidebar {
    display: none; /* fallback for very small screens, overridden below for custom behavior */
  }
}

/* Responsive: stack table rows as cards on small screens */
@media (max-width: 640px) {
  .data-table {
    border: 0;
  }
  .data-table thead {
    display: none;
  }
  .data-table tbody tr {
    display: block;
    margin-bottom: 12px;
    background: var(--panel);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 4px 10px rgba(10, 20, 30, 0.04);
  }
  /* Mobile card header (company name) */
  .data-table tbody tr .company-cell {
    display: block;
    background: #567a9f;
    color: #e1e0e1;
    font-weight: 700;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
  }
  /* Card body: keep white background and zinc-600 text color */
  .data-table tbody tr > td:not(.company-cell) {
    background: #ffffff;
    color: rgb(74 85 104 / 1); /* tailwind zinc-600 approximation */
    display: flex;
    justify-content: space-between;
    padding: 8px 6px;
  }
  .data-table tbody td {
    display: flex;
    justify-content: space-between;
    padding: 8px 6px;
    border: none;
  }
  .data-table tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    flex: 0 0 45%;
    max-width: 45%;
    padding-right: 8px;
    font-weight: 600;
    text-align: left;
  }
  .data-table tbody td.flag-cell::before {
    content: ""; /* no label for flag cell */
    padding-right: 0;
    flex: 0 0 auto;
  }
}

/* Hamburger / mobile sidebar (for screens smaller than 1024x768) */
@media (max-width: 1023px) {
  .sidebar {
    display: block; /* ensure sidebar exists but as overlay */
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 240ms ease-in-out;
    z-index: 60;
    border-radius: 0;
    box-shadow: 0 12px 40px rgba(10, 20, 30, 0.3);
  }

  /* When body (or root) has .sidebar-open, slide the sidebar into view */
  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* small toggle button (hamburger) */
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    /* move to the very top-right corner, account for safe-area on iOS */
    top: calc(8px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
    z-index: 100; /* above overlay */
    width: 44px;
    height: 44px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 6px 16px rgba(10, 20, 30, 0.12);
    cursor: pointer;
  }

  /* Force display on small screens (avoid being hidden by page-specific styles) */
  .sidebar-toggle {
    display: inline-flex !important;
    /* let the button grow to fit label while keeping a minimum size */
    width: auto;
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    gap: 8px;
    box-sizing: border-box;
  }

  .sidebar-toggle .sidebar-toggle-label {
    display: inline-block;
    font-size: 13px;
    color: #0f1724;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
  }

  /* force the toggle to size to its content — override any earlier fixed width */
  .sidebar-toggle {
    width: auto !important;
    min-width: 48px !important;
    padding: 0 12px !important;
  }

  @media (min-width: 1024px) {
    .sidebar-toggle {
      display: none !important;
    }
    .sidebar-toggle .sidebar-toggle-label {
      display: none !important;
    }
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 50;
  }
  .sidebar-open .sidebar-overlay {
    display: block;
  }

  /* make main content scroll disabled when sidebar open */
  .sidebar-open .app-main {
    pointer-events: none;
  }
}
.data-table thead th {
  font-weight: 600;
  text-align: left;
  padding: 14px 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.data-table tbody td {
  padding: 14px 12px;
  border-top: 1px solid #f3f6f8;
}
.data-table tbody tr:hover {
  background: #fbfdfe;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* Ensure sidebar keeps its own background even when panel class is present */
.sidebar.panel {
  background: var(--sidebar-bg);
}
.page-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
}
.page-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
