/* Shared layout: mobile below 768px, tablet from 768px, sidebar from 1100px. */
:root {
  --app-max-width: 1760px;
  --sidebar-width: 232px;
}

.desktop-sidebar,
.desktop-page-title {
  display: none;
}

.app-main,
.app-main > section,
.form-grid > *,
.form-row,
.invoice-item-grid > *,
.charts-grid > *,
.project-grid > * {
  min-width: 0;
}

.form-control {
  min-width: 0;
  max-width: 100%;
}

.page-title,
.page-sub,
.detail-body,
.profile-card,
.project-import-row > div {
  overflow-wrap: anywhere;
}

.section-head > :first-child {
  min-width: 0;
}

.section-head > .small-link {
  flex-shrink: 0;
}

.project-toolbar > .small-link,
.project-switcher button {
  flex-shrink: 0;
}

.sheet {
  position: relative;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.sheet h2 {
  padding-right: 36px;
}

body.sheet-open {
  overflow: hidden;
}

@media screen {
  body:not(.auth-page) {
    padding: 0;
    background: var(--bg);
  }

  .app-shell:not(.auth-shell) {
    width: 100%;
    max-width: var(--app-max-width);
    overflow: clip;
    min-height: 100dvh;
    border-radius: 0;
  }

  .has-app-nav .bottom-nav {
    position: fixed;
    border-radius: 0;
  }

  .has-app-nav .app-main {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }
}

/* Keep all four account controls accessible on narrow phones, including admin. */
@media screen and (max-width: 420px) {
  .topbar {
    gap: 8px;
    padding-inline: 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand img {
    width: 126px;
  }

  .topbar-actions {
    gap: 4px;
    flex-shrink: 0;
  }

  .topbar-actions .icon-btn {
    width: 36px;
    height: 42px;
  }

  .section-head,
  .performance-head,
  .notification-page-head {
    flex-wrap: wrap;
  }

  .record-side .activity-price {
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: right;
  }
}

@media screen and (min-width: 361px) and (max-width: 420px) {
  .record-side {
    max-width: 38%;
  }
}

@media screen and (min-width: 768px) {
  .topbar {
    min-height: 80px;
    padding: 16px 32px;
    border-bottom: 1px solid var(--line);
    gap: 24px;
  }

  .auth-topbar {
    border: 0;
  }

  .brand img {
    width: 168px;
  }

  .app-main {
    min-height: calc(100dvh - 80px);
    padding: 24px 32px 40px;
    background: var(--bg);
  }

  .app-main > section {
    width: 100%;
  }

  .page-title {
    font-size: 30px;
    margin-top: 0;
  }

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

  .section-head {
    margin: 24px 0 16px;
  }

  .section-head h2,
  .chart-head h2 {
    font-size: 18px;
  }

  .project-toolbar {
    padding: 14px 18px;
    gap: 24px;
    margin-bottom: 28px;
    background: #fff;
  }

  .project-switcher {
    max-width: 720px;
    gap: 14px;
  }

  .project-switcher label,
  .small-link,
  .form-row label {
    font-size: 13px;
  }

  .project-switcher .form-control {
    min-height: 44px;
    font-size: 14px;
  }

  .hello {
    margin-bottom: 22px;
    align-items: center;
  }

  .hello h1 {
    font-size: 28px;
  }

  .hello p,
  .date-chip {
    font-size: 13px;
  }

  .welcome {
    padding: 26px;
    grid-template-columns: minmax(0, 1fr) 170px;
    min-height: 190px;
  }

  .welcome h2 {
    font-size: 23px;
  }

  .welcome p {
    font-size: 14px;
    max-width: 480px;
    line-height: 1.6;
  }

  .welcome .cta {
    min-height: 44px;
    margin-top: 18px;
    font-size: 13px;
  }

  .car-illus img {
    width: 160px;
    max-height: 130px;
  }

  .dashboard-info {
    padding: 24px;
  }

  .dashboard-info > p,
  .dashboard-kpi span {
    font-size: 12px;
  }

  .dashboard-kpi strong {
    font-size: 30px;
  }

  .quick {
    gap: 14px;
  }

  .quick-btn {
    min-height: 100px;
    font-size: 12px;
    justify-content: center;
  }

  .timeline-card {
    padding: 16px;
  }

  .timeline-card b,
  .activity-text b,
  .list-copy b {
    font-size: 14px;
  }

  .timeline-card p,
  .timeline-card span,
  .activity-text span,
  .list-copy span {
    font-size: 12px;
  }

  .list-copy span,
  .activity-text span {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.6;
  }

  .record-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
  }

  .record-list > * {
    grid-column: 1 / -1;
  }

  .record-list > .list-card {
    grid-column: auto;
    margin: 0;
    height: 100%;
    min-width: 0;
  }

  .record-list > .section-head {
    margin: 0;
  }

  .photo-gallery .photo-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .photo-gallery .vehicle-photo {
    grid-column: 1 / -1;
    width: 100%;
    height: 210px;
  }

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

  .meta-item {
    padding: 18px;
  }

  .meta-item span {
    font-size: 12px;
    line-height: 1.4;
    margin-bottom: 8px;
  }

  .meta-item b {
    font-size: 20px;
  }

  .form-card.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    padding: 26px;
    align-items: start;
  }

  .form-card.form-grid > * {
    grid-column: 1 / -1;
  }

  .form-card.form-grid > .form-row {
    grid-column: auto;
  }

  .form-card.form-grid > .form-row:has(textarea, input[type="file"], #record_project, .vehicle-photo-grid) {
    grid-column: 1 / -1;
  }

  .form-card.form-grid .section-head {
    margin: 10px 0 0;
    padding-top: 20px;
    border-top: 1px solid var(--line);
  }

  .form-row small {
    line-height: 1.5;
  }

  textarea.form-control {
    min-height: 120px;
    resize: vertical;
  }

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

  .vehicle-photo-grid {
    max-width: 680px;
    gap: 12px;
  }

  .detail-hero {
    display: grid;
    grid-template-columns: minmax(220px, .8fr) minmax(0, 1.2fr);
    align-items: stretch;
  }

  .detail-image img {
    height: 280px;
  }

  .detail-body {
    padding: 28px;
    align-self: center;
  }

  .work-history {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .work-history .list-card {
    margin: 0;
  }

  .charts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
  }

  .charts-grid > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .chart-card,
  .performance-card {
    padding: 24px;
  }

  .performance-chart {
    max-height: 330px;
  }

  .performance-head p,
  .performance-hint,
  .statistics-period-btn,
  .statistics-action-btn {
    font-size: 12px;
  }

  .performance-period {
    font-size: 12px;
    white-space: normal;
  }

  .calendar-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }

  .calendar-details .section-head {
    margin-top: 0;
  }

  .calendar-day {
    width: min(100%, 44px);
    font-size: 13px;
  }

  .calendar-blank {
    aspect-ratio: auto;
  }

  .calendar-grid {
    row-gap: 14px;
  }

  .calendar-legend {
    flex-wrap: wrap;
  }

  .calendar-weekdays span,
  .calendar-legend span {
    font-size: 11px;
  }

  .calendar-details [id] {
    scroll-margin-top: 100px;
  }

  .invoice-paper {
    max-width: 1100px;
    margin-inline: auto;
  }

  .invoice-item-grid {
    gap: 20px;
  }

  .invoice-items .invoice-item {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 20px;
  }

  .invoice-item > .invoice-item-head,
  .invoice-item > .form-row,
  .invoice-item > .invoice-summary-row {
    grid-column: 1 / -1;
  }

  .invoice-summary {
    justify-self: end;
    width: min(100%, 440px);
  }

  .project-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
  }

  .project-card {
    padding: 24px;
  }

  .admin-overview-charts,
  .admin-overview-tables {
    gap: 20px;
  }

  .modal-wrap {
    align-items: center;
  }

  .sheet {
    width: 100%;
    max-width: 620px;
    padding: 30px;
  }

  .sheet-handle {
    display: none;
  }

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

  .has-app-nav .bottom-nav {
    height: 82px;
    grid-template-columns: 1fr 1fr 96px 1fr 1fr;
    padding-inline: max(24px, calc((100% - 720px) / 2));
  }

  .nav-item {
    font-size: 12px;
  }
}

@media screen and (min-width: 1100px) {
  .desktop-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: max(0px, calc((100% - var(--app-max-width)) / 2));
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--line);
    z-index: 35;
  }

  .sidebar-brand {
    min-height: 80px;
    padding: 22px 26px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  .sidebar-brand img {
    width: 174px;
  }

  .sidebar-add {
    margin: 12px 18px 18px;
    flex-shrink: 0;
    font-weight: 400;
  }

  .sidebar-add svg {
    width: 20px;
    height: 20px;
  }

  .sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 14px 20px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .sidebar-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    min-height: 44px;
    border-radius: 12px;
    color: #586b83;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
  }

  .sidebar-links svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .sidebar-links a:hover,
  .sidebar-profile:hover {
    background: #f5f8fd;
    color: var(--blue);
  }

  .sidebar-links a[aria-current="page"],
  .sidebar-profile[aria-current="page"] {
    background: #eaf2ff;
    color: var(--blue);
    font-weight: 400;
  }

  .sidebar-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 14px 16px;
    padding: 14px 8px;
    border-top: 1px solid var(--line);
    color: var(--ink);
    flex-shrink: 0;
    border-radius: 12px;
  }

  .sidebar-profile > span {
    min-width: 0;
  }

  .sidebar-profile b,
  .sidebar-profile small {
    display: block;
    overflow-wrap: anywhere;
    font-size: 12px;
    font-weight: 400;
  }

  .sidebar-profile small {
    margin-top: 4px;
    color: var(--muted);
  }

  .has-app-nav .app-main,
  .has-app-nav .topbar {
    margin-left: var(--sidebar-width);
  }

  .has-app-nav .app-main {
    padding: 28px 32px 48px;
  }

  .has-app-nav .bottom-nav,
  .has-app-nav .topbar > .brand {
    display: none;
  }

  .desktop-page-title {
    display: block;
    color: var(--navy);
    font-size: 17px;
    font-weight: 750;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .topbar-actions {
    margin-left: auto;
    flex-shrink: 0;
  }

  .dashboard-page {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, .85fr);
    gap: 24px;
  }

  .dashboard-page > .hello,
  .dashboard-page > .project-toolbar,
  .dashboard-page > .search-wrap {
    grid-column: 1 / -1;
    margin: 0;
    align-self: center;
  }

  .dashboard-columns {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, .85fr);
    gap: 24px;
    align-items: start;
  }

  .dashboard-overview,
  .dashboard-recent {
    min-width: 0;
  }

  .dashboard-recent {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 20px;
  }

  .dashboard-recent > .section-head {
    margin: 0 0 20px;
  }

  .dashboard-columns .welcome {
    grid-template-columns: minmax(0, 1fr) 100px;
    padding: 24px;
  }

  .dashboard-columns .welcome h2 {
    font-size: 21px;
  }

  .dashboard-columns .car-illus img {
    width: 100px;
  }

  .dashboard-columns .dashboard-info {
    padding: 20px 16px;
  }

  .profile-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }

  .profile-layout > .profile-card {
    position: sticky;
    top: 104px;
    min-width: 0;
  }

  .profile-editor {
    min-width: 0;
  }

  .profile-editor > .section-head {
    margin-top: 0;
  }

  .profile-editor .form-card.form-grid {
    padding: 22px;
  }

  .toast-stack {
    left: auto;
    right: 28px;
    bottom: 24px;
    transform: none;
    width: min(420px, calc(100% - 48px));
  }
}

@media screen and (min-width: 1440px) {
  :root {
    --sidebar-width: 248px;
  }

  .app-main,
  .has-app-nav .app-main {
    padding-inline: 40px;
  }

  .topbar {
    padding-inline: 40px;
  }

  .project-grid,
  .photo-gallery,
  .vehicle-records {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .charts-grid > :last-child:nth-child(odd) {
    grid-column: auto;
  }

  .dashboard-columns .welcome {
    grid-template-columns: minmax(0, 1fr) 160px;
  }

  .dashboard-columns .car-illus img {
    width: 150px;
  }

  .dashboard-columns .welcome h2 {
    font-size: 24px;
  }

  .admin-overview-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media print {
  body {
    padding: 0;
  }

  .app-shell {
    min-height: auto;
    border-radius: 0;
  }

  .desktop-sidebar,
  .desktop-page-title,
  .project-toolbar {
    display: none !important;
  }
}
