/************************************************************
 AKG MASTER WEBAPP – GLOBAL THEME (v1)
 Option 2: Refined + Consistent, NO functionality changes
*************************************************************/

/* ------------------------------
   ROOT + BASE
------------------------------ */

:root {
  --primary: #1e3a8a;
  --primary-light: #3b5bdb;
  --text-dark: #0f172a;
  --text-light: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --bg: radial-gradient(circle at top left, #e9efff 0, #f7f9fc 55%, #ffffff 100%);
  --card-bg: #ffffff;
  --shadow-soft: 0 10px 28px rgba(15,23,42,0.08);
  --shadow-tile: 0 6px 18px rgba(15,23,42,0.04);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-dark);
  min-height: 100vh;
}

/* Keep default button behavior; only normalize font */
button {
  font-family: inherit;
}

/* Utility wrappers – can be used across pages */
.page-wrapper {
  max-width: 1200px;
  margin: 34px auto 40px;
  padding: 0 22px;
}

.card,
.content-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 18px 22px;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border);
}

/* Generic container used in STR/RTR/Stage2 */
.container {
  width: 100%;
  max-width: 900px;
  margin: 30px auto 40px auto;
  padding: 22px 28px;
  background: var(--card-bg);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  box-sizing: border-box;
}

/* Slightly tighter on small screens */
@media (max-width: 900px) {
  .container {
    margin: 110px 16px 40px 16px;
    padding: 24px 18px;
  }
}

@media (max-width: 600px) {
  .container {
    margin: 90px 12px 30px 12px;
    padding: 20px 14px;
  }
}

/* ------------------------------
   UNIFIED HEADER (akg-header)
   Used by: home, records, master, dispatch, STR, RTR, Stage2, activity
------------------------------ */

.akg-header {
  width: 100%;
  padding: 18px 26px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #ffffffcc;
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-sizing: border-box;
}

.akg-header-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
}

.akg-header-sub {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 2px;
}

.akg-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* User pill variations (headerUserEmail, #userBox, etc.) */
.akg-user-pill,
#headerUserEmail,
#userBox {
  padding: 7px 14px;
  background: rgba(37, 99, 235, 0.10);
  color: var(--primary);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* In a few pages #userBox had slightly stronger bg – this still looks fine */
#userBox {
  background: rgba(37, 99, 235, 0.12);
}

/* Unified header buttons */
.akg-nav-btn,
.akg-logout-btn,
.akg-header-btn,
.akg-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
  white-space: nowrap;
}


.akg-btn-save {
  border: none;
  background:#004e0a;
  color: #fff;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: 0.2s ease;
}
.akg-btn-save:hover {
  background: #0eb427;
  transform: translateY(-1px);
}



.akg-btn.secondary {
  background: #0f172a;
}

.akg-nav-btn:hover,
.akg-logout-btn:hover,
.akg-header-btn:hover,
.akg-btn:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* Header – mobile behavior */
@media (max-width: 620px) {
  .akg-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }

  .akg-header-right {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }
}

/* ------------------------------
   TITLES / TEXT
------------------------------ */

h1 {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-light);
  margin-top: -4px;
  margin-bottom: 20px;
}

.section-title {
  font-weight: 700;
  font-size: 16px;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--text-dark);
}

/* Records / Activity section title variant */
.section-title.section-em {
  border-left: 4px solid var(--primary);
  padding-left: 10px;
  margin-top: 30px;
}

/* Center text helper */
.center-message {
  padding: 22px 10px;
  text-align: center;
  color: var(--text-light);
  font-size: 13px;
}

/* Loader spinner */
.loader {
  border: 3px solid #e5e7eb;
  border-top: 3px solid var(--primary-light);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  margin-right: 6px;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ------------------------------
   FILTER ROWS (Records + Activity)
------------------------------ */

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  min-width: 160px;
  flex: 1;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
}

.filter-group input,
.filter-group select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: #f8fafc;
}

.badge-count {
  font-size: 12px;
  color: var(--text-light);
}

/* ------------------------------
   TABLES + WRAPPERS
   Used by: records, activity, dispatch lists, STR store list, etc.
------------------------------ */

.table-wrapper {
  margin-top: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: #ffffff;
}

/* For tables placed directly without .table-wrapper, still allow scrolling on mobile */
.table-wrapper,
.table-scroll {
  overflow-x: auto;
}

/* Base table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: #eef2ff;
}

th,
td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}

/* Header: smaller font + avoid wrapping into 2 lines */
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: #f9fafb;
}

tbody tr:hover {
  background: #f1f5f9;
}

/* Records / Activity status pills */
.status-pill,
.st-success,
.st-error,
.status-success,
.status-pending,
.status-error {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

/* Activity */
.st-success { background:#dcfce7; color:#166534; }
.st-error   { background:#fee2e2; color:#991b1b; }

/* Records */
.status-success { background:#dcfce7; color:#166534; }
.status-pending { background:#fef9c3; color:#854d0e; }
.status-error   { background:#fee2e2; color:#991b1b; }

/* Details button in tables */
.btn-details {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 700;
  transition: 0.2s;
}

.btn-details:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* Timeline panel (activity page) */
.details-panel {
  margin-top: 16px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  padding: 12px 14px;
  background: #f8fafc;
  font-size: 12px;
  max-height: 260px;
  overflow: auto;
}

.timeline {
  border-left: 2px solid #cbd5e1;
  margin-left: 8px;
  padding-left: 12px;
}

.timeline-item {
  position: relative;
  margin-bottom: 10px;
  padding-left: 4px;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  position: absolute;
  left: -17px;
  top: 4px;
}

.timeline-time {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 2px;
}

.timeline-main {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dark);
}

.timeline-sub {
  font-size: 11px;
  color: #4b5563;
  margin-top: 2px;
}

.timeline-extra {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: #6b7280;
  margin-top: 2px;
  white-space: pre-wrap;
}

/* ------------------------------
   DASHBOARD GRID CARDS
   Used by: home, master/index, dispatch/index
------------------------------ */

.container-grid,
.grid-modules {
  max-width: 1080px;
  margin: 40px auto;
  padding: 0 22px;
  display: grid;
  gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* Home + Master + Dispatch cards */
.module-card,
.tile {
  padding: 24px 22px;
  border-radius: 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: 0.25s ease;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.module-card:hover,
.tile:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.10);
  border-color: #c7d2fe;
}

/* Disabled / coming soon */
.disabled,
.coming-soon-tile {
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(100%);
}

.module-icon {
  font-size: 40px;
  margin-bottom: 10px;
  color: var(--primary);
}

.module-title,
.tile-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-dark);
}

.module-desc,
.tile-desc {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.45;
}

/* Tile internal button */
.tile-btn {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  border: none;
  background: var(--text-dark);
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  width: fit-content;
}

.tile-btn:hover {
  background: var(--primary);
  transform: translateY(-1px);
}

/* ------------------------------
   FORMS / INPUTS
   Used by: STR, RTR, Stage2, Records filters
------------------------------ */

input[type="file"] {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  padding: 12px !important;
  background: #f8fafc !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  display: block !important;
  margin-bottom: 14px !important;
}

input,
select {
  font-family: inherit;
}

/* STR / RTR parameter inputs */
input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-size: 14px;
  margin-bottom: 14px;
}

input:focus,
select:focus {
  background: #ffffff;
  border-color: var(--primary-light);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.15);
}

/* RTR buffer triple inputs row */
.buffer-row {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  width: 100%;
}

.buffer-item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.buffer-item span {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
}

/* ------------------------------
   PRIMARY ACTION BUTTONS
   (Run STR, Run RTR, Stage2, etc.)
------------------------------ */

.btn-run,
.stage2-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  transition: 0.2s ease;
  margin-top: 10px;
}

/* STR / RTR main run buttons */
.btn-run {
  background: var(--primary);
  color: white;
}

.btn-run:hover {
  background: var(--primary-light);
  transform: translateY(-2px);
}

/* Stage 2 special button (kept gold) */
.stage2-btn {
  background: linear-gradient(135deg, rgb(192,157,1) 0%, rgb(192,157,1) 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(129,106,3,0.25);
}

.stage2-btn:hover {
  transform: translateY(-2px);
  box-shadow: 6px 6px 16px #f8c418;
}

/* Locked state – shared */
.btn-disabled {
  background: #9eb6ff !important;
  cursor: not-allowed !important;
  opacity: 0.7;
  pointer-events: none !important;
  transform: none !important;
}

/* Download buttons (STR/RTR/Records/Stage2) */
.download-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.download-buttons a {
  flex: 1;
  min-width: 45%;
  text-decoration: none;
}

.download-buttons button,
.download-btn {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: 0.2s;
}

.download-buttons button:hover,
.download-btn:hover {
  background: var(--primary-light);
  transform: translateY(-2px);
}

/* ------------------------------
   PROGRESS / ALERT BOXES
   (STR, RTR, Stage2, Records)
------------------------------ */

.output,
#loadingBox,
#successBox {
  margin-top: 24px;
  padding: 20px;
  border-radius: 14px;
  font-size: 14px;
}

/* Generic usage by RTR .output.processing/success/error */
.output.processing,
#loadingBox {
  background: #f0f4ff;
  color: var(--primary);
  border-left: 5px solid var(--primary);
}

.output.success,
#successBox {
  background: #f0fdf4;
  color: #166534;
  border-left: 5px solid #22c55e;
}

.output.error {
  background: #fef2f2;
  color: #991b1b;
  border-left: 5px solid #dc2626;
}

.progress-container {
  text-align: left;
}

.progress-label,
#loadingText {
  margin-bottom: 10px;
  font-weight: 700;
  color: var(--primary);
}

.progress-bar {
  width: 100%;
  height: 12px;
  background: #e0e7ff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.progress-fill,
#progressFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transition: width 0.4s ease;
}

/* ------------------------------
   MOBILE TWEAKS
   (Important for your issues)
------------------------------ */

@media (max-width: 600px) {

  /* Make primary buttons full-width and nicely stacked */
  .btn-run,
  .stage2-btn,
  .akg-nav-btn,
  .akg-logout-btn,
  .akg-header-btn,
  .akg-btn,
  .btn-details,
  .tile-btn,
  .download-buttons button,
  .download-btn {
    width: 100%;
    text-align: center;
  }

  /* Slightly smaller table font on mobile */
  th, td {
    font-size: 12px;
  }
}

/* ============================================================
   UNIVERSAL TABLE RESPONSIVE SCROLL (Mobile Friendly)
============================================================ */
.table-wrapper {
  width: 100%;
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch; /* smooth iPhone scrolling */
}

.table-wrapper table {
  min-width: 900px; /* large enough for your columns */
}
.table-wrapper::after {
  content: "Swipe →";
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 12px;
  color: #94a3b8;
}
@media (min-width: 700px) {
  .table-wrapper::after { display: none; }
}
