/* Premium mobiel & PWA */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html.is-standalone,
html.is-standalone body {
  overscroll-behavior-y: none;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.touch-target,
.btn,
.tab,
.bottom-nav__item,
.mobile-menu__item,
.data-table .btn-icon {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

select,
input,
textarea {
  font-size: 16px;
  min-height: 44px;
}

.bottom-nav,
.mobile-menu,
.mobile-menu-backdrop,
.tabs--desktop {
  display: none;
}

@media (max-width: 768px) {
  :root {
    --mobile-header-offset: calc(env(safe-area-inset-top, 0px) + 3.5rem);
  }

  html {
    scroll-padding-top: var(--mobile-header-offset);
  }

  .tabs--desktop {
    display: none !important;
  }

  .entry-view--mobile {
    display: block;
  }

  .entry-view--desktop {
    display: none !important;
  }

  .app-header {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 100;
    padding: 0;
    padding-top: env(safe-area-inset-top, 0);
    background: #fff;
    color: var(--text);
    box-shadow: 0 1px 0 var(--border), 0 4px 16px rgba(13, 59, 102, 0.06);
  }

  .app-header__inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    min-height: 52px;
    flex-wrap: nowrap;
  }

  .app-header__brand {
    flex-shrink: 0;
  }

  .app-header .brand-logo {
    background: transparent;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
  }

  .app-header .brand-logo__img--light {
    width: 40px;
    height: 40px;
  }

  .app-header__titles {
    display: none;
  }

  .app-header__brand .brand-mark {
    display: none;
  }

  .app-header__period {
    flex: 1;
    min-width: 0;
    gap: 0.35rem;
  }

  .app-header__period-label {
    display: none;
  }

  .app-header__period-selects {
    flex: 1;
    min-width: 0;
    gap: 0.35rem;
  }

  .app-header__period-selects .period-select {
    min-height: 40px;
    padding: 0.4rem 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f4f7fa;
    color: var(--accent);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%230d3b66' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.45rem center;
    padding-right: 1.5rem;
  }

  .period-select--month {
    flex: 1;
    min-width: 0;
  }

  .period-select--year {
    flex: 0 0 4.75rem;
    min-width: 4.75rem;
  }

  .app-header__actions {
    flex-shrink: 0;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.2rem 0.25rem;
    max-width: 5.75rem;
  }

  .save-status {
    display: none;
  }

  .save-status.saving {
    display: block;
    flex: 1 1 100%;
    font-size: 0.65rem;
    color: var(--muted);
    text-align: right;
  }

  .save-status.ok {
    display: block;
    flex: 1 1 100%;
    position: static;
    transform: none;
    max-width: none;
    font-size: 0.65rem;
    line-height: 1.2;
    color: var(--success);
    text-align: right;
    white-space: nowrap;
  }

  .btn-header-save {
    min-height: 40px;
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    white-space: nowrap;
  }

  .app-header__user {
    display: none;
  }

  .content {
    padding: var(--mobile-header-offset) 0.75rem calc(5.5rem + env(safe-area-inset-bottom, 0)) 0.75rem;
    box-sizing: border-box;
  }

  .content > .panel.active {
    scroll-margin-top: var(--mobile-header-offset);
  }

  .operatie-panel {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: 0 2px 12px rgba(13, 59, 102, 0.08);
    overflow: hidden;
    margin-bottom: 0.5rem;
  }

  .operatie-panel__hero {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.85rem 1rem;
    background: linear-gradient(135deg, #0d3b66 0%, #1a5f8a 100%);
    color: #fff;
  }

  .operatie-panel__hero-main {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .operatie-panel__hero-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.88;
  }

  .operatie-panel__hero-value {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .operatie-panel__hero-meta {
    font-size: 0.78rem;
    opacity: 0.9;
    overflow-wrap: anywhere;
  }

  .operatie-panel__sections {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .operatie-panel__sections.card-grid {
    grid-template-columns: 1fr;
  }

  #panel-operatie .operatie-card {
    margin-bottom: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border);
  }

  #panel-operatie .operatie-card--revenue {
    border-top: none;
  }

  #panel-operatie .operatie-card--revenue.card-highlight {
    border-left: none;
  }

  #panel-operatie .operatie-card h2 {
    margin: 0;
    padding: 0.75rem 1rem 0.35rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  #panel-operatie .computed-total--card {
    display: none;
  }

  #panel-operatie .form-grid--operatie {
    gap: 0;
    padding: 0 0 0.35rem;
  }

  #panel-operatie .operatie-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin: 0;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid #eef2f6;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
  }

  #panel-operatie .operatie-field--wide {
    grid-column: span 1;
  }

  #panel-operatie .operatie-field:last-child {
    border-bottom: none;
    padding-bottom: 0.85rem;
  }

  #panel-operatie .operatie-field input {
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
    font-size: 16px;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f9fbfd;
    min-height: 44px;
    padding: 0.5rem 0.65rem;
  }

  #panel-operatie .operatie-card--revenue .operatie-field input {
    font-weight: 600;
    color: var(--accent);
    background: #fff;
  }

  .mobile-menu__user {
    margin: 0 0 0.25rem;
    padding: 0.5rem 0.75rem 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent);
  }

  .mobile-menu__item--logout {
    margin-top: 0.5rem;
    color: var(--danger);
    font-weight: 600;
    border-top: 1px solid var(--border);
    border-radius: 0;
    padding-top: 0.85rem;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0));
    gap: 2px;
    box-shadow: 0 -4px 24px rgba(13, 59, 102, 0.08);
  }

  .bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    padding: 4px 2px;
    border: none;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.65rem;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
  }

  .bottom-nav__item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .bottom-nav__item.active {
    color: var(--accent);
    background: #f0f6fc;
  }

  .bottom-nav__item.active svg {
    stroke: var(--accent);
  }

  .card {
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
  }

  .entry-panel.card {
    padding: 0;
  }

  .entry-panel--overuren .entry-panel__toolbar {
    padding: 0.6rem 0.75rem;
    gap: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
  }

  .entry-panel--overuren .entry-panel__hero {
    flex: 1;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .entry-panel--overuren .entry-panel__hero-value {
    font-size: 1.2rem;
  }

  .entry-panel--overuren .entry-panel__add {
    flex-shrink: 0;
    min-height: 38px;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
  }

  .entry-view--mobile {
    padding: 0 0 0.5rem;
  }

  .entry-form-slot {
    padding: 0.65rem 0.75rem 0;
  }

  .entry-form {
    background: #f0f6fc;
    border: 1px solid #c5d9eb;
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.65rem;
  }

  .entry-form__title {
    margin: 0 0 0.65rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
  }

  .m-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.6rem;
    width: 100%;
    min-width: 0;
  }

  .m-field span {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  .m-field input {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    min-height: 44px;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: #fff;
  }

  .m-field--accent input {
    background: #fff;
    font-weight: 600;
    color: var(--accent);
  }

  .entry-form__actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
  }

  .entry-form__actions .btn {
    flex: 1;
    min-height: 44px;
  }

  .m-entry-list {
    list-style: none;
    margin: 0;
    padding: 0 0.75rem;
  }

  .m-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.35rem 0.5rem;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.45rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(13, 59, 102, 0.05);
  }

  .m-row__body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    min-width: 0;
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
    width: 100%;
  }

  .m-row__title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  .m-row__sub {
    font-size: 0.78rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  .m-row__value {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent);
    white-space: nowrap;
  }

  .m-row__value--muted {
    color: var(--muted);
    font-weight: 600;
  }

  .m-row__delete {
    flex-shrink: 0;
  }

  .entry-empty {
    margin: 0.5rem 0.75rem 0.75rem;
    padding: 1rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
    background: #f9fbfd;
    border-radius: 10px;
    border: 1px dashed var(--border);
  }

  .btn-block-mobile {
    display: block;
    width: calc(100% - 1.5rem);
    margin: 0.5rem 0.75rem 0.75rem;
    min-height: 44px;
  }

  .personeel-panel .subtabs {
    padding: 0.35rem 0.75rem 0;
    background: #f4f7fa;
  }

  .personeel-panel .subtab-panel {
    padding-top: 0.25rem;
  }

  #panel-ziekte .entry-panel__toolbar--inline,
  .entry-panel__toolbar--inline {
    display: none;
  }

  .card-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span-2 {
    grid-column: span 1;
  }

  .card-header-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .card-header-row .btn-secondary {
    width: 100%;
    min-height: 44px;
  }

  .btn-row {
    flex-direction: column;
  }

  .btn-row .btn {
    width: 100%;
    min-height: 44px;
  }

  .charts-row,
  .charts-row-3 {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1rem 0;
  }

  .chart-box,
  .chart-box-sm {
    height: 220px;
  }

  .content,
  .app-shell {
    overflow-x: hidden;
    max-width: 100%;
  }

  .stats-kpis {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .kpi {
    padding: 0.75rem;
    min-width: 0;
  }

  .kpi .value,
  .kpi .value-sm {
    font-size: 1.05rem;
    word-break: break-word;
  }

  .kpi .sub,
  .pct-badge {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  #panel-stats .card-header-row label {
    width: 100%;
  }

  #panel-stats .card-header-row select {
    width: 100%;
  }

  .stats-insights ul {
    padding-left: 1.1rem;
    margin: 0;
  }

  .stats-insights li {
    margin-bottom: 0.5rem;
    overflow-wrap: anywhere;
  }

  .email-layout,
  .stats-email-layout {
    grid-template-columns: 1fr;
  }

  .card-preview iframe {
    min-height: 360px;
  }

  .table-wrap--stack {
    margin: 0;
    padding: 0;
    overflow-x: visible;
  }

  .data-table--stack-mobile {
    min-width: 0 !important;
    width: 100%;
  }

  .data-table--stack-mobile thead {
    display: none;
  }

  .data-table--stack-mobile tbody tr,
  .data-table--stack-mobile tfoot tr:not(.table-summary) {
    display: block;
    background: #f9fbfd;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.75rem 0.5rem;
  }

  .data-table--stack-mobile tbody td,
  .data-table--stack-mobile tfoot tr:not(.table-summary) td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid #e8ecf0;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .data-table--stack-mobile tbody td:last-child,
  .data-table--stack-mobile tfoot tr:not(.table-summary) td:last-child {
    border-bottom: none;
  }

  .data-table--stack-mobile tbody td[data-label]::before,
  .data-table--stack-mobile tfoot tr:not(.table-summary) td[data-label]::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent);
    flex: 0 0 42%;
    max-width: 46%;
    line-height: 1.25;
    padding-right: 0.35rem;
  }

  .data-table--stack-mobile tbody td.cell-actions {
    justify-content: flex-end;
    padding-top: 0.15rem;
    border-bottom: none;
  }

  .data-table--stack-mobile tbody td.cell-actions::before {
    content: none;
  }

  .data-table--stack-mobile tbody td > input,
  .data-table--stack-mobile tbody td > select {
    flex: 1;
    min-width: 0;
    width: auto;
    max-width: 58%;
    min-height: 40px;
    font-size: 16px;
  }

  .data-table--stack-mobile.data-table--readonly tbody td,
  .data-table--stack-mobile.data-table--readonly tfoot td {
    text-align: right;
    align-items: flex-start;
  }

  .data-table--stack-mobile.data-table--readonly tbody td[data-label]::before,
  .data-table--stack-mobile.data-table--readonly tfoot td[data-label]::before {
    text-align: left;
    padding-top: 0.1rem;
  }

  .data-table--stack-mobile.data-table--readonly .cell-row-title {
    display: block;
    text-align: left;
    font-size: 1rem;
    padding: 0.55rem 0 0.4rem;
    border-bottom: 2px solid var(--accent);
    margin-bottom: 0.15rem;
  }

  .data-table--stack-mobile.data-table--readonly .cell-row-title::before {
    content: none;
  }

  .data-table--stack-mobile tfoot tr.table-summary td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: none;
    padding: 0.65rem 0;
    background: #f0f6fc;
    border-radius: 10px;
    margin-top: 0.25rem;
    font-weight: 600;
  }

  .data-table--stack-mobile tfoot tr.table-summary {
    display: block;
    background: #f0f6fc;
    border: 1px solid #c5d9eb;
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0;
  }

  .table-summary__label {
    color: var(--accent);
    font-size: 0.85rem;
  }

  .table-summary__value {
    font-size: 1.1rem;
    color: var(--text);
  }

  .data-table input,
  .data-table select {
    min-height: 40px;
    font-size: 16px;
  }

  .data-table .btn-icon {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.25rem;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }

  /* Mobiel menu (Meer) */
  .mobile-menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(13, 59, 102, 0.4);
    z-index: 250;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mobile-menu-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 260;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    padding: 0.5rem 0.75rem calc(1rem + env(safe-area-inset-bottom, 0));
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -8px 32px rgba(13, 59, 102, 0.15);
  }

  .mobile-menu.is-open {
    transform: translateY(0);
  }

  .mobile-menu__handle {
    width: 36px;
    height: 4px;
    background: #dde3ea;
    border-radius: 2px;
    margin: 0.5rem auto 0.75rem;
  }

  .mobile-menu__title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 0 0.5rem 0.5rem;
  }

  .mobile-menu__item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 48px;
    padding: 0.65rem 0.75rem;
    border: none;
    background: none;
    font: inherit;
    font-size: 1rem;
    color: var(--text);
    text-align: left;
    border-radius: 10px;
    cursor: pointer;
  }

  .mobile-menu__item:active,
  .mobile-menu__item.active {
    background: #f0f6fc;
    color: var(--accent);
  }

  .pwa-install {
    display: flex;
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0));
    z-index: 150;
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    box-shadow: 0 8px 24px rgba(13, 59, 102, 0.35);
    font-size: 0.9rem;
  }

  .pwa-install[hidden] {
    display: none !important;
  }

  .pwa-install__actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
  }

  .pwa-install__actions button {
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.65rem;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
  }

  .pwa-install__btn-install {
    background: #fff;
    color: var(--accent);
  }

  .pwa-install__btn-dismiss {
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
  }
}

@media (min-width: 769px) {
  .tabs--desktop {
    display: flex;
  }

  .header-period-row {
    display: contents;
  }

  .header-actions-row {
    display: contents;
  }

  .pwa-install {
    display: none !important;
  }
}
