:root {
  color-scheme: light;
  --ink: #142033;
  --muted: #60728f;
  --line: #cfe0f3;
  --surface: #ffffff;
  --soft: #eaf4ff;
  --brand: #2f80d0;
  --brand-dark: #155a9c;
  --accent: #b13f2d;
  --warn: #a33224;
  --shadow: 0 16px 42px rgba(26, 78, 135, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #e5f1ff;
  color: var(--ink);
  font-size: 13px;
  font-family: "Noto Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.ubn-time-mode {
  --line: #f5cfe1;
  --soft: #fff0f7;
  --brand: #d64f8d;
  --brand-dark: #9e2e64;
  --shadow: 0 16px 42px rgba(166, 54, 105, 0.14);
  background: #ffe7f2;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  padding: 7px 9px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 128, 208, 0.16);
}

label {
  display: grid;
  gap: 5px;
  color: #31425e;
  font-size: 0.76rem;
  font-weight: 700;
}

.label-text {
  display: inline-flex;
  gap: 3px;
  align-items: baseline;
}

.required-mark {
  color: var(--warn);
  font-weight: 900;
}

.field-help {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
}

h1,
h2,
p {
  margin: 0;
}

.shell {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 10px;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.stack {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0 10px;
}

.topbar h1,
.login-panel h1 {
  font-size: 0.9rem;
  line-height: 1.12;
}

.header-dedication {
  color: var(--brand-dark);
  font-size: 0.52rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 3px;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hamburger-menu {
  position: relative;
  justify-self: end;
}

.hamburger-menu summary {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--brand-dark);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
  list-style: none;
  box-shadow: 0 4px 14px rgba(26, 78, 135, 0.08);
}

.hamburger-menu summary::-webkit-details-marker {
  display: none;
}

.hamburger-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 6px;
  width: min(190px, calc(100vw - 20px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mode-tab {
  min-height: 32px;
  background: var(--soft);
  color: var(--brand-dark);
}

.mode-tab.active {
  background: var(--brand);
  color: #fff;
}

.entry-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.entry-tab {
  min-height: 32px;
  background: transparent;
  color: var(--muted);
}

.entry-tab.active {
  background: var(--surface);
  color: var(--brand-dark);
  box-shadow: 0 4px 16px rgba(26, 78, 135, 0.1);
}

.app-panel {
  display: none;
}

.app-panel.active {
  display: grid;
  gap: 10px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 0 2px;
}

.section-head p {
  color: var(--muted);
  margin-top: 4px;
  font-size: 0.72rem;
}

.section-head h2,
.summary-band h2 {
  font-size: 0.9rem;
  line-height: 1.15;
}

.form-grid {
  display: grid;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide,
.form-actions {
  grid-column: 1 / -1;
}

.check-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 20px;
  height: 20px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-error {
  grid-column: 1 / -1;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #f0b7ae;
  border-radius: 8px;
  background: #fff1ef;
  color: var(--warn);
  font-size: 0.78rem;
  font-weight: 800;
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 32px;
  padding: 0 9px;
}

.primary {
  background: var(--brand);
  color: #fff;
}

.secondary {
  background: #dcecff;
  color: var(--brand-dark);
}

body.ubn-time-mode .secondary {
  background: #ffd9eb;
}

.compact-action {
  white-space: nowrap;
}

.ghost {
  background: transparent;
  color: var(--brand-dark);
  border: 1px solid var(--line);
}

.danger {
  background: #f8dfda;
  color: var(--warn);
}

.month-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 4px 0;
  text-align: center;
}

.month-link {
  min-height: 28px;
  padding: 0 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.month-link:first-child {
  justify-self: end;
}

.month-link:last-child {
  justify-self: start;
}

.month-title {
  font-size: 0.86rem;
  line-height: 1.15;
}

.roster-list,
.summary-list {
  display: grid;
  gap: 12px;
}

.month-list {
  display: grid;
  gap: 10px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekdays {
  margin-bottom: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #cfe7ff;
}

.calendar-weekdays div {
  padding: 4px 2px;
  color: #0f4f88;
  font-size: 0.52rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.calendar-weekdays .weekend {
  color: #078a2f;
}

.month-calendar {
  gap: 4px;
}

.calendar-day {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 112px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.calendar-day.outside-month {
  opacity: 0.46;
  background: #edf5ff;
}

.calendar-day.today {
  border-color: #e58ab3;
  background: #ffeaf3;
  box-shadow: inset 0 0 0 2px rgba(229, 138, 179, 0.24);
}

.calendar-day.today .calendar-day-head strong {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  min-height: 18px;
  border-radius: 999px;
  background: #d94f8b;
  color: #fff;
}

.calendar-day.today .calendar-day-head span {
  color: #a82f68;
}

.calendar-day-head {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  align-items: center;
}

.calendar-day-head strong {
  font-size: 0.72rem;
  line-height: 1;
}

.calendar-day-head span {
  color: var(--muted);
  font-size: 0.52rem;
  font-weight: 800;
}

.calendar-schedule-mark {
  display: inline-grid;
  width: 12px;
  min-width: 12px;
  height: 12px;
  place-items: center;
  border-radius: 999px;
  color: #fff !important;
  font-size: 0.42rem !important;
  font-weight: 900 !important;
  line-height: 1;
}

.calendar-check-mark {
  background: #1fa853;
}

.calendar-x-mark {
  background: #d54040;
}

.calendar-duties {
  display: grid;
  gap: 3px;
}

.calendar-duty {
  display: grid;
  gap: 2px;
  min-width: 0;
  width: 100%;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #f7fbff;
  text-align: left;
  overflow: hidden;
}

.calendar-duty.flight-duty {
  border-color: transparent;
}

.calendar-duty.rest-duty {
  background: #f0fff4;
}

.calendar-duty.rest-duty .calendar-duty-flight {
  color: #078a2f;
}

.calendar-duty.other-duty {
  background: #fafbfc;
}

.calendar-duty.other-duty .calendar-duty-flight {
  color: var(--ink);
}

.calendar-duty.available-duty {
  background: #f7fbff;
}

.calendar-duty.available-duty .calendar-duty-flight {
  color: #155a9c;
}

.calendar-duty.training-duty {
  background: #f7fbff;
}

.calendar-duty.training-duty .calendar-duty-flight {
  color: #155a9c;
}

.calendar-duty.office-duty {
  background: #f7fbff;
}

.calendar-duty.office-duty .calendar-duty-flight {
  color: #155a9c;
}

.calendar-duty.standby-duty {
  background: #f7fbff;
}

.calendar-duty.standby-duty .calendar-duty-flight {
  color: #155a9c;
}

.calendar-duty.overnight-duty {
  background: #fff6c7;
  color: #b35a00;
}

.calendar-duty.overnight-duty .calendar-duty-flight {
  color: #b35a00;
}

.calendar-duty.overnight-duty .calendar-duty-times {
  color: #9a4d00;
}

.calendar-duty.grey-duty {
  background: #f3f4f6;
  color: #6b7280;
}

.calendar-duty.grey-duty .calendar-duty-flight,
.calendar-duty.grey-duty .calendar-duty-times {
  color: #6b7280;
}

.calendar-duty-flight {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 16px;
  padding: 0;
  background: transparent;
  color: var(--brand-dark);
  font-size: 0.64rem;
  font-weight: 900;
  text-align: left;
  overflow-wrap: anywhere;
}

.calendar-duty:not(.flight-duty) .calendar-duty-flight {
  font-weight: 400;
}

.calendar-duty-times {
  display: grid;
  gap: 1px;
  min-width: 0;
  color: #2f405c;
  font-size: 0.48rem;
  font-weight: 800;
  line-height: 1.15;
}

.calendar-duty-times span {
  min-width: 0;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  overflow-wrap: normal;
  word-break: normal;
}

.day-card {
  display: grid;
  grid-template-columns: minmax(132px, 170px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.other-duty-day {
  background: #f8fbff;
}

.day-head {
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
}

.day-head strong {
  font-size: 0.86rem;
}

.day-head span {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
}

.day-duties {
  display: grid;
  gap: 7px;
}

.day-duty {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) minmax(260px, 1.6fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid #e5ebf2;
  border-radius: 8px;
  background: var(--soft);
}

.day-duty.rest-duty {
  background: #5cff8d;
}

.day-duty.other-duty {
  background: #fff6e5;
}

.day-duty-title,
.day-duty-toggle,
.day-duty-edit,
.day-duty-delete {
  width: 100%;
  min-height: 30px;
  padding: 5px 7px;
  border-radius: 8px;
  text-align: left;
}

.day-duty-title {
  display: grid;
  gap: 2px;
  background: transparent;
  color: var(--ink);
}

.day-duty-title span {
  font-weight: 900;
}

.day-duty-title small {
  color: var(--muted);
  font-weight: 700;
}

.day-duty-times {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 7px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.day-duty-times > div {
  display: grid;
  gap: 2px;
}

.day-duty-times > div > span {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
  text-transform: uppercase;
}

.day-duty-times .time-lines {
  margin-top: 0;
  font-size: 0.64rem;
  font-weight: 800;
}

.day-duty-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 6px;
}

.day-duty-edit,
.day-duty-toggle,
.day-duty-delete {
  font-size: 0.66rem;
  font-weight: 900;
  text-align: center;
  border: 1px solid transparent;
}

.day-duty-edit {
  background: #dcecff;
  color: var(--brand-dark);
}

.day-duty-delete {
  background: #f8dfda;
  color: var(--warn);
}

.day-duty-toggle.planned {
  background: #f7e6c8;
  color: #7a4b00;
}

.day-duty-toggle.flown {
  background: #d7ebff;
  color: var(--brand-dark);
}

.empty-day-text {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.roster-card,
.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.roster-card {
  display: grid;
  gap: 14px;
}

.roster-main {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.flight-title {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  font-weight: 900;
  font-size: 0.92rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 0 7px;
  background: var(--soft);
  color: var(--brand-dark);
  font-size: 0.64rem;
  font-weight: 800;
}

.badge.flown {
  background: #d7ebff;
}

.badge.pending {
  background: #f7e6c8;
  color: #7c4b00;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.meta {
  padding: 8px;
  background: #f4f9ff;
  border-radius: 8px;
  min-width: 0;
}

.meta span {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meta strong {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.time-lines {
  display: grid;
  gap: 2px;
  line-height: 1.35;
}

.time-lines span {
  display: block;
}

.converted-time {
  color: var(--muted);
  font-weight: 700;
}

.roster-dialog {
  width: min(620px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  overflow: visible;
}

.roster-dialog::backdrop {
  background: rgba(10, 22, 20, 0.42);
}

.dialog-panel {
  display: grid;
  gap: 12px;
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-head {
  display: grid;
  grid-template-columns: 34px 28px minmax(0, 1fr) 28px 34px;
  gap: 8px;
  align-items: center;
}

.dialog-head h2 {
  font-size: 0.86rem;
  font-weight: 900;
  text-align: center;
  overflow-wrap: anywhere;
}

#dialogPrevFlight {
  grid-column: 1;
}

#dialogCopyFlight {
  grid-column: 2;
}

#dialogTitle {
  grid-column: 3;
}

#dialogClose {
  grid-column: 4;
}

#dialogNextFlight {
  grid-column: 5;
}

.icon-button {
  display: inline-grid;
  width: 28px;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--brand-dark);
  font-size: 0.84rem;
  line-height: 1;
}

.dialog-nav-button {
  font-size: 1.1rem;
}

.dialog-nav-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.dialog-body {
  display: grid;
  gap: 12px;
}

.dialog-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-row {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 7px;
  border-radius: 8px;
  background: var(--soft);
}

.detail-row-stack {
  grid-column: 1 / -1;
}

.route-time-card {
  gap: 8px;
}

.route-time-card > div {
  display: grid;
  gap: 2px;
}

.detail-row span {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 400;
  text-transform: uppercase;
}

.detail-row strong {
  font-weight: 400;
  overflow-wrap: anywhere;
}

.detail-row a {
  color: var(--brand-dark);
  font-weight: 400;
}

.roster-dialog button {
  font-weight: 400;
}

.dialog-actions {
  grid-template-columns: repeat(3, minmax(80px, 1fr));
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-band {
  display: grid;
  gap: 12px;
  padding: 12px 0 20px;
}

.summary-card {
  display: grid;
  grid-template-columns: 1fr repeat(4, minmax(150px, auto));
  gap: 10px;
  align-items: center;
}

.empty,
.error {
  color: var(--warn);
  font-weight: 700;
}

@media (max-width: 820px) {
  .shell {
    padding: 8px;
  }

  .section-head,
  .roster-main {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: row;
  }

  .form-grid,
  .entry-tabs,
  .meta-grid,
  .summary-card {
    grid-template-columns: 1fr;
  }

  .day-card,
  .day-duty,
  .day-duty-times,
  .day-duty-actions {
    grid-template-columns: 1fr;
  }

  .month-calendar {
    gap: 3px;
  }

  .calendar-day {
    min-height: 90px;
    padding: 4px;
  }

  .calendar-weekdays div {
    padding: 4px 1px;
    font-size: 0.54rem;
  }

  .calendar-duty {
    padding: 3px;
  }

  .calendar-duty-flight {
    min-height: 16px;
    font-size: 0.48rem;
  }

  .calendar-duty-times {
    font-size: 0.44rem;
  }

  .dialog-details {
    grid-template-columns: 1fr;
  }

  .form-actions button {
    width: 100%;
  }

  .month-link {
    font-size: 0.7rem;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 12px;
  }

  .login-panel,
  .form-grid,
  .day-card,
  .summary-card {
    padding: 8px;
  }

  .topbar h1,
  .login-panel h1 {
    font-size: 0.9rem;
  }

  .mode-tab,
  .entry-tab,
  .primary,
  .secondary,
  .ghost,
  .danger {
    min-height: 30px;
  }

  .month-nav {
    gap: 6px;
  }

  .month-link {
    font-size: 0.62rem;
  }

  .day-card {
    gap: 8px;
  }

  .calendar-day {
    min-height: 76px;
    padding: 3px;
    border-radius: 6px;
  }

  .calendar-day-head strong {
    font-size: 0.6rem;
  }

  .calendar-day-head span {
    display: none;
  }

  .calendar-duties {
    gap: 2px;
  }

  .calendar-duty {
    gap: 1px;
    padding: 2px;
    border-radius: 7px;
  }

  .calendar-duty-flight {
    min-height: 15px;
    font-size: 0.46rem;
  }

  .calendar-duty-times {
    font-size: 0.42rem;
  }

  .empty-day-text {
    padding: 3px;
    font-size: 0.52rem;
  }

  .day-head,
  .day-duty {
    padding: 7px;
  }

  .day-duty {
    gap: 7px;
  }

  .day-duty-title,
  .day-duty-toggle,
  .day-duty-edit,
  .day-duty-delete {
    min-height: 28px;
    padding: 4px 5px;
  }

  .day-duty-times {
    padding: 6px;
  }

  .summary-band {
    padding: 8px 0 14px;
  }

  .dialog-panel {
    padding: 8px;
  }
}

@media (max-width: 380px) {
  body {
    font-size: 11px;
  }

  .shell {
    padding: 6px;
  }

  input,
  select,
  textarea {
    min-height: 30px;
    padding: 5px 7px;
  }

  .entry-tabs {
    gap: 3px;
    padding: 3px;
  }

  .hamburger-panel {
    width: min(180px, calc(100vw - 12px));
  }

  .month-calendar {
    gap: 2px;
  }

  .calendar-weekdays div {
    font-size: 0.52rem;
  }

  .calendar-day {
    min-height: 68px;
    padding: 2px;
  }

  .calendar-duty {
    padding: 2px;
  }

  .calendar-duty-flight {
    font-size: 0.42rem;
  }

  .calendar-duty-times {
    font-size: 0.4rem;
  }
}
