
/* =========================================
   CLMS 2.0 - MOBILE ZOOM FIX
   ========================================= */

/* Keep controls inside their containers */
input,
select,
textarea {
    box-sizing: border-box;
    max-width: 100%;
}

/* Desktop: compact form controls */
@media (min-width: 769px) {
    input,
    select,
    textarea {
        font-size: 13px !important;
    }
}

/* Mobile: prevent iPhone Safari auto-zoom */
@media (max-width: 768px) {
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Dashboard filter dropdowns: preserve compact appearance */
@media (max-width: 768px) {
    .filter-field select,
    .table-filter,
    .users-select {
        font-size: 16px !important;
    }
}

/* =========================================
   RESPONSIVE DATE FIELDS — MOBILE FIX
   Keep native date controls inside their form/grid cells.
   ========================================= */
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="time"] {
    box-sizing: border-box !important;
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-inline: 0;
}

/* Form/grid children must be allowed to shrink on narrow screens. */
.form-grid > *,
.form-grid .field,
.form-field,
.field,
.loss-filter-grid > *,
.loss-filter-grid label,
label:has(> input[type="date"]),
label:has(> input[type="datetime-local"]) {
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 768px) {
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="time"] {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        padding-left: 8px;
        padding-right: 6px;
        font-size: 16px !important;
        line-height: normal;
    }

    /* Prevent date fields from forcing a horizontal page overflow. */
    .form-grid,
    .form-grid .field,
    .field,
    .form-field,
    .loss-filter-grid,
    .loss-filter-grid label {
        min-width: 0;
    }

    .date-value,
    .topbar-date,
    time {
        max-width: 100%;
        overflow-wrap: anywhere;
    }
}


/* =========================================
   COMPACT DATE CONTROLS — prevent oversized fields
   Keep analysis filter dates compact and preserve native iOS picker UI.
   ========================================= */
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="time"] {
    box-sizing: border-box !important;
    max-width: 100%;
    min-width: 0;
    font-family: inherit;
    font-size: 13px;
    text-align: left;
}

/* Loss/Rejected analysis filters have a compact six-column grid. */
.loss-filter-grid input[type="date"],
.loss-filter-grid input[type="datetime-local"],
.loss-filter-grid input[type="month"],
.loss-filter-grid input[type="time"] {
    width: 100% !important;
    height: 35px !important;
    min-height: 35px !important;
    padding: 0 9px !important;
    border-radius: 6px !important;
    font-size: 13px !important;
    line-height: normal;
    appearance: auto;
    -webkit-appearance: auto;
}

/* Keep date text natural on iOS without enlarging the control. */
input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value {
    min-height: 0;
    margin: 0;
    padding: 0;
    text-align: left;
}

@media (max-width: 768px) {
    /* Native date fields in regular forms stay touch-friendly. */
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="time"] {
        min-height: 42px;
        height: 42px;
        padding: 0 10px;
        font-size: 16px !important;
        appearance: auto;
        -webkit-appearance: auto;
    }

    /* Analysis filter boxes remain compact and fit their grid cells. */
    .loss-filter-grid input[type="date"],
    .loss-filter-grid input[type="datetime-local"],
    .loss-filter-grid input[type="month"],
    .loss-filter-grid input[type="time"] {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: 40px !important;
        min-height: 40px !important;
        padding: 0 6px !important;
        font-size: 16px !important;
    }
}

/* =========================================
   NEW CASE FORM — iPhone date input overflow fix
   Scope to the case-entry form so desktop layout stays unchanged.
   ========================================= */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        width: 100%;
        min-width: 0 !important;
    }

    .form-grid > *,
    .form-field,
    .form-field.full-width {
        width: 100%;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .form-field input[type="date"],
    .form-field input[type="datetime-local"],
    .form-field input[type="month"],
    .form-field input[type="time"] {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 10px !important;
        font-size: 16px !important;
        line-height: normal !important;
        text-align: left !important;
    }

    .form-field input[type="date"]::-webkit-date-and-time-value,
    .form-field input[type="datetime-local"]::-webkit-date-and-time-value {
        text-align: left;
        margin: 0;
        padding: 0;
    }
}


/* =========================================================
   FINAL MOBILE FIT + NO PAGE ZOOM
   Prevent date controls from overlapping on narrow screens.
   ========================================================= */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}
*, *::before, *::after {
    box-sizing: border-box;
}
@media (max-width: 768px) {
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="time"] {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding-left: 4px !important;
        padding-right: 4px !important;
        font-size: 16px !important;
        letter-spacing: 0 !important;
    }

    /* Give date values a full-width row on mobile instead of squeezing them
       into narrow two/three-column filter cells. */
    .loss-filter-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    .loss-filter-grid > *,
    .loss-filter-grid label,
    .loss-filter-grid input,
    .loss-filter-grid select {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .form-grid,
    .form-field,
    .field,
    .form-field.full-width,
    .filter-field {
        min-width: 0 !important;
        max-width: 100% !important;
    }
}

/* FINAL: iPhone/iOS date field should match the other form controls. */
@media (max-width: 768px) {
  .form-field input[type="date"],
  input#caseDate[type="date"] {
    -webkit-appearance: none !important;
    appearance: none !important;
    display: flex !important;
    align-items: center !important;
    flex: 0 1 auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    padding: 0 12px !important;
    margin: 0 !important;
    border: 1px solid #d9e1ed !important;
    border-radius: 10px !important;
    background-color: #fff !important;
    color: #202c40 !important;
    font: 400 16px/normal -apple-system, BlinkMacSystemFont, "Inter", Arial, sans-serif !important;
    letter-spacing: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  .form-field input[type="date"]::-webkit-date-and-time-value,
  input#caseDate[type="date"]::-webkit-date-and-time-value {
    display: block;
    text-align: left !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: normal !important;
  }
  .form-field input[type="date"]::-webkit-calendar-picker-indicator,
  input#caseDate[type="date"]::-webkit-calendar-picker-indicator {
    margin: 0 0 0 6px;
    padding: 0;
    flex: 0 0 auto;
  }
  .form-grid, .form-field, .form-field > input, .form-field > select {
    min-width: 0 !important;
    max-width: 100% !important;
  }
}


/* CLMS stylish date picker — red selected date, neutral unselected state */
input[type="date"],
input[type="datetime-local"],
input[type="month"] {
    color-scheme: light;
    accent-color: #c62828;
    border: 1px solid #d7dde5 !important;
    border-radius: 8px !important;
    background: #fff !important;
    color: #263449 !important;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="month"]:focus {
    outline: none !important;
    border-color: #c62828 !important;
    box-shadow: 0 0 0 3px rgba(198, 40, 40, .12) !important;
}
input[type="date"].clms-date-has-value,
input[type="datetime-local"].clms-date-has-value,
input[type="month"].clms-date-has-value {
    background: #c62828 !important;
    border-color: #c62828 !important;
    color: #fff !important;
    font-weight: 600 !important;
}
input[type="date"].clms-date-has-value::-webkit-calendar-picker-indicator,
input[type="datetime-local"].clms-date-has-value::-webkit-calendar-picker-indicator,
input[type="month"].clms-date-has-value::-webkit-calendar-picker-indicator {
    filter: brightness(0) invert(1);
    opacity: .95;
}


/* CLMS custom date calendar — selected date appears as a bordered red square */
.clms-calendar-field{position:relative;display:inline-flex;align-items:stretch;width:100%;min-width:0}
.clms-calendar-display{width:100%;min-width:0;box-sizing:border-box;cursor:pointer;padding-right:42px!important;background:#fff!important;color:#202c40!important;border:1px solid #d7dde5!important;border-radius:8px!important}
.clms-calendar-field:after{content:"";position:absolute;right:14px;top:50%;width:18px;height:18px;transform:translateY(-50%);pointer-events:none;background-repeat:no-repeat;background-position:center;background-size:18px 18px;opacity:.82;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23263449' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M16 3v4M8 3v4M3 10h18'/%3E%3C/svg%3E")}
.clms-calendar-native{position:absolute!important;width:1px!important;height:1px!important;min-height:1px!important;opacity:0!important;pointer-events:none!important;left:0!important;bottom:0!important;padding:0!important;border:0!important;overflow:hidden!important}
.clms-calendar-popup{z-index:99999;width:350px;max-width:calc(100vw - 24px);padding:16px;background:#fff;border:1px solid #d6dde6;border-radius:14px;box-shadow:0 14px 40px rgba(24,39,60,.18);font-family:inherit;color:#17243a;box-sizing:border-box}
.clms-calendar-head{display:grid;grid-template-columns:36px 1fr 36px;align-items:center;gap:8px;margin-bottom:12px}
.clms-calendar-head strong{text-align:center;font-size:16px;font-weight:650;letter-spacing:.1px}
.clms-calendar-nav{width:34px;height:34px;border:1px solid #e1e6ed;border-radius:7px;background:#fff;color:#23334b;display:flex;align-items:center;justify-content:center;cursor:pointer;padding:7px}
.clms-calendar-nav svg{width:18px;height:18px}
.clms-calendar-grid{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:0;border:1px solid #e0e5ec;border-radius:8px;overflow:hidden}
.clms-calendar-weekday{height:34px;display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;color:#697588;background:#f8fafc;border-bottom:1px solid #e0e5ec}
.clms-calendar-day{height:39px;min-width:0;border:0;border-right:1px solid #e0e5ec;border-bottom:1px solid #e0e5ec;background:#fff;color:#263449;font:500 13px/1 inherit;display:flex;align-items:center;justify-content:center;cursor:pointer;border-radius:0;padding:0}
.clms-calendar-day:nth-child(7n){border-right:0}
.clms-calendar-day:nth-last-child(-n+7){border-bottom:0}
.clms-calendar-day:hover:not(:disabled){background:#fff1f1;color:#b71c1c}
.clms-calendar-day.is-outside{color:#aab2bd;background:#fafbfd}
.clms-calendar-day.is-selected,.clms-calendar-day.is-selected:hover{background:#c62828;color:#fff;font-weight:700;box-shadow:inset 0 0 0 1px #c62828}
.clms-calendar-day.is-disabled{color:#c5cbd3;cursor:not-allowed;background:#f9fafb}
.clms-calendar-footer{display:flex;justify-content:flex-end;gap:10px;margin-top:14px}
.clms-calendar-clear,.clms-calendar-apply{height:36px;min-width:82px;padding:0 16px;border-radius:7px;font:600 13px inherit;cursor:pointer}
.clms-calendar-clear{background:#fff;border:1px solid #d5dce5;color:#263449}
.clms-calendar-apply{background:#c62828;border:1px solid #c62828;color:#fff}
.clms-calendar-apply:hover{background:#ad2020}
@media(max-width:420px){.clms-calendar-popup{width:calc(100vw - 24px);padding:12px}.clms-calendar-day{height:36px}.clms-calendar-weekday{height:30px}}


/* Calendar popup placement/scroll fix: opens above when bottom space is limited. */
.clms-calendar-popup{overscroll-behavior:contain;touch-action:pan-y}
.clms-calendar-field{min-width:0}
.clms-calendar-native{pointer-events:none!important}


/* Compact CLMS calendar popup */
.clms-calendar-popup{width:292px!important;padding:11px!important;border-radius:11px!important}
.clms-calendar-head{grid-template-columns:30px 1fr 30px!important;gap:6px!important;margin-bottom:8px!important}
.clms-calendar-head strong{font-size:14px!important}
.clms-calendar-nav{width:29px!important;height:29px!important;padding:6px!important}
.clms-calendar-nav svg{width:16px!important;height:16px!important}
.clms-calendar-weekday{height:27px!important;font-size:10px!important}
.clms-calendar-day{height:31px!important;font-size:12px!important}
.clms-calendar-footer{margin-top:10px!important;gap:8px!important}
.clms-calendar-clear,.clms-calendar-apply{height:31px!important;min-width:68px!important;padding:0 12px!important;font-size:12px!important}
@media(max-width:420px){
 .clms-calendar-popup{width:min(292px,calc(100vw - 24px))!important;padding:10px!important}
 .clms-calendar-day{height:30px!important}
 .clms-calendar-weekday{height:26px!important}
}


/* Calendar always fits in viewport: no inner scrollbar, smooth upward opening */
.clms-calendar-popup{
  max-height:none!important;
  overflow:visible!important;
  overflow-y:visible!important;
  scrollbar-width:none!important;
  transform-origin:bottom left;
  animation:clms-calendar-fade-in .16s ease-out both;
  will-change:transform,opacity;
}
.clms-calendar-popup::-webkit-scrollbar{display:none!important}
.clms-calendar-popup.clms-calendar-open-above{animation:clms-calendar-open-above .18s ease-out both}
.clms-calendar-popup.clms-calendar-open-below{animation:clms-calendar-open-below .18s ease-out both}
@keyframes clms-calendar-open-above{
  from{opacity:0;translate:0 7px}
  to{opacity:1;translate:0 0}
}
@keyframes clms-calendar-open-below{
  from{opacity:0;translate:0 -5px}
  to{opacity:1;translate:0 0}
}
@keyframes clms-calendar-fade-in{from{opacity:0}to{opacity:1}}


/* CLMS custom calendar refinement — premium styling with crisp, unscaled text */
.clms-calendar-popup {
  width: 326px !important;
  max-width: calc(100vw - 24px) !important;
  padding: 15px !important;
  box-sizing: border-box !important;
  background: #fff !important;
  border: 1px solid #d8e0eb !important;
  border-radius: 14px !important;
  box-shadow: 0 14px 36px rgba(24, 39, 60, .16) !important;
  color: #17243a !important;
  font-family: "Segoe UI", Arial, sans-serif !important;
  font-size: 13px !important;
  line-height: 1.35 !important;
  filter: none !important;
  opacity: 1 !important;
  transform: none !important;
  will-change: auto !important;
  -webkit-font-smoothing: antialiased;
  text-rendering: auto;
}
.clms-calendar-head { grid-template-columns: 36px minmax(0,1fr) 36px !important; gap: 8px !important; margin-bottom: 12px !important; }
.clms-calendar-head strong {
  color: #17243a !important;
  font-family: "Segoe UI", Arial, sans-serif !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  line-height: 1.3 !important;
  text-shadow: none !important;
}
.clms-calendar-nav {
  width: 36px !important; height: 36px !important;
  padding: 8px !important;
  color: #34445c !important; background: #fff !important;
  border: 1px solid #dce3ec !important; border-radius: 8px !important;
  box-shadow: none !important; filter: none !important;
}
.clms-calendar-nav svg { width: 18px !important; height: 18px !important; }
.clms-calendar-weekday {
  height: 34px !important;
  color: #68768b !important; background: #f6f8fb !important;
  font-family: "Segoe UI", Arial, sans-serif !important;
  font-size: 11px !important; font-weight: 700 !important; line-height: 1 !important;
}
.clms-calendar-day {
  height: 39px !important;
  color: #263449 !important; background: #fff !important;
  font-family: "Segoe UI", Arial, sans-serif !important;
  font-size: 13px !important; font-weight: 600 !important; line-height: 1 !important;
  text-shadow: none !important; filter: none !important; opacity: 1 !important;
  transform: none !important; box-shadow: none;
}
.clms-calendar-day.is-outside { color: #aab3c0 !important; background: #fafbfd !important; }
.clms-calendar-day.is-selected, .clms-calendar-day.is-selected:hover {
  color: #fff !important; background: #c62828 !important;
  font-weight: 700 !important; box-shadow: inset 0 0 0 1px #c62828 !important;
}
.clms-calendar-footer { margin-top: 14px !important; gap: 9px !important; }
.clms-calendar-clear, .clms-calendar-apply {
  min-width: 84px !important; height: 38px !important; padding: 0 16px !important;
  border-radius: 8px !important;
  font-family: "Segoe UI", Arial, sans-serif !important;
  font-size: 13px !important; font-weight: 700 !important; line-height: 1 !important;
  letter-spacing: .1px !important; text-shadow: none !important;
  filter: none !important; opacity: 1 !important; transform: none !important;
  box-shadow: none !important; -webkit-font-smoothing: antialiased;
}
.clms-calendar-clear { color: #34445c !important; background: #fff !important; border: 1px solid #d7dfeb !important; }
.clms-calendar-apply { color: #fff !important; background: #c62828 !important; border: 1px solid #c62828 !important; }
.clms-calendar-apply:hover { color: #fff !important; background: #ad2020 !important; }
.clms-calendar-display {
  color: #202c40 !important;
  font-family: "Segoe UI", Arial, sans-serif !important;
  font-size: 13px !important; font-weight: 600 !important;
  line-height: 1.4 !important; letter-spacing: .1px !important;
  -webkit-font-smoothing: antialiased;
}
@media (max-width: 420px) {
  .clms-calendar-popup { width: min(326px, calc(100vw - 24px)) !important; padding: 12px !important; }
  .clms-calendar-day { height: 36px !important; }
  .clms-calendar-weekday { height: 31px !important; }
}


/* Unified CLMS date-picker system: compact, square cells, blue selection */
.clms-calendar-display {
    min-height: 35px !important;
    height: 35px !important;
    padding: 5px 36px 5px 10px !important;
    border: 1px solid #d6deea !important;
    border-radius: 6px !important;
    font-size: 10px !important;
    color: #253248 !important;
    box-shadow: none !important;
}
.clms-calendar-display:hover,
.clms-calendar-display:focus,
.clms-calendar-display:focus-visible {
    border-color: #5278c4 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(1,36,113,.10) !important;
}
.clms-calendar-field:after {
    right: 10px !important;
    width: 15px !important;
    height: 15px !important;
    background-size: 15px 15px !important;
}
.clms-calendar-popup {
    width: 286px !important;
    padding: 11px !important;
    border-radius: 11px !important;
    box-shadow: 0 12px 34px rgba(18,35,58,.16) !important;
}
.clms-calendar-head {
    grid-template-columns: 27px 1fr 27px !important;
    gap: 5px !important;
    margin-bottom: 8px !important;
}
.clms-calendar-head strong { font-size: 12px !important; font-weight: 500 !important; }
.clms-calendar-nav {
    width: 25px !important;
    height: 25px !important;
    padding: 5px !important;
    border-radius: 5px !important;
}
.clms-calendar-nav svg { width: 14px !important; height: 14px !important; }
.clms-calendar-grid {
    grid-template-columns: repeat(7,minmax(0,1fr)) !important;
    gap: 3px !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: visible !important;
}
.clms-calendar-weekday {
    height: 20px !important;
    border: 0 !important;
    background: transparent !important;
    font-size: 9px !important;
    font-weight: 500 !important;
}
.clms-calendar-day {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 2px !important;
    background: #fff !important;
    color: #263449 !important;
    font: 400 10px/1 inherit !important;
}
.clms-calendar-day:nth-child(7n),
.clms-calendar-day:nth-last-child(-n+7) { border: 0 !important; }
.clms-calendar-day:hover:not(:disabled) {
    background: #dce9ff !important;
    color: #17468f !important;
}
.clms-calendar-day.is-outside { color: #b9c1cc !important; background: transparent !important; }
.clms-calendar-day.is-selected,
.clms-calendar-day.is-selected:hover {
    background: #2456a6 !important;
    color: #fff !important;
    border-radius: 2px !important;
    font-weight: 500 !important;
    box-shadow: none !important;
}
.clms-calendar-day.is-disabled { color: #c5cbd3 !important; background: #f9fafb !important; }
.clms-calendar-footer { margin-top: 8px !important; gap: 6px !important; }
.clms-calendar-clear,
.clms-calendar-apply {
    height: 28px !important;
    min-width: 62px !important;
    padding: 0 10px !important;
    border-radius: 5px !important;
    font: 400 9px/1 inherit !important;
}
.clms-calendar-apply {
    background: #2456a6 !important;
    border-color: #2456a6 !important;
}
.clms-calendar-apply:hover { background: #19478f !important; }
@media(max-width:420px) {
    .clms-calendar-popup { width: min(286px,calc(100vw - 24px)) !important; padding: 10px !important; }
    .clms-calendar-day { height: auto !important; aspect-ratio: 1 / 1 !important; }
}
