/* Web interpretation of Apple's split views and Liquid Glass materials.
   Keep the existing palette. Glass belongs to navigation and controls;
   data tables, charts and documents retain opaque surfaces. */
@media screen {
  html[data-theme] :is(.stat-icon, .documents-card-icon, .journal-group-icon) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 0;
    flex-shrink: 0;
  }

  html[data-theme] :is(.stat-icon, .documents-card-icon, .journal-group-icon) > .icon {
    display: block;
    margin: 0;
    align-self: center;
    flex-shrink: 0;
  }

  html[data-theme] select:not([multiple]):not([size]) {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='m4 6 4 4 4-4' stroke='%23526579' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
  }

  html[data-theme='dark'] select:not([multiple]):not([size]) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='m4 6 4 4 4-4' stroke='%23becbd9' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
  html[data-theme] {
    --depth-highlight: rgb(255 255 255 / 0.68);
    --depth-sheen: rgb(255 255 255 / 0.12);
    --depth-edge: rgb(255 255 255 / 0.42);
    --depth-shadow: 0 2px 5px rgb(16 27 41 / 0.045), 0 9px 24px rgb(16 27 41 / 0.045);
    --depth-control: 0 2px 4px rgb(16 27 41 / 0.07), inset 0 1px 0 var(--depth-highlight);
    --glass-shadow:
      0 4px 14px rgb(16 27 41 / 0.09), inset 0 1px 0 var(--depth-highlight),
      inset 0 -1px 0 rgb(16 27 41 / 0.035);
    --glass-sheen: rgb(255 255 255 / 0.28);
  }
  html[data-theme='dark'] {
    --depth-highlight: rgb(255 255 255 / 0.12);
    --depth-sheen: rgb(255 255 255 / 0.025);
    --depth-edge: rgb(255 255 255 / 0.1);
    --depth-shadow: 0 2px 4px rgb(0 0 0 / 0.1), 0 9px 24px rgb(0 0 0 / 0.11);
    --depth-control: 0 2px 5px rgb(0 0 0 / 0.14), inset 0 1px 0 var(--depth-highlight);
    --glass-shadow:
      0 4px 16px rgb(0 0 0 / 0.16), inset 0 1px 0 var(--depth-highlight),
      inset 0 -1px 0 rgb(0 0 0 / 0.1);
    --glass-sheen: rgb(255 255 255 / 0.13);
  }
  /* One quiet divider, a stable selection, and a collapsible navigation pane. */
  html[data-theme] .sidebar {
    border-right: 1px solid var(--mac-line);
    box-shadow:
      inset -1px 0 0 var(--depth-edge),
      5px 0 20px rgb(0 0 0 / 0.025);
    background: var(--mac-sidebar);
    background-image: linear-gradient(150deg, var(--depth-sheen), transparent 65%);
  }
  html[data-theme] .sidebar-toggle {
    display: inline-flex;
    flex-shrink: 0;
  }
  html[data-theme] .sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    visibility: hidden;
    pointer-events: none;
  }
  html[data-theme] .sidebar-collapsed .main-shell {
    margin-left: 0;
    width: 100%;
  }
  html[data-theme] .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    gap: 12px;
    min-height: 70px;
    height: 70px;
    border-bottom: 1px solid var(--mac-line);
    background: var(--mac-canvas);
    box-shadow: 0 1px 0 var(--depth-edge);
  }
  html[data-theme] .topbar .breadcrumbs {
    min-width: 0;
  }
  html[data-theme] .topbar .breadcrumbs strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  html[data-theme] .topbar-right {
    position: relative;
    isolation: isolate;
    gap: 7px;
    padding: 5px 7px;
    border: 1px solid var(--mac-line);
    border-radius: 999px;
    background: var(--mac-raised);
    box-shadow: var(--glass-shadow);
    flex-shrink: 0;
  }
  html[data-theme] .topbar .topbar-right {
    gap: 7px;
  }
  html[data-theme] .topbar-right > .save-state {
    padding-left: 5px;
  }
  html[data-theme] .topbar-right :is(.icon-button, .theme-toggle, .care-topbar-notice) {
    border-radius: 50%;
  }
  html[data-theme] .topbar :is(.sidebar-toggle, .mobile-menu) {
    border: 1px solid var(--mac-line);
    background: var(--mac-surface);
    box-shadow: var(--depth-control);
    border-radius: 11px;
    width: 36px;
    min-width: 36px;
    height: 36px;
  }
  html[data-theme] .nav-link {
    transition:
      background-color 0.16s ease,
      box-shadow 0.16s ease;
  }
  html[data-theme] .nav-link.active {
    position: relative;
    isolation: isolate;
    background-image: linear-gradient(160deg, rgb(255 255 255 / 0.13), rgb(0 0 0 / 0.02));
    box-shadow:
      0 3px 8px rgb(0 0 0 / 0.1),
      inset 0 1px 0 rgb(255 255 255 / 0.2);
    border-radius: 10px;
  }
  /* Subtle solid depth in the content layer, without blurring any data. */
  html[data-theme]
    :is(
      .panel,
      .stat-card,
      .care-stat,
      .care-signal-card,
      .care-case-card,
      .documents-selector,
      .documents-card,
      .documents-history,
      .month-panel,
      .access-card
    ) {
    border-radius: 14px;
    background-image: linear-gradient(155deg, var(--depth-sheen), transparent 58%);
    box-shadow:
      var(--depth-shadow),
      inset 0 1px 0 var(--depth-highlight);
  }
  html[data-theme] :is(.btn, .format-select label, .code-option) {
    border-radius: 10px;
    box-shadow: var(--depth-control);
    transition:
      box-shadow 0.15s ease,
      background-color 0.15s ease,
      transform 0.15s ease;
  }
  html[data-theme] .btn.primary {
    position: relative;
    isolation: isolate;
    background-image: linear-gradient(160deg, rgb(255 255 255 / 0.14), rgb(0 0 0 / 0.025));
    box-shadow:
      0 3px 8px rgb(0 0 0 / 0.1),
      inset 0 1px 0 rgb(255 255 255 / 0.28);
  }
  html[data-theme] .btn:not(:disabled):hover {
    box-shadow:
      0 4px 10px rgb(0 0 0 / 0.1),
      inset 0 1px 0 var(--depth-highlight);
  }
  html[data-theme] .btn:not(:disabled):active {
    transform: translateY(1px);
    box-shadow: inset 0 1px 3px rgb(0 0 0 / 0.1);
  }
  html[data-theme] :is(.avatar, .stat-icon, .documents-card-icon) {
    box-shadow:
      inset 0 1px 0 var(--depth-highlight),
      0 2px 4px rgb(0 0 0 / 0.055);
  }
  html[data-theme] :is(input, select, textarea) {
    box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.045);
    border-radius: 9px;
  }
  html[data-theme] :is(.search-field, .date-control) {
    box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.04);
    border-radius: 10px;
  }
  html[data-theme] :is(.search-field, .date-control) input {
    box-shadow: none;
  }
  html[data-theme] :is(input, select, textarea):focus {
    box-shadow:
      0 0 0 3px var(--mac-accent-soft),
      inset 0 1px 2px rgb(0 0 0 / 0.04);
  }
  html[data-theme] :is(.search-field, .date-control):focus-within {
    border-color: var(--mac-accent);
    box-shadow: 0 0 0 3px var(--mac-accent-soft);
  }
  html[data-theme] :is(.search-field, .date-control) input:focus {
    box-shadow: none;
  }
  /* A regular, readable glass material for filter and selection controls. */
  html[data-theme] :is(.scope-controls, .care-filters) {
    padding: 18px 20px;
    border: 1px solid var(--mac-line);
    border-radius: 16px;
    background: var(--mac-surface);
    background-image: linear-gradient(155deg, var(--depth-sheen), transparent 65%);
    box-shadow: var(--glass-shadow);
  }
  html[data-theme] .care-filters {
    gap: 16px;
    align-items: end;
  }
  html[data-theme] .care-filters > label {
    gap: 7px;
    min-width: 0;
    font-size: 13px;
  }
  html[data-theme] .care-filters :is(input, select):not([type='checkbox']) {
    min-width: 0;
    min-height: 44px;
    height: 44px;
    font-size: 14px;
    border-radius: 10px;
  }
  /* One field surface: the icon and editable input share the same height. */
  html[data-theme] .care-filters .search-field {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 9px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--mac-line);
    border-radius: 10px;
    background: var(--mac-raised);
    box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.045);
  }
  html[data-theme]
    .care-filters
    .search-field
    > input:is(#care-signals-search, #care-passport-search) {
    display: block;
    flex: 1 1 0;
    width: 0;
    max-width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    outline: none;
    color: var(--mac-text);
    font-size: 14px;
  }
  html[data-theme] .care-filters .search-field input::placeholder {
    font-size: 13px;
    color: var(--mac-secondary);
  }
  html[data-theme] .care-filters .search-field > .icon {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    color: var(--mac-secondary);
  }
  html[data-theme] .care-filters .search-field:focus-within {
    border-color: var(--mac-accent);
    box-shadow: 0 0 0 3px var(--mac-accent-soft);
  }
  html[data-theme]
    .care-filters
    .search-field
    > input:is(#care-signals-search, #care-passport-search):focus {
    box-shadow: none;
  }
  html[data-theme] .care-filters input[type='search']::-webkit-search-decoration {
    -webkit-appearance: none;
  }
  html[data-theme] .care-filters input[type='search']::-webkit-search-cancel-button {
    cursor: pointer;
  }
  html[data-theme] :is(.care-history-switch) {
    position: relative;
    border-radius: 999px;
    box-shadow: var(--glass-shadow);
  }
  html[data-theme] :is(.care-history-switch) > button {
    border-radius: 999px;
  }
  html[data-theme] :is(.care-history-switch) > button.active {
    box-shadow: var(--depth-control);
  }
  html[data-theme] .group-more > button {
    border-radius: 12px;
    box-shadow: var(--glass-shadow);
  }
  html[data-theme] .modal {
    border-radius: 20px;
    box-shadow:
      0 24px 72px rgb(0 0 0 / 0.22),
      inset 0 1px 0 var(--depth-highlight);
  }
  html[data-theme] .modal-head {
    box-shadow: inset 0 1px 0 var(--depth-highlight);
  }
  html[data-theme] #toast {
    border-radius: 15px;
    box-shadow: var(--glass-shadow);
  }
  @supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
    html[data-theme] .sidebar {
      background:
        linear-gradient(150deg, var(--depth-sheen), transparent 65%),
        color-mix(in srgb, var(--mac-sidebar) 91%, transparent);
      -webkit-backdrop-filter: blur(24px) saturate(1.08);
      backdrop-filter: blur(24px) saturate(1.08);
    }
    html[data-theme] .topbar {
      background: color-mix(in srgb, var(--mac-canvas) 88%, transparent);
      -webkit-backdrop-filter: blur(20px);
      backdrop-filter: blur(20px);
    }
    html[data-theme] :is(.topbar-right, .care-history-switch) {
      background:
        linear-gradient(160deg, var(--depth-sheen), transparent 65%),
        color-mix(in srgb, var(--mac-raised) 82%, transparent);
      -webkit-backdrop-filter: blur(18px) saturate(1.08);
      backdrop-filter: blur(18px) saturate(1.08);
    }
    html[data-theme] :is(.scope-controls, .care-filters) {
      background:
        linear-gradient(155deg, var(--depth-sheen), transparent 65%),
        color-mix(in srgb, var(--mac-surface) 94%, transparent);
      -webkit-backdrop-filter: blur(14px);
      backdrop-filter: blur(14px);
    }
    html[data-theme] .modal {
      background: color-mix(in srgb, var(--mac-surface) 96%, transparent);
      -webkit-backdrop-filter: blur(24px);
      backdrop-filter: blur(24px);
    }
    html[data-theme] .modal::backdrop {
      -webkit-backdrop-filter: blur(6px);
      backdrop-filter: blur(6px);
    }
  }
  @media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
    html[data-theme]
      :is(.topbar-right, .btn.primary, .nav-link.active, .care-history-switch)::before {
      content: '';
      position: absolute;
      pointer-events: none;
      inset: 0;
      border-radius: inherit;
      background: radial-gradient(
        140px circle at var(--glass-x, 50%) var(--glass-y, 0%),
        var(--glass-sheen),
        transparent 72%
      );
      opacity: 0;
      transition: opacity 0.18s ease;
    }
    html[data-theme]
      :is(.topbar-right, .btn.primary, .nav-link.active, .care-history-switch):hover::before {
      opacity: 0.7;
    }
  }
  @media (max-width: 1150px) {
    html[data-theme] {
      --workspace-sidebar: 224px;
    }
    html[data-theme] .topbar-right > .save-state > span {
      display: none;
    }
    html[data-theme] .topbar-right > .save-state {
      padding: 0;
    }
    html[data-theme] .topbar .topbar-right {
      gap: 6px;
    }
  }
  @media (max-width: 760px) {
    html[data-theme] .topbar {
      height: 64px;
      min-height: 64px;
      padding: 0 12px;
      gap: 9px;
    }
    html[data-theme] .sidebar-toggle {
      display: none;
    }
    html[data-theme] .sidebar-collapsed .sidebar {
      visibility: visible;
      pointer-events: auto;
    }
    html[data-theme] .sidebar-collapsed.menu-open .sidebar {
      transform: translateX(0);
    }
    html[data-theme] .topbar .breadcrumbs {
      flex: 1 1 auto;
    }
    html[data-theme] .topbar .topbar-right {
      gap: 4px;
      padding: 4px;
    }
    html[data-theme] .topbar-right :is(.theme-toggle, .account-button, .care-topbar-notice) {
      min-width: 32px;
      width: 32px;
      height: 32px;
      min-height: 32px;
    }
    html[data-theme] :is(.scope-controls, .care-filters) {
      padding: 16px;
      border-radius: 14px;
    }
    html[data-theme] .care-filters {
      gap: 13px;
    }
  }
  @media (prefers-reduced-transparency: reduce), (prefers-contrast: more), (forced-colors: active) {
    html[data-theme]
      :is(
        .sidebar,
        .topbar,
        .topbar-right,
        .scope-controls,
        .care-filters,
        .care-history-switch,
        .modal
      ) {
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
      background-image: none;
      box-shadow: none;
    }
    html[data-theme] .sidebar {
      background-color: var(--mac-sidebar);
    }
    html[data-theme] .topbar {
      background-color: var(--mac-canvas);
    }
    html[data-theme] :is(.topbar-right, .care-history-switch) {
      background-color: var(--mac-raised);
    }
    html[data-theme] :is(.scope-controls, .care-filters, .modal) {
      background-color: var(--mac-surface);
    }
    html[data-theme] .btn.primary::before,
    html[data-theme] .nav-link.active::before {
      display: none;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    html[data-theme] *,
    html[data-theme] *::before {
      transition: none;
    }
    html[data-theme] .btn:active {
      transform: none;
    }
  }
}
