/* Keep intrinsic controls from expanding cards and grid tracks on iOS Safari. */
.company-name-form {
  display: grid;
  gap: 12px;
  max-width: 560px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid #5f5f5f;
}
.company-name-form label { font-weight: 700; }
.company-name-form input { width: 100%; }
.company-name-form button { justify-self: start; }
.company-name-form p { margin: 0; }

html, body, #app, .shell, .main-column, main {
  max-width: 100%;
  min-width: 0;
}

.grid > *, .forms > *, .card > *, .row > *,
.section-heading > *, .topbar > *, .detail-line > *,
#period-field, #event-field {
  min-width: 0;
}

.forms {
  width: 100%;
  min-width: 0;
}

input, select, textarea {
  display: block;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
}

/* The native date control has a large intrinsic width in WebKit. */
input[type="date"], input[type="time"] {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: left;
}

.toolbar input, .toolbar select {
  min-width: 0;
  max-width: 100%;
}

.card, dialog, .notice, .row, .metric-row,
.section-heading, .sidebar-bottom, .brand {
  overflow-wrap: anywhere;
}

/* The two-word brand must stay inside the fixed desktop sidebar, including
   tablets in landscape where the sidebar is still shown. */
.sidebar .brand {
  min-width: 0;
  margin-left: 0;
  margin-right: 0;
  gap: 10px;
  font-size: .8rem;
  letter-spacing: .06em;
  white-space: normal;
  line-height: 1.2;
}
.sidebar .brand-mark {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  overflow: hidden;
  border-radius: 14px;
  background: #1a1a1a;
}
.sidebar .brand-mark img { display: block; width: 100%; height: 100%; object-fit: cover; }
.sidebar .brand > span:last-child { min-width: 0; }
.sidebar .brand strong { display: block; }

.row > :first-child, .metric-row > :first-child { min-width: 0; }
.dialog-actions button { max-width: 100%; }
dialog form, dialog .detail-line { min-width: 0; max-width: 100%; }
dialog .forms > * { min-width: 0; }

@media (min-width: 701px) and (max-width: 1100px) {
  .grid > .span-8, .grid > .span-4 { grid-column: span 12; }
}

@media (min-width: 701px) and (max-width: 900px) {
  .forms { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 700px) {
  .forms { grid-template-columns: minmax(0, 1fr); }
  .card { max-width: 100%; }
  .mobile-nav { width: 100%; min-width: 0; }
  .mobile-nav button {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: center;
    line-height: 1.2;
  }
  .section-heading { flex-wrap: wrap; }
  .row { flex-wrap: wrap; }
  .money { white-space: normal; overflow-wrap: anywhere; text-align: right; margin-left: auto; }
  .login-shell { min-width: 0; max-width: 100%; }
  dialog { width: calc(100% - 20px); padding: 18px; }
}

@media (max-width: 360px) {
  .main-column { padding-left: 11px; padding-right: 11px; }
  .card { padding: 15px; }
  .mobile-nav { gap: 0; padding-left: 3px; padding-right: 3px; }
  .mobile-nav button { padding-left: 2px; padding-right: 2px; }
}

/* Keep the month readable when seven columns become narrow. The full event
   titles remain available in the list after selecting a date. */
.calendar .calendar-event-indicator { display: none; }
@media (max-width: 480px) {
  .calendar .calendar-event-title { display: none; }
  .calendar .calendar-event-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    margin-top: 4px;
    padding: 0 4px;
    border-radius: 10px;
    background: #e4e4e4;
    color: #242424;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1;
  }
}

/* All entry categories use the same usable control width. Native WebKit date
   fields can otherwise retain an intrinsic width wider than a grid track. */
#mode-badge {
  max-inline-size: min(42vw, 360px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar > div:first-child, .top-actions { min-inline-size: 0; }
#modal, #entry-form, #detail-lines, #entry-form .detail-line,
#entry-form .forms, #entry-form .form-field, #entry-form .full {
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
}

#modal { max-inline-size: calc(100vw - 16px); overflow-x: hidden; }
#entry-form.forms, #entry-form .detail-line .forms {
  grid-template-columns: minmax(0, 1fr);
}
#entry-form .detail-line {
  overflow: hidden;
  padding: clamp(12px, 3vw, 20px);
  margin-block: 0 14px;
}
#entry-form .form-field { overflow: hidden; text-align: left; }
#entry-form :is(input:not([type="file"]), select, textarea, .event-picker-trigger) {
  display: block;
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  min-block-size: 52px;
  margin: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
#entry-form input:not([type="file"]), #entry-form select {
  block-size: 52px;
  padding-block: 0;
  line-height: normal;
}
#entry-form textarea {
  min-block-size: 96px;
  block-size: 96px;
  padding-block: 31px;
  line-height: 32px;
  resize: vertical;
}
#entry-form textarea:focus,
#entry-form textarea:not(:placeholder-shown) {
  padding-block: 12px;
  line-height: 1.4;
}
#entry-form :is(input, textarea)::placeholder { text-align: center; }
#entry-form select { text-align-last: center; }
#entry-form input[type="date"], #entry-form input[type="time"],
#entry-form input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
}
#entry-form :is(input[type="date"], input[type="time"], input[type="datetime-local"])::-webkit-date-and-time-value,
#entry-form :is(input[type="date"], input[type="time"], input[type="datetime-local"])::-webkit-datetime-edit {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  block-size: 100%;
  min-block-size: 0;
  padding-block: 0;
  text-align: center;
}
#entry-form input[type="number"]::-webkit-inner-spin-button { margin: 0; }
#entry-form .event-picker-trigger {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: normal;
  overflow-wrap: anywhere;
}
#entry-form .event-picker-trigger small {
  flex-basis: 100%;
  margin: 0;
  text-align: center;
}
#entry-form .dialog-actions { justify-content: center; }
#entry-form .dialog-actions .primary { min-inline-size: min(100%, 240px); text-align: center; }
#entry-form .work-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-inline-size: 0;
  margin-block-start: 18px;
  padding: 16px;
  border: 1px solid #9c9c9c;
  border-radius: 18px;
  background: #404040;
}
#entry-form .work-total strong { display: block; color: #eef6ed; }
#entry-form .work-total small { display: block; margin-block-start: 5px; color: #cdcdcd; }
#entry-form .work-total b {
  color: #e5e5e5;
  font-size: 1.4rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#entry-form [data-add-line], #entry-form [data-remove-line] {
  max-inline-size: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}
.receipt-picker { position: relative; inline-size: 100%; min-inline-size: 0; }
.receipt-file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  opacity: 0;
}
.receipt-file-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-sizing: border-box;
  inline-size: 100%;
  min-block-size: 52px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid #555555;
  border-radius: 15px;
  background: #272727;
  color: #f3f7ef;
  text-align: center;
  cursor: pointer;
}
.receipt-file-input:focus-visible + .receipt-file-control {
  outline: 2px solid #e5e5e5;
  outline-offset: 2px;
}
.receipt-file-action { padding: 5px 10px; border-radius: 10px; background: #414141; }
.receipt-file-name { min-inline-size: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  #entry-form [data-add-line], #entry-form .dialog-actions .primary { inline-size: 100%; }
  #entry-form .detail-line { padding: 12px; }
}
@media (max-width: 340px) {
  #entry-form .work-total { align-items: flex-start; flex-direction: column; }
}
