/*
 * SIMA overrides on top of the Sneat theme.
 * Loaded on every page through layouts/style. Keeps the existing look and
 * fixes accessibility and mobile issues found in the UI review.
 */

:root {
  --sima-focus: #696cff;          /* Sneat primary */
  --sima-focus-ring: rgba(105, 108, 255, 0.35);
  --sima-touch: 44px;             /* minimum touch target */
}

/* ---- Text contrast (WCAG AA, 4.5:1 for normal text) ---------------------
   Sneat defaults measured against white: body text 4.40, muted text 2.31,
   white on primary 4.05, white on success green 1.74. The values below are
   the nearest shades that pass, so the look barely changes. */
:root {
  --bs-body-color: #637385;       /* 4.86:1 */
  --bs-secondary-color: #6e757d;  /* 4.66:1 */
  --bs-link-color: #6164eb;       /* 4.63:1 */
  --bs-link-hover-color: #5658d0;
}
body {
  color: var(--bs-body-color);
}
.text-muted {
  color: #6e757d !important;
}
.breadcrumb-item a,
.landing-nav-menu .nav-link:not([aria-current="page"]) {
  color: #637385;
}
.btn-primary {
  --bs-btn-bg: #6164eb;
  --bs-btn-border-color: #6164eb;
  --bs-btn-hover-bg: #5658d0;
  --bs-btn-hover-border-color: #5658d0;
  --bs-btn-active-bg: #5658d0;
  --bs-btn-active-border-color: #5658d0;
  background-color: #6164eb;
  border-color: #6164eb;
}
.btn-primary:hover,
.btn-primary:focus-visible,
.btn-primary:active {
  background-color: #5658d0 !important;
  border-color: #5658d0 !important;
}
/* Sneat colours links and outline buttons with #696cff directly (4.05:1). */
a {
  color: #6164eb;
}
a:hover {
  color: #5658d0;
}
.btn-outline-primary {
  color: #6164eb;
  border-color: #6164eb;
}
.btn-outline-primary:hover,
.btn-outline-primary:focus-visible,
.btn-outline-primary:active {
  color: #fff !important;
  background-color: #5658d0 !important;
  border-color: #5658d0 !important;
}
/* Keep the lime green, but put dark text on it (7.3:1) instead of white. */
.btn-success,
.btn-success:hover,
.btn-success:focus-visible,
.btn-success:active,
.btn-success:disabled {
  color: #1b3a07 !important;
}

/* ---- Keyboard focus: always visible ------------------------------------ */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--sima-focus);
  outline-offset: 2px;
}
.form-control:focus-visible,
.form-select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 0.25rem var(--sima-focus-ring);
}

/* ---- Clickable things look clickable ----------------------------------- */
button:not(:disabled),
.btn:not(:disabled),
[role="button"],
summary,
label[for],
.dataTables_wrapper .paginate_button,
.dt-container .dt-paging-button,
table.dataTable thead th.dt-orderable-asc,
table.dataTable thead th.dt-orderable-desc,
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
  cursor: pointer;
}

/* ---- Active nav link (set by js/sima.js) ------------------------------- */
.landing-nav-menu .nav-link[aria-current="page"] {
  color: var(--sima-focus) !important;
  font-weight: 600 !important;
}

/* ---- Wide tables scroll in their own box, not the page ----------------- */
.sima-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.dataTables_wrapper,
.dt-container {
  max-width: 100%;
}
.dataTables_wrapper .dataTables_filter input,
.dt-container .dt-search input {
  max-width: 100%;
}

/* ---- A .row placed straight in a <section> (no .container) has negative
        side margins that stick out past the screen. -------------------- */
section > .row {
  margin-left: 0;
  margin-right: 0;
}

/* ---- Logo in the navbar must not push the page wider ------------------- */
.app-brand-logo.demo,
.app-brand-logo.demo img {
  max-width: 120px;
  height: auto;
}

/* ---- Phones and tablets ------------------------------------------------ */
@media (max-width: 767.98px) {
  /* Button groups in page headers wrap instead of running off screen. */
  .d-flex:has(> .btn + .btn),
  .d-flex:has(> a.btn + a.btn),
  .d-flex:has(> form > .btn) {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* DataTables controls stack and use the full width. */
  .dt-container .dt-layout-row:not(.dt-layout-table) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .dt-container .dt-search,
  .dt-container .dt-length {
    text-align: left;
  }
  /* Extra specificity: DataTables' own CSS loads after this file. */
  .dt-container .dt-search input.dt-input {
    display: block;
    width: 100%;
    margin-left: 0;
    box-sizing: border-box;
  }
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    float: none;
    text-align: left;
    margin-bottom: 0.5rem;
  }
  .dataTables_wrapper .dataTables_filter input {
    width: 100%;
    margin-left: 0;
  }
}

/* Touch screens: controls at least 44px tall so they are easy to tap. */
@media (pointer: coarse) {
  .btn,
  .form-control,
  .form-select,
  .page-link,
  .dataTables_wrapper .paginate_button,
  .dt-container .dt-paging-button {
    min-height: var(--sima-touch);
  }
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .btn-icon {
    min-width: var(--sima-touch);
  }
}

/* ---- Respect "reduce motion" ------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ======================================================================
   Dashboards (resources/views/dashboard/*)
   ====================================================================== */
.sima-dash {
  background:
    radial-gradient(1200px 380px at 10% -10%, rgba(105, 108, 255, 0.10), transparent 60%),
    radial-gradient(900px 300px at 100% 0%, rgba(113, 221, 55, 0.10), transparent 60%);
}
.sima-dash-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.sima-dash-title {
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem);
  font-weight: 600;
  color: #384551;
  margin-bottom: 0.25rem;
}
.sima-dash-date {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6e757d;
}
.sima-dash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.sima-card-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: #384551;
  margin-bottom: 0.125rem;
}
.sima-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #6e757d;
  margin: 0.75rem 0 0.25rem;
}
.sima-empty {
  padding: 1rem;
  border: 1px dashed #d9dee3;
  border-radius: 0.5rem;
  text-align: center;
  color: #637385;
  margin: 0.25rem 0 0;
}

/* KPI cards */
.sima-kpi .card-body { padding: 1.25rem; }
.sima-kpi-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  font-size: 1.375rem;
  margin-bottom: 0.75rem;
}
.sima-kpi-label {
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}
.sima-kpi-value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
  color: #384551;
  margin-bottom: 0.25rem;
  font-variant-numeric: tabular-nums;
}
.sima-kpi-of {
  font-size: 1rem;
  font-weight: 500;
  color: #6e757d;
}
.sima-kpi-sub {
  font-size: 0.8125rem;
  margin-bottom: 0;
  font-variant-numeric: tabular-nums;
}
.sima-trend {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  white-space: nowrap;
}
.sima-trend.is-up { color: #2b6b0f; }
.sima-trend.is-down { color: #b3261e; }

/* Chart */
.sima-chart { min-height: 260px; }
.sima-chart-table summary {
  font-size: 0.875rem;
  color: var(--bs-link-color);
  width: fit-content;
}

/* Status: always icon + text, never colour alone. All pairs >= 4.5:1. */
.sima-status,
.sima-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}
.sima-status--lunas, .sima-pill--free { background: #e8f7df; color: #2b6b0f; }
.sima-status--dp                      { background: #fff2d6; color: #7a4f00; }
.sima-status--belum                   { background: #ffe3dd; color: #b3261e; }
.sima-status--unknown                 { background: #eceef1; color: #4b5866; }
.sima-pill--busy                      { background: #e7e7ff; color: #4a4cc4; }

/* Lists */
.sima-trips li + li,
.sima-unpaid li + li,
.sima-fleet-item + .sima-fleet-item {
  border-top: 1px solid #eceef1;
}
.sima-row-link {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 0.5rem;
  color: inherit;
  min-height: 44px;
  transition: background-color 0.15s ease;
}
.sima-row-link:hover { background: #f5f5f9; color: inherit; }
.sima-row-main { flex: 1 1 auto; min-width: 0; }
.sima-row-main > * { overflow-wrap: anywhere; }
.sima-fleet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0;
}
.sima-date-chip {
  flex: 0 0 auto;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 0.5rem;
  background: #f0f0ff;
  color: #4a4cc4;
  line-height: 1.05;
}
.sima-date-chip.is-live { background: #e8f7df; color: #2b6b0f; }
.sima-date-chip-day { font-size: 1.125rem; font-weight: 700; }
.sima-date-chip-mon { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; }

@media (max-width: 575.98px) {
  .sima-kpi .card-body { padding: 1rem; }
  .sima-kpi-value { font-size: 1.5rem; }
  .sima-dash-actions, .sima-dash-actions .btn { width: 100%; }
  .sima-row-link .sima-status { align-self: flex-start; }
}

/* Crew dashboard */
.sima-alert { color: #5c3d00; background: #fff2d6; border-color: #ffd98a; }
.sima-current { border: 2px solid #b9e8a0; }
.sima-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem 1.25rem;
  margin: 0;
}
.sima-facts dt {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6e757d;
}
.sima-facts dd { margin: 0; color: #384551; font-weight: 500; }

/* Order detail (detail_pesanan) */
.sima-order-head.section-py { padding-bottom: 1.25rem; }
.sima-order-summary .sima-facts { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.sima-facts-wide { grid-column: 1 / -1; }
.sima-doc-head .btn { white-space: nowrap; }
/* Tabs stay on one row and scroll on small screens instead of wrapping. */
.sima-doc-tabs > .nav-tabs {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.sima-doc-tabs > .nav-tabs::-webkit-scrollbar { display: none; }
.sima-doc-tabs > .nav-tabs .nav-link { white-space: nowrap; min-height: 44px; }
.sima-doc-tabs > .nav-tabs .nav-link.active {
  color: #4a4cc4;
  font-weight: 600;
  box-shadow: inset 0 -3px 0 #6164eb;
}
/* Shown by js when a form has unsaved edits. */
.sima-unsaved {
  display: none;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #7a4f00;
  margin-right: auto;
}
form.is-dirty .sima-unsaved { display: inline-flex; }
/* Negative money values (e.g. Total Sisa below zero). */
.sima-negative { color: #b3261e !important; font-weight: 600; }

/* Quick filters above large tables (js/sima.js section 6) */
.sima-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin: 0 0 1rem;
}
.sima-filter { min-width: 160px; }
.sima-filter .form-label { font-size: 0.75rem; }
@media (max-width: 575.98px) {
  .sima-filter { flex: 1 1 calc(50% - 0.5rem); min-width: 0; }
  .sima-filter-reset { width: 100%; }
}
/* Searchable long dropdowns (js/sima.js section 7) */
.sima-select-count { display: block; min-height: 1.1em; font-size: 0.75rem; color: #6e757d; }

/* Unit calendars (table.sima-unit-grid): keep the date column visible while
   scrolling sideways through the units. */
table.sima-unit-grid tr > :first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 #eceef1;
}
table.sima-unit-grid thead tr > :first-child { z-index: 101; }
.sima-grid-count { font-size: 0.8125rem; color: #637385; align-self: center; }

/* Fleet card at full width (admin dashboard without the revenue chart): units in columns. */
.sima-fleet--wide {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  column-gap: 2rem;
}
.sima-fleet--wide .sima-fleet-item + .sima-fleet-item { border-top: 0; }
.sima-fleet--wide .sima-fleet-item { border-bottom: 1px solid #eceef1; }
