/* The Astrona component system (DESIGN.md "Components"). The classes here are the API of
   app/views/ui/components.cr; pages do not restyle them. Tokens live in app.css :root. */

.ui-icon { display: block; width: 16px; height: 16px; flex: 0 0 16px; }
.ui-link { color: var(--accent); font-weight: 600; text-decoration: underline; }
.ui-link:hover { color: var(--accent-dark); }
[hidden] { display: none !important; }

/* ---- badges: text on its own tint, one pair per tone */
.badge.neutral { background: var(--grey-100); color: var(--muted); }
.badge.success { background: var(--success-100); color: var(--success); }
.badge.warning { background: var(--warning-100); color: var(--warning); }
.badge.error { background: var(--error-100); color: var(--error); }
.badge.info { background: var(--info-100); color: var(--info); }
.badge.brand { background: var(--soft); color: var(--accent-dark); }

/* ---- fields */
.ui-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ui-label { color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1.4; }
.ui-help { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.46; }
.ui-field :is(select, input[type=month], input[type=date], input[type=search], input[type=text], input[type=number]) {
  width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border: 1px solid var(--grey-300); border-radius: 8px;
  background: var(--paper); color: var(--ink); font-size: 15px; box-shadow: none;
}
.ui-field :is(select, input, .ui-picker > summary):focus-visible { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px #235c4c66; }
.ui-field [aria-invalid=true] { border-color: var(--error) !important; }

.ui-locked { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 10px 12px; border-radius: 8px; background: var(--grey-100); color: var(--ink); font-size: 15px; }
.ui-locked-icon { color: var(--muted); }

/* ---- segmented control (links or radios) */
.ui-segmented { display: inline-flex; max-width: 100%; gap: 4px; padding: 4px; border-radius: 8px; background: var(--grey-100); overflow-x: auto; }
.ui-segmented > a { flex-shrink: 0; }
.ui-segmented > a, .ui-segmented > label > span { display: flex; align-items: center; justify-content: center; min-height: 36px; padding: 6px 14px; border-radius: 6px; color: var(--muted); font-size: 14px; font-weight: 500; white-space: nowrap; }
.ui-segmented > a:hover { color: var(--ink); text-decoration: none; }
.ui-segmented > a.selected, .ui-segmented > label input:checked + span { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px #253d3814; }
.ui-segmented > label { position: relative; display: block; flex: 1; cursor: pointer; }
.ui-segmented > label input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.ui-segmented > label input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 0; }
.ui-field > .ui-segmented { display: flex; }

/* ---- underline tabs */
.ui-tabs { display: flex; gap: 32px; margin: 0 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.ui-tabs a { flex-shrink: 0; margin-bottom: -1px; padding: 12px 0; border-bottom: 2px solid transparent; color: var(--muted); font-size: 15px; font-weight: 500; white-space: nowrap; }
.ui-tabs a:hover { color: var(--ink); text-decoration: none; }
.ui-tabs a.selected { border-bottom-color: var(--accent); color: var(--ink); }

/* ---- switch: ink when on, because green is for actions */
.ui-switch { position: relative; display: inline-flex; flex-direction: row; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); font-size: 15px; font-weight: 400; cursor: pointer; }
.ui-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.ui-switch-track { position: relative; flex: 0 0 40px; width: 40px; height: 24px; border-radius: 9999px; background: var(--grey-300); transition: background .12s; }
.ui-switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #253d3833; transition: transform .12s; }
.ui-switch input:checked + .ui-switch-track { background: var(--ink); }
.ui-switch input:checked + .ui-switch-track::after { transform: translateX(16px); }
.ui-switch input:focus-visible + .ui-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- a picker that looks like a select and opens a list of checkboxes */
.ui-picker { position: relative; }
.ui-picker > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 10px 12px; border: 1px solid var(--grey-300); border-radius: 8px; background: var(--paper); color: var(--ink); font-size: 15px; list-style: none; cursor: pointer; }
.ui-picker > summary::-webkit-details-marker { display: none; }
.ui-picker > summary::before, .ui-picker > summary::after { content: none; }
.ui-picker-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-picker-caret { display: inline-flex; }
.ui-picker[open] .ui-picker-caret { transform: rotate(180deg); }
.ui-picker-options { position: absolute; z-index: 20; top: calc(100% + 4px); inset-inline-start: 0; min-width: 100%; max-height: 280px; margin: 0; padding: 10px 12px; display: grid; gap: 4px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: var(--shadow-raised); }
.ui-check { display: flex; flex-direction: row; align-items: center; gap: 10px; min-height: 36px; font-size: 15px; font-weight: 400; color: var(--ink); cursor: pointer; }
.ui-check input { flex: 0 0 auto; margin: 0; }

/* ---- messages: text on its own tint, role alert only for errors */
.ui-alert { display: flex; align-items: flex-start; gap: 12px; margin: 16px 0 0; padding: 12px 16px; border-radius: 8px; font-size: 15px; line-height: 1.45; }
.ui-alert.success { background: var(--success-100); color: var(--success); }
.ui-alert.error { background: var(--error-100); color: var(--error); }
.ui-alert.warning { background: var(--warning-100); color: var(--warning); }
.ui-alert.info { background: var(--info-100); color: var(--info); }
.ui-alert-icon { display: inline-flex; padding-top: 2px; }
.ui-alert-icon .ui-icon { width: 18px; height: 18px; flex-basis: 18px; }
.ui-alert-text { flex: 1; min-width: 0; }
.ui-alert-text strong { display: block; font-weight: 650; }
.ui-alert-text p { margin: 2px 0 0; color: inherit; }
.ui-alert-text > :is(p, strong) + * { margin-top: 8px; }
.ui-alert-links { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-left: auto; font-weight: 600; }
.ui-alert-links a { color: inherit; text-decoration: underline; }

/* ---- figures: the number is the hero */
.ui-figure { padding: 16px 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); min-width: 0; }
.ui-figure.is-emphasis { border-color: var(--accent); background: var(--soft); }
.ui-figure-label { margin: 0 0 2px; color: var(--ink); font-size: 14px; font-weight: 600; }
.ui-figure-amount { display: block; font-size: clamp(28px, 2.4vw, 36px); font-weight: 500; line-height: 1.15; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ui-figure-detail, .ui-figure-note { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.46; }
.ui-figure.is-emphasis .ui-figure-detail { color: var(--ink); font-size: 14px; }

/* ---- tables: header on primary-50, rules not fills, amounts right-aligned in tabular numerals */
.ui-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.5; }
.ui-table :is(th, td) { padding: 13px 16px; font-weight: 400; text-align: left; font-variant-numeric: tabular-nums; border-bottom: 0; }
.ui-table .number { text-align: right; white-space: nowrap; }
.ui-table thead th { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--primary-50); color: var(--ink); font-size: 14px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.ui-table tbody th { background: transparent; color: var(--ink); font-size: 14px; letter-spacing: 0; text-transform: none; }
.ui-table tbody tr :is(th, td) { border-top: 1px solid var(--line); }
.ui-table tbody tr:first-child :is(th, td) { border-top: 0; }
.ui-table tbody tr:hover { background: transparent; }

/* ---- buttons: ink and ghost join primary, secondary (button-quiet) and danger */
.button-ink { background: var(--ink); border-color: var(--ink); color: #fff; }
.button-ink:hover { background: var(--muted); border-color: var(--muted); color: #fff; }
.button-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.button-ghost:hover { background: var(--grey-100); color: var(--ink); }
.button-danger-solid { background: var(--error); border-color: var(--error); color: #fff; }
.button-danger { color: var(--error); border-color: #dfbbae; }
.button-danger:hover { background: var(--error-100); border-color: var(--error); color: var(--error); }
.button-danger-solid:hover { background: #702e24; border-color: #702e24; color: #fff; }

@media (max-width: 640px) {
  .ui-tabs { gap: 20px; }
  .ui-alert { padding: 12px; }
  .ui-picker-options { position: static; margin-top: 4px; box-shadow: none; }
}
