/* V10: smartphone responsive improvements. Desktop layout remains unchanged. */

@media (max-width: 760px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    -webkit-text-size-adjust: 100%;
  }

  button,
  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .app-shell {
    width: 100%;
    padding: 16px 10px 82px;
  }

  .hero {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
  }

  .hero h1 {
    font-size: clamp(25px, 8vw, 34px);
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .lead {
    font-size: 14px;
    line-height: 1.6;
  }

  .version {
    justify-self: start;
    margin-top: 0;
  }

  .case-list {
    gap: 14px;
  }

  .case-card,
  .work-card,
  .grand-total-card {
    border-radius: 14px;
  }

  .case-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px;
  }

  .case-title-wrap {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    min-width: 0;
  }

  .case-name {
    width: 100%;
    min-width: 0;
    margin: 0;
  }

  .delete-case,
  .delete-work,
  .primary-button,
  .copy-button,
  .add-work-button,
  .service-tab {
    min-height: 44px;
    touch-action: manipulation;
  }

  .delete-case {
    width: 100%;
    margin: 0;
  }

  .work-list {
    gap: 12px;
    padding: 10px;
  }

  .work-header {
    padding: 12px;
  }

  .work-number,
  .case-number {
    overflow-wrap: anywhere;
  }

  .service-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
    padding: 10px;
  }

  .service-tab {
    min-width: 0;
    padding: 10px 6px;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .work-body {
    padding: 14px 12px;
  }

  .fields-grid,
  .dtp-fields-grid,
  .design-row-extended,
  .design-extra-options,
  .option-grid,
  .option-grid.two-col,
  .option-grid.three-col {
    grid-template-columns: 1fr !important;
  }

  .field,
  .input-wrap,
  .input-wrap input,
  .input-wrap select,
  .design-row input,
  .design-row select,
  .design-row-extended input,
  .design-row-extended select {
    min-width: 0;
    width: 100%;
  }

  .field-label,
  .hint,
  .rule-note,
  .design-global-note,
  .design-inline-note {
    overflow-wrap: anywhere;
  }

  .input-wrap input,
  .input-wrap select,
  .share-field input,
  .share-field select,
  .share-field textarea {
    min-height: 46px;
  }

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

  .quick-select button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    border-radius: 10px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .option-with-count {
    display: grid !important;
    grid-template-columns: 1fr !important;
    align-items: stretch;
    gap: 10px;
    min-height: 0;
    padding: 12px;
  }

  .option-with-count .checkbox-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    width: 100%;
  }

  .option-with-count .checkbox-row input {
    width: 20px;
    height: 20px;
    margin-top: 1px;
  }

  .option-with-count .checkbox-row span {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .option-with-count .option-count {
    width: 100% !important;
    min-width: 0 !important;
    padding-left: 32px;
  }

  .checkbox-row {
    align-items: flex-start;
    min-width: 0;
  }

  .checkbox-row span,
  .checkbox-row label {
    overflow-wrap: anywhere;
  }

  .design-row,
  .design-row-extended {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .design-row-extended .remove-row,
  .remove-row {
    width: 100%;
    min-height: 42px;
  }

  .work-result {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .work-result-text,
  .all-results,
  .summary-block,
  .comment-text {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .case-summary {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
    padding: 14px;
    text-align: left;
  }

  .case-summary strong {
    width: 100%;
    min-width: 0;
    text-align: center;
  }

  .deadline-setting {
    padding: 12px;
  }

  .deadline-row {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 8px 10px;
  }

  .deadline-row input[type="number"] {
    grid-column: 2;
    width: 100%;
    min-height: 44px;
  }

  .deadline-row > *:last-child {
    grid-column: 2;
  }

  /* On phones, keep only the total amount fixed at the bottom. */
  .app-layout {
    display: block !important;
  }

  .main-column {
    width: 100%;
    min-width: 0;
  }

  .total-column {
    position: static;
    width: 100%;
    padding: 0;
    margin-top: 16px;
  }

  .total-column .grand-total-card {
    width: 100%;
    max-height: none;
    overflow: visible;
    margin: 0;
    padding: 14px 12px 22px;
    border-radius: 14px;
    box-shadow: none;
  }

  .total-heading {
    position: fixed;
    z-index: 50;
    left: 8px;
    right: 8px;
    bottom: 8px;
    top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0;
    padding: 9px 12px;
    background: rgba(255, 255, 255, .97);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 6px 22px rgba(23, 45, 68, .22);
    backdrop-filter: blur(8px);
  }

  .total-heading .eyebrow {
    display: none;
  }

  .total-heading h2 {
    margin: 0;
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
  }

  .total-column .grand-total {
    font-size: 22px;
    line-height: 1;
    white-space: nowrap;
  }

  .result-details,
  .deadline-summary-card,
  .share-panel {
    margin-top: 12px;
  }

  .total-column .all-results {
    max-height: none;
    overflow: visible;
    font-size: 13px;
  }

  .total-column .copy-button,
  .share-create-button,
  .share-copy-button,
  .comment-send-button {
    width: 100%;
    min-height: 46px;
    margin-top: 10px;
  }

  .share-field textarea {
    min-height: 120px;
    resize: vertical;
  }

  .comment-list {
    max-height: 220px;
  }

  .comment-meta,
  .comment-meta-main {
    flex-wrap: wrap;
  }

  .comment-delete-button {
    min-height: 34px;
    padding: 6px 10px;
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-left: 7px;
    padding-right: 7px;
  }

  .service-tabs,
  .quick-select {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px;
  }

  .service-tab,
  .quick-select button {
    font-size: 13px;
    padding-left: 5px;
    padding-right: 5px;
  }

  .work-body,
  .work-header,
  .case-header {
    padding-left: 10px;
    padding-right: 10px;
  }

  .grand-total-card {
    font-size: 14px;
  }
}
