/* DPS Courier Timekeeping — application stylesheet.
 *
 * Replaces the cdn.tailwindcss.com <script>, which was compiling CSS in the
 * browser on every page load and left the app unstyled whenever a driver had
 * poor signal. This file is ~6KB and loads from our own server.
 *
 * Mobile first: the base rules are the phone layout, and the media queries add
 * the desktop one. Drivers are the heaviest users and they are on phones.
 */

:root {
  --blue:        #1a56db;
  --blue-dark:   #1541a8;
  --purple:      #5b129b;
  --green:       #16a34a;
  --green-dark:  #15803d;
  --red:         #dc2626;
  --red-dark:    #b91c1c;
  --amber:       #b45309;
  --grey-50:     #f8fafc;
  --grey-100:    #f3f4f6;
  --grey-200:    #e5e7eb;
  --grey-400:    #9ca3af;
  --grey-600:    #4b5563;
  --grey-800:    #1f2937;
  --radius:      12px;
  --tap:         44px;   /* minimum comfortable touch target */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;              /* < 16px makes iOS zoom on focus */
  color: var(--grey-800);
  background: var(--grey-100);
  -webkit-text-size-adjust: 100%;
}

/* -- Layout ---------------------------------------------------------------- */

.wrap        { max-width: 640px; margin: 0 auto; }
.wrap-wide   { max-width: 1200px; margin: 0 auto; }

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(20, 32, 64, .08);
  padding: 20px;
  margin-bottom: 16px;
}

.row        { display: flex; flex-wrap: wrap; gap: 12px; }
.row > *    { flex: 1 1 100%; }
.between    { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.stack > * + * { margin-top: 12px; }

h1 { font-size: 1.4rem; margin: 0 0 4px; color: var(--purple); }
h2 { font-size: 1.15rem; margin: 0 0 12px; color: var(--blue); }

.muted  { color: var(--grey-600); font-size: .875rem; }
.tiny   { color: var(--grey-400); font-size: .75rem; }
.center { text-align: center; }

hr { border: 0; border-top: 1px solid var(--grey-200); margin: 20px 0; }

/* -- Forms ----------------------------------------------------------------- */

label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .9rem; }

input[type=text], input[type=password], input[type=date],
input[type=time], input[type=number], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--grey-800);
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: 8px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, .2);
}

input[readonly] { background: var(--grey-100); color: var(--grey-600); }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  font-weight: 500;
}
.check input { width: 22px; height: 22px; min-height: 0; flex: none; }

/* -- Buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:hover     { background: var(--blue-dark); }
.btn-block     { display: flex; width: 100%; }
.btn-green     { background: var(--green); }
.btn-green:hover { background: var(--green-dark); }
.btn-red       { background: var(--red); }
.btn-red:hover { background: var(--red-dark); }
.btn-grey      { background: #fff; color: var(--grey-800); border: 1px solid var(--grey-200); }
.btn-grey:hover{ background: var(--grey-100); }
.btn-sm        { min-height: 38px; padding: 6px 14px; font-size: .875rem; }

/* -- Dropdown menu --------------------------------------------------------- */
/* Built on <details>/<summary> so it works with no JavaScript at all; the small
   script on the page only closes it when you click elsewhere. */

.menu { position: relative; display: inline-block; }

.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::marker { content: ''; }

.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 250px;
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20, 32, 64, .16);
  overflow: hidden;
  text-align: left;
}

.menu-items a {
  display: block;
  padding: 11px 14px;
  color: var(--grey-800);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 600;
}
.menu-items a:hover { background: var(--grey-100); }
.menu-items a + a   { border-top: 1px solid var(--grey-200); }

.menu-items .sub {
  display: block;
  font-size: .75rem;
  font-weight: 400;
  color: var(--grey-600);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* On a phone the menu would run off the edge, so pin it to the viewport. */
@media (max-width: 639px) {
  .menu-items { right: auto; left: 0; min-width: min(280px, calc(100vw - 48px)); }
}

/* -- Messages -------------------------------------------------------------- */

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid;
  margin-bottom: 14px;
  font-size: .925rem;
}
.alert-error   { color: var(--red);    background: #fef2f2; border-color: #fecaca; }
.alert-ok      { color: var(--green-dark); background: #f0fdf4; border-color: #bbf7d0; }
.alert-warn    { color: var(--amber);  background: #fffbeb; border-color: #fde68a; }
.alert ul      { margin: 6px 0 0; padding-left: 20px; }

.toast {
  position: fixed;
  top: 16px; left: 16px; right: 16px;
  z-index: 1000;
  padding: 14px 18px;
  border-radius: 10px;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .2);
  text-align: center;
}
.toast-ok    { background: var(--green); }
.toast-error { background: var(--red); }

/* -- Day cards (the phone view of a pay period) ---------------------------- */

.day {
  border: 1px solid var(--grey-200);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}
.day.empty      { border-style: dashed; background: var(--grey-50); }
.day-head       { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.day-date       { font-weight: 700; }
.day-hours      { font-size: .875rem; color: var(--grey-600); font-variant-numeric: tabular-nums; }
.day-grid       { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.day-grid label { font-size: .75rem; color: var(--grey-600); font-weight: 500; }
.day-actions    { display: flex; gap: 8px; margin-top: 12px; }
.day-actions .btn { flex: 1; }

/* -- Tables (desktop) ------------------------------------------------------ */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
  background: var(--blue);
  color: #fff;
  text-align: left;
  padding: 10px;
  font-weight: 600;
  white-space: nowrap;
}
tbody td { padding: 9px 10px; border-top: 1px solid var(--grey-200); }
tbody tr:hover { background: var(--grey-50); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Controls inside a table are compact, and a <select> gets a floor so it cannot
   be squeezed down to just its arrow when the table runs out of room. */
td input[type=text],
td input[type=email],
td input[type=tel],
td select {
  min-height: 38px;
  padding: 6px 10px;
  font-size: .875rem;
}
td select { min-width: 104px; }

/* Two inputs sharing one cell. display:block is what actually stacks them —
   inputs are inline by default and would otherwise sit side by side and widen
   the whole table. Full width means a long email address fills the cell rather
   than overflowing a fixed size. */
td .stacked          { display: block; width: 100%; }
td .stacked + .stacked { margin-top: 6px; }

/* -- Sticky action bar on phones ------------------------------------------- */

.sticky-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 0 4px;
  background: linear-gradient(to top, #fff 70%, rgba(255, 255, 255, 0));
}

/* -- Desktop --------------------------------------------------------------- */

@media (min-width: 640px) {
  body { padding: 24px; }

  .row > .half   { flex: 1 1 calc(50% - 6px); }
  .row > .third  { flex: 1 1 calc(33.333% - 8px); }
  .row > .auto   { flex: 0 0 auto; }

  h1 { font-size: 1.6rem; }

  .toast { left: auto; right: 24px; max-width: 380px; }

  /* A day reflows from a stacked card into a single dense row. Same markup and
     the same form fields either way — rendering the inputs twice would put
     duplicate names in one form and corrupt the submission. */
  .day        { display: flex; align-items: flex-end; gap: 14px; padding: 12px 14px; }
  .day-head   { flex: 0 0 128px; display: block; margin: 0; }
  .day-grid   { flex: 1; grid-template-columns: repeat(4, 1fr) auto; align-items: end; }
  .day-breaks { display: flex; gap: 12px; }
  .day-breaks .check { min-height: 0; font-size: .8rem; font-weight: 500; }

  .cards-only  { display: none; }
  .table-only  { display: block; }

  .sticky-bar { position: static; background: none; padding: 12px 0 0; }
}

@media (max-width: 639px) {
  .table-only { display: none; }
  .cards-only { display: block; }
}

/* -- Print (payroll takes these to the accountant) ------------------------- */

@media print {
  body { background: #fff; padding: 0; }
  .card { box-shadow: none; border: 1px solid var(--grey-200); }
  .btn, .sticky-bar, .no-print { display: none !important; }
  thead th { background: #fff; color: #000; border-bottom: 2px solid #000; }
}

/* -- Sortable column headers ----------------------------------------------- */

.sort-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.sort-link:hover { text-decoration: underline; }

/* The idle double-arrow is dimmed so the active column's single arrow reads as
   the answer to "what is this sorted by?" at a glance. */
.sort-idle { opacity: .45; font-weight: 400; }
