/* Our own form controls (ui.js). The browser's element stays underneath as the source of truth;
   these rules hide its system UI and draw ours. Motion follows motion.css's tokens. */

/* The native element a drawn control stands in for: still in the form and the page, never seen. */
.ui-native { position:absolute !important; inset:0; width:100% !important; height:100% !important; margin:0; opacity:0; pointer-events:none; }

/* Dropdowns */
.cs,.tags,.color-field,.dp { position:relative; display:block; min-width:0; font-weight:400; }
.cs-native { position:absolute; inset:0; width:100%; height:100%; opacity:0; pointer-events:none; }
.cs-trigger,.dp-trigger { display:flex; align-items:center; gap:10px; width:100%; min-height:46px; padding:11px 13px; background:#fff; color:var(--ink); border:1px solid #cbd8d3; border-radius:7px; font:inherit; font-weight:500; text-align:left; cursor:pointer; transition:border-color 150ms ease,box-shadow 150ms ease,transform 160ms var(--ease-out); }
.cs-trigger:hover,.dp-trigger:hover { filter:none; border-color:#a9bfb6; }
.cs-trigger:active,.dp-trigger:active { transform:scale(0.99); }
.cs-value,.dp-value { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cs-chevron { width:16px; height:16px; color:var(--muted); transition:transform 200ms var(--ease-out); }
.cs.is-open .cs-chevron,.dp:has(.dp-trigger[aria-expanded="true"]) .cs-chevron { transform:rotate(180deg); }
.cs-native:focus-visible+.cs-trigger,.cs.is-open .cs-trigger,.ui-native:focus-visible+.dp-trigger,.ui-native:focus-visible~.color-swatch { outline:3px solid #9ecdb9; outline-offset:2px; }
.cs.is-disabled .cs-trigger,.dp-trigger:disabled { opacity:.55; cursor:not-allowed; }
.discovery .filters .cs-trigger { border-radius:24px; font-size:13px; padding:11px 14px; min-height:44px; }
.organization-switch .cs-trigger { font-size:12px; min-height:40px; padding:9px 12px; }

/* Popovers (dropdown lists and pickers) sit on <body> and open from their field. */
.ui-pop { position:fixed; z-index:60; background:#fff; border:1px solid var(--line); border-radius:12px; box-shadow:0 2px 4px #103c3210,0 18px 40px -12px #103c3238; opacity:0; transform:translateY(-4px) scale(0.98); transform-origin:top center; visibility:hidden; pointer-events:none; transition:opacity 160ms var(--ease-out),transform 160ms var(--ease-out),visibility 0s linear 160ms; }
.ui-pop.is-up { transform-origin:bottom center; transform:translateY(4px) scale(0.98); }
.ui-pop.is-open { opacity:1; transform:none; visibility:visible; pointer-events:auto; transition-delay:0s; }
.cs-list { max-height:300px; overflow:auto; padding:6px; outline:none; overscroll-behavior:contain; }
.cs-option { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 12px; border-radius:8px; font-size:14px; color:var(--ink); cursor:pointer; }
.cs-option.is-active { background:var(--tint); }
.cs-option[aria-selected="true"] { font-weight:600; color:var(--accent); }
.cs-option[aria-disabled="true"] { opacity:.45; cursor:not-allowed; }
.cs-check { width:16px; height:16px; opacity:0; color:var(--accent); }
.cs-option[aria-selected="true"] .cs-check { opacity:1; }

/* Checkboxes and radio buttons */
input[type="checkbox"],input[type="radio"] { appearance:none; -webkit-appearance:none; width:18px; height:18px; padding:0; flex-shrink:0; margin:0; display:inline-grid; place-content:center; background:#fff; border:1.5px solid #b3c6bd; border-radius:5px; cursor:pointer; transition:background-color 150ms ease,border-color 150ms ease,transform 160ms var(--ease-out); }
input[type="radio"] { border-radius:50%; }
input[type="checkbox"]::after { content:''; width:10px; height:10px; background:#fff; clip-path:polygon(14% 44%,0 65%,50% 100%,100% 16%,80% 0%,43% 62%); transform:scale(0); transition:transform 180ms var(--ease-out); }
input[type="radio"]::after { content:''; width:8px; height:8px; border-radius:50%; background:#fff; transform:scale(0); transition:transform 180ms var(--ease-out); }
input[type="checkbox"]:checked,input[type="radio"]:checked { background:var(--accent); border-color:var(--accent); }
input[type="checkbox"]:checked::after,input[type="radio"]:checked::after { transform:scale(1); }
input[type="checkbox"]:active,input[type="radio"]:active { transform:scale(0.92); }
input[type="checkbox"]:focus-visible,input[type="radio"]:focus-visible { outline:3px solid #9ecdb9; outline-offset:2px; }
input[type="checkbox"]:disabled,input[type="radio"]:disabled { opacity:.5; cursor:not-allowed; }
label.check input { margin-top:3px; }

/* Numbers without spinners, searches without the system clear button, our own file button. */
input[type="number"] { -moz-appearance:textfield; appearance:textfield; }
input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button { -webkit-appearance:none; margin:0; }
input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration { -webkit-appearance:none; appearance:none; }
/* The whole pill is the button: one cursor, one hover, one press, one focus ring. The inner button is only its face. */
.file-field { position:relative; display:flex; align-items:center; gap:12px; min-height:46px; padding:6px; border:1px dashed #b9cbc2; border-radius:10px; background:#fff; font-weight:400; cursor:pointer; transition:border-color 160ms ease,background-color 160ms ease,transform 160ms var(--ease-out); }
.file-field:active { transform:scale(0.99); }
.file-field.has-file { border-style:solid; }
.file-button { padding:9px 16px; font-size:13px; pointer-events:none; }
.file-name { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:13px; color:var(--muted); }
.file-field.has-file .file-name { color:var(--ink); font-weight:500; }
.file-field:has(.ui-native:focus-visible) { outline:3px solid #9ecdb9; outline-offset:2px; }
.file-field:has(.ui-native:disabled) { cursor:not-allowed; opacity:.6; }
.file-field:has(.ui-native:disabled):active { transform:none; }
@media (hover:hover) and (pointer:fine) { .file-field:not(:has(.ui-native:disabled)):hover { border-color:var(--accent); background:var(--tint); } }

/* Disclosures: our chevron instead of the system triangle. */
details>summary { list-style:none; display:flex; align-items:center; gap:8px; }
details>summary::-webkit-details-marker { display:none; }
details>summary::before { content:''; width:12px; height:12px; flex-shrink:0; background:currentColor; -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E") center/contain no-repeat; mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E") center/contain no-repeat; transition:transform 200ms var(--ease-out); }
details[open]>summary::before { transform:rotate(90deg); }

/* Tags */
.tags { display:flex; flex-wrap:wrap; align-items:center; gap:6px; min-height:46px; padding:6px 8px; background:#fff; border:1px solid #cbd8d3; border-radius:7px; cursor:text; transition:border-color 150ms ease; }
.tags:focus-within { outline:3px solid #9ecdb9; outline-offset:2px; }
.tags-list { display:contents; }
.tag { display:inline-flex; align-items:center; gap:4px; padding:4px 4px 4px 10px; border-radius:16px; background:var(--tint); color:#244b3b; font-size:13px; font-weight:500; animation:tag-in 220ms var(--ease-out); }
.tag button { display:grid; place-items:center; width:20px; height:20px; padding:0; border-radius:50%; background:transparent; color:#4c6b5b; }
.tag button:hover { background:#d7e8db; filter:none; }
.tag button .icon { width:12px; height:12px; }
.tags-entry { flex:1; min-width:120px; border:0 !important; outline:none !important; padding:6px 4px !important; background:transparent !important; }
@keyframes tag-in { from { opacity:0; transform:scale(0.9); } }

/* Colours */
.color-field { display:flex; align-items:center; gap:8px; }
.color-swatch { width:46px; height:46px; flex-shrink:0; padding:0; border-radius:10px; border:1px solid #cbd8d3; box-shadow:inset 0 0 0 3px #fff; }
.color-swatch:hover { filter:none; }
.color-hex { flex:1; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; text-transform:uppercase; letter-spacing:.5px; }
.color-pop { padding:12px; }
.color-grid { display:grid; grid-template-columns:repeat(4,36px); gap:8px; }
.color-grid button { width:36px; height:36px; padding:0; border-radius:9px; border:1px solid #0000001a; }
.color-grid button[aria-pressed="true"] { box-shadow:0 0 0 2px #fff,0 0 0 4px var(--accent); }

/* Dates */
.dp-trigger .icon:first-child { width:17px; height:17px; color:var(--accent); }
.dp-trigger.is-empty .dp-value { color:#8a9a94; }
.dp-pop { padding:14px; }
.dp-body { display:flex; gap:14px; }
.dp-head { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:10px; }
.dp-head b { font:700 15px 'Manrope',sans-serif; }
.dp-nav { display:grid; place-items:center; width:34px; height:34px; padding:0; border-radius:9px; background:transparent; color:var(--ink); }
.dp-nav:hover { background:var(--tint); filter:none; }
.dp-week,.dp-days { display:grid; grid-template-columns:repeat(7,38px); gap:2px; }
.dp-week span { text-align:center; font-size:11px; font-weight:600; color:var(--muted); padding:4px 0; }
.dp-days button { width:38px; height:38px; padding:0; border-radius:9px; background:transparent; color:var(--ink); font-weight:500; font-size:14px; }
.dp-days button:hover:not([disabled]) { background:var(--tint); filter:none; }
.dp-days button.is-today { box-shadow:inset 0 0 0 1px var(--accent); }
.dp-days button[aria-pressed="true"] { background:var(--accent); color:#fff; }
.dp-days button[disabled],.dp-months button[disabled] { opacity:.3; cursor:not-allowed; }
.dp-times { display:flex; flex-direction:column; gap:2px; width:104px; max-height:286px; overflow:auto; padding-left:12px; border-left:1px solid var(--line); overscroll-behavior:contain; }
.dp-clock { width:16px; height:16px; color:var(--muted); margin:4px auto 8px; flex-shrink:0; }
.dp-times button { padding:8px; border-radius:8px; background:transparent; color:var(--ink); font-size:13px; font-weight:500; }
.dp-times button:hover { background:var(--tint); filter:none; }
.dp-times button[aria-pressed="true"] { background:var(--accent); color:#fff; }
.dp-months { display:grid; grid-template-columns:repeat(3,1fr); gap:6px; }
.dp-months button { padding:12px 8px; border-radius:9px; background:transparent; color:var(--ink); font-weight:500; }
.dp-months button:hover:not([disabled]) { background:var(--tint); filter:none; }
.dp-months button[aria-pressed="true"] { background:var(--accent); color:#fff; }
.dp-foot { display:flex; justify-content:flex-end; gap:8px; margin-top:12px; padding-top:12px; border-top:1px solid var(--line); }
.dp-done { padding:9px 18px; }
@media (max-width:480px) {
  .dp-body { flex-direction:column; }
  .dp-times { width:auto; max-height:150px; flex-direction:row; flex-wrap:nowrap; overflow-x:auto; overflow-y:hidden; padding:10px 0 0; border-left:0; border-top:1px solid var(--line); }
  .dp-times button { flex-shrink:0; }
  .dp-clock { display:none; }
}

/* Our confirmation dialog */
.ui-dialog { width:min(440px,calc(100vw - 32px)); padding:26px; border:0; border-radius:18px; background:#fff; color:var(--ink); box-shadow:0 30px 80px -20px #103c3255; animation:dialog-in 220ms var(--ease-out); }
.ui-dialog::backdrop { background:#0c1f1a66; animation:backdrop-in 220ms ease; }
.ui-dialog p { margin:0 0 22px; font-size:16px; line-height:1.6; }
.ui-dialog-actions { display:flex; justify-content:flex-end; gap:10px; flex-wrap:wrap; }
.danger-solid { background:#b4362c; color:#fff; }
@keyframes dialog-in { from { opacity:0; transform:translateY(8px) scale(0.97); } }
@keyframes backdrop-in { from { opacity:0; } }

/* Validation: our message under the field. */
.field-error { display:flex; align-items:center; gap:6px; font-size:13px; font-weight:500; color:#9d352b; animation:rise 260ms var(--ease-out) both; }
[aria-invalid="true"],.tags:has([aria-invalid="true"]),.cs:has(.cs-native:invalid) .cs-trigger.is-touched { border-color:#d67a70 !important; }

@media (prefers-reduced-motion:reduce) {
  .ui-pop,.ui-pop.is-up { transform:none; }
  .tag,.field-error { animation:none; }
  .ui-dialog { animation-name:backdrop-in; }
}
