:root {
  --navy: #152d48;
  --navy-dark: #0c1e31;
  --blue: #2878b8;
  --blue-soft: #eaf4fb;
  --orange: #e47b24;
  --orange-soft: #fff2e7;
  --green: #247a4a;
  --green-soft: #e8f6ed;
  --amber: #9a6500;
  --amber-soft: #fff5d6;
  --red: #b63737;
  --red-soft: #fff0f0;
  --ink: #222c35;
  --muted: #65727d;
  --line: #d9e0e6;
  --surface: #ffffff;
  --background: #f3f5f7;
  --shadow: 0 10px 35px rgba(12, 30, 49, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--background);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--muted); }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  letter-spacing: 0.04em;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 12px 3px 12px 3px;
  background: var(--orange);
  color: white;
  font-size: 25px;
  font-weight: 900;
  font-style: italic;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; }
.brand small { margin-top: 1px; font-size: 11px; font-weight: 600; opacity: 0.74; }

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, rgba(40, 120, 184, 0.28), transparent 40%),
    linear-gradient(145deg, var(--navy-dark), var(--navy));
}

.login-card {
  width: min(100%, 420px);
  padding: 34px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.brand-login {
  margin-bottom: 28px;
  color: var(--navy);
}

.login-card h1 { margin: 0 0 6px; font-size: 27px; }
.login-card > p { margin: 0 0 24px; }

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  color: #3e4b55;
  font-size: 13px;
  font-weight: 700;
}

.login-card .field + .field { margin-top: 15px; }

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #cbd4dc;
  border-radius: 8px;
  outline: none;
  background: white;
  color: var(--ink);
  font-weight: 500;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { min-height: 78px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 120, 184, 0.14);
}

.button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: white;
  color: var(--navy);
  font-weight: 750;
  transition: transform 0.1s, opacity 0.1s, background 0.1s;
}

.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: 0.58; transform: none; }
.button-primary { background: var(--orange); color: white; }
.button-primary:hover { background: #cc681a; }
.button-light { border-color: var(--line); background: white; }
.button-quiet { border-color: rgba(255, 255, 255, 0.3); background: transparent; color: inherit; }
.button-link { padding-inline: 5px; background: transparent; color: var(--blue); }
.button-danger { border-color: #e8b7b7; background: var(--red-soft); color: var(--red); }
.button-block { width: 100%; margin-top: 22px; }
.button-small { min-height: 32px; padding: 4px 10px; }

.form-error {
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.app-header { background: var(--navy); color: white; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15); }
.header-inner {
  display: flex;
  width: min(1180px, calc(100% - 32px));
  min-height: 78px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.session-area { display: flex; align-items: center; gap: 14px; }
.session-copy { display: grid; justify-items: end; font-size: 12px; }
#connectedUser { font-weight: 750; }
.connection-state { margin-top: 3px; color: #b9c8d5; }
.connection-state.synced { color: #9ae3b8; }
.connection-state.pending { color: #ffd684; }
.connection-state.error { color: #ffb1b1; }

.page-shell { width: min(1180px, calc(100% - 32px)); margin: 26px auto 70px; }
.today-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 26px;
  border-left: 5px solid var(--orange);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.eyebrow { margin: 0 0 5px; color: var(--orange); font-size: 11px; font-weight: 900; letter-spacing: 0.16em; }
.today-panel h1 { margin: 0; color: var(--navy); font-size: clamp(20px, 3vw, 27px); }
.today-panel p:last-child { margin: 7px 0 0; color: var(--muted); }
.action-row { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0;
  padding: 12px 14px;
  border: 1px solid;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 650;
}
.login-card .notice { margin: 14px 0; }
.notice-info { border-color: #b8d8ee; background: var(--blue-soft); color: #205f8f; }
.notice-warning { border-color: #efd98a; background: var(--amber-soft); color: #755000; }
.notice-error { border-color: #edbcbc; background: var(--red-soft); color: #8e2929; }

.tabs { display: flex; gap: 25px; margin-top: 26px; border-bottom: 1px solid var(--line); }
.tab-button {
  padding: 11px 4px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.tab-button.active { border-bottom-color: var(--orange); color: var(--navy); }

.filters {
  display: grid;
  grid-template-columns: minmax(210px, 2fr) repeat(4, minmax(125px, 1fr)) minmax(140px, 1fr) auto;
  gap: 9px;
  margin: 18px 0 12px;
}
.filters input, .filters select { min-height: 40px; font-size: 13px; }
.search-field { position: relative; }
.search-field::before { position: absolute; z-index: 1; top: 10px; left: 12px; content: "⌕"; color: var(--muted); }
.search-field input { padding-left: 32px; }

.list-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 16px; }
.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
  padding: 11px 14px;
  border-radius: 9px;
  background: var(--navy);
  color: white;
}
.selection-bar strong { margin-right: auto; }

.date-group { margin: 0 0 25px; }
.date-heading { margin: 0 0 9px 4px; color: var(--muted); font-size: 12px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; }
.date-heading.today { color: var(--orange); }
.movement-card {
  display: grid;
  grid-template-columns: 38px 5px minmax(0, 1fr) auto;
  overflow: hidden;
  margin-bottom: 9px;
  border: 1px solid #e0e5e9;
  border-radius: 10px;
  background: white;
  box-shadow: 0 2px 7px rgba(12, 30, 49, 0.045);
}
.movement-card.done { opacity: 0.68; }
.movement-card.noted { background: var(--green-soft); }
.movement-select { display: grid; place-items: center; }
.movement-select input { width: 17px; min-height: 17px; accent-color: var(--orange); }
.type-mark.delivery { background: var(--blue); }
.type-mark.pickup { background: var(--orange); }
.movement-body { min-width: 0; padding: 14px 16px; }
.movement-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.movement-time { color: var(--navy); font-size: 16px; font-weight: 900; }
.tag { padding: 3px 7px; border-radius: 99px; font-size: 10px; font-weight: 850; letter-spacing: 0.03em; text-transform: uppercase; }
.tag.delivery { background: var(--blue-soft); color: #1e6397; }
.tag.pickup { background: var(--orange-soft); color: #a55212; }
.tag.pending { background: var(--amber-soft); color: var(--amber); }
.tag.done, .tag.noted { background: var(--green-soft); color: var(--green); }
.tag.driver { background: #edf0f3; color: #45535e; }
.movement-client { margin-top: 7px; color: var(--navy-dark); font-size: 17px; font-weight: 850; }
.movement-machine { margin-top: 2px; color: #45525d; font-weight: 650; }
.movement-details { display: flex; flex-wrap: wrap; gap: 7px 18px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.movement-details a { color: var(--blue); }
.movement-notes { margin-top: 9px; padding: 8px 10px; border-radius: 6px; background: rgba(21, 45, 72, 0.055); font-size: 12px; }
.movement-actions { display: flex; align-items: center; gap: 6px; padding: 12px; }
.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--navy);
  font-size: 17px;
  font-weight: 800;
}
.icon-button.active { border-color: #80c49c; background: var(--green-soft); color: var(--green); }

.empty-state, .loading-state {
  padding: 48px 20px;
  border: 1px dashed #c8d1d9;
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}
.empty-state strong { display: block; margin-bottom: 5px; color: var(--navy); }

.week-navigation { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin: 18px 0 14px; }
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(115px, 1fr)); gap: 8px; overflow-x: auto; }
.week-day { min-height: 260px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: white; }
.week-day.today { border: 2px solid var(--orange); }
.week-day-heading { margin-bottom: 10px; color: var(--navy); text-align: center; font-size: 12px; font-weight: 850; }
.week-movement { width: 100%; margin-bottom: 7px; padding: 8px; border: 0; border-left: 4px solid; border-radius: 6px; text-align: left; font-size: 11px; }
.week-movement.delivery { border-color: var(--blue); background: var(--blue-soft); }
.week-movement.pickup { border-color: var(--orange); background: var(--orange-soft); }
.week-movement.done { opacity: 0.55; text-decoration: line-through; }
.week-movement.noted { box-shadow: inset 0 0 0 2px #78bd95; }
.week-movement strong { display: block; margin-bottom: 3px; }
.week-empty { padding-top: 10px; color: #a4adb5; text-align: center; }

.modal-overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  overflow-y: auto;
  place-items: center;
  padding: 24px;
  background: rgba(7, 18, 29, 0.65);
}
.modal-card {
  width: min(100%, 680px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 25px;
  border-radius: 14px;
  background: white;
  box-shadow: 0 25px 75px rgba(0, 0, 0, 0.3);
}
.modal-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 19px; }
.modal-heading h2 { margin: 0; color: var(--navy); font-size: 22px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.modal-card > .field { margin-top: 14px; }
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.type-toggle span { display: block; padding: 10px; border: 2px solid var(--line); border-radius: 8px; text-align: center; }
.type-toggle .delivery input:checked + span { border-color: var(--blue); background: var(--blue-soft); color: #1d6398; }
.type-toggle .pickup input:checked + span { border-color: var(--orange); background: var(--orange-soft); color: #a55112; }
.modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 23px; }
.modal-actions-right { display: flex; gap: 10px; margin-left: auto; }

.toast {
  position: fixed;
  z-index: 30;
  right: 22px;
  bottom: 22px;
  max-width: min(390px, calc(100% - 44px));
  padding: 12px 17px;
  border-radius: 9px;
  background: var(--navy-dark);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.18s, transform 0.18s;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #8d2727; }

#printView { display: none; }

@media (max-width: 980px) {
  .filters { grid-template-columns: repeat(3, 1fr); }
  .search-field { grid-column: 1 / -1; }
  .week-grid { grid-template-columns: repeat(7, 145px); }
}

@media (max-width: 700px) {
  .header-inner, .page-shell { width: min(100% - 20px, 1180px); }
  .header-inner { min-height: 68px; }
  .brand small, .session-copy { display: none; }
  .session-area { gap: 6px; }
  .today-panel { align-items: stretch; flex-direction: column; padding: 19px; }
  .action-row { justify-content: stretch; }
  .action-row .button { flex: 1; }
  .filters { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .movement-card { grid-template-columns: 34px 5px minmax(0, 1fr); }
  .movement-actions { grid-column: 3; justify-content: flex-end; padding: 0 12px 12px; }
  .field-grid { grid-template-columns: 1fr; }
  .modal-overlay { padding: 10px; }
  .modal-card { max-height: calc(100vh - 20px); padding: 19px; }
  .selection-bar { flex-wrap: wrap; }
}

@media (max-width: 470px) {
  .login-card { padding: 25px 20px; }
  .filters { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .list-toolbar { align-items: stretch; flex-direction: column-reverse; gap: 6px; }
  .modal-actions { align-items: stretch; flex-direction: column-reverse; }
  .modal-actions-right { width: 100%; margin-left: 0; }
  .modal-actions-right .button, .modal-actions > .button { flex: 1; }
}

@media print {
  body { background: white; }
  .app-header, .today-panel, .notice, .tabs, #listView, #weekView, .modal-overlay, .toast { display: none !important; }
  .page-shell { width: 100%; margin: 0; }
  #printView { display: block; }
  .print-date { margin: 0 0 14px; border-bottom: 2px solid #222; font-size: 20px; }
  .print-item { break-inside: avoid; margin-bottom: 11px; padding-bottom: 9px; border-bottom: 1px solid #bbb; font-size: 12px; }
}
