/* Shared components: brand, buttons, form fields, alerts. */

/* ---- Brand ---- */

.logo-mark {
    display: block;
    width: 32px;
    height: 32px;
    flex: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
}

/* White tile carrying the Zencia logo. It stays white in the dark theme too:
   the logo's black strokes need a light background. The logo is the one
   place a colour other than black, white and grey appears. */
.brand__tile {
    display: grid;
    place-items: center;
    flex: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #ffffff;
}

.brand__logo {
    display: block;
    width: 26px;
    height: 26px;
}

.brand__name {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* ---- Buttons ---- */

.button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--control-height);
    padding: 0 20px;
    border: 1px solid var(--fg);
    border-radius: var(--radius);
    background: var(--fg);
    color: var(--bg);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.05s ease, background-color 0.15s ease;
}

.button:hover {
    opacity: 0.86;
}

.button:active {
    transform: translateY(1px);
}

.button:disabled {
    cursor: default;
    opacity: 0.6;
}

.button--block {
    width: 100%;
}

.button--outline {
    background: transparent;
    color: var(--fg);
    border-color: var(--border);
}

.button--outline:hover {
    opacity: 1;
    background: var(--subtle);
    border-color: var(--border-hover);
}

.button__spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.button.is-loading .button__spinner {
    display: block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--fg);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover {
    background: var(--subtle);
    border-color: var(--border-hover);
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

.theme-toggle__sun,
:root[data-theme="dark"] .theme-toggle__moon {
    display: none;
}

:root[data-theme="dark"] .theme-toggle__sun {
    display: block;
}

/* Switching theme: the new theme spreads out in a circle from the switch
   (theme.js draws the circle). The browser's own cross-fade is turned off so
   the edge of the circle stays sharp. */
:root.theme-switching::view-transition-old(root),
:root.theme-switching::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

/* ---- Forms ---- */

.form {
    display: grid;
    gap: 18px;
}

.field {
    display: grid;
    gap: 7px;
}

.field__label {
    font-size: 13px;
    font-weight: 500;
}

.input {
    width: 100%;
    height: var(--control-height);
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    font-size: 15px;
    transition: border-color 0.15s ease;
}

.input::placeholder {
    color: var(--fg-muted);
    opacity: 0.75;
}

.input:hover {
    border-color: var(--border-hover);
}

/* One clean 2px ring instead of a border plus a separate outline */
.input:focus-visible {
    border-color: var(--fg);
    outline: 2px solid var(--fg);
    outline-offset: -1px;
}

/* Keep browser autofill in the black-and-white palette. */
.input:-webkit-autofill,
.input:-webkit-autofill:hover,
.input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--fg);
    box-shadow: 0 0 0 1000px var(--subtle) inset;
    caret-color: var(--fg);
}

.input-group {
    position: relative;
}

.input-group .input {
    padding-right: 68px;
}

.input-group__action {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    height: 32px;
    padding: 0 10px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--fg-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.input-group__action:hover {
    background: var(--subtle);
    color: var(--fg);
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    width: fit-content;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}

.checkbox__input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.checkbox__box {
    position: relative;
    flex: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border-hover);
    border-radius: 5px;
    background: var(--surface);
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.checkbox__box::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 1.5px;
    width: 5px;
    height: 9px;
    border: solid var(--bg);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
}

.checkbox:hover .checkbox__box {
    border-color: var(--fg);
}

.checkbox__input:checked + .checkbox__box {
    background: var(--fg);
    border-color: var(--fg);
}

.checkbox__input:checked + .checkbox__box::after {
    opacity: 1;
}

.checkbox__input:focus-visible + .checkbox__box {
    outline: 2px solid var(--fg);
    outline-offset: 2px;
}

/* ---- Alert ---- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--fg);
    border-radius: var(--radius);
    background: var(--subtle);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.45;
}

.alert__icon {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: 1px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }

    .button__spinner {
        animation-duration: 1.6s;
    }
}

/* ---- Icons and avatars ---- */

.icon {
    display: block;
    flex: none;
    width: 18px;
    height: 18px;
}

.icon-button--plain {
    border-color: transparent;
    color: var(--fg-muted);
}

.icon-button--plain:hover {
    color: var(--fg);
}

.avatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--fg);
    color: var(--bg);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* A profile photo in place of the initials */
.avatar img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar--xl {
    width: 88px;
    height: 88px;
    font-size: 28px;
}

/* ---- Stat card ---- */

.stat {
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.stat__label {
    color: var(--fg-muted);
    font-size: 13px;
    font-weight: 500;
}

.stat__value {
    margin-top: 8px;
    font-size: 30px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.stat__hint {
    margin-top: 6px;
    color: var(--fg-muted);
    font-size: 12.5px;
}

/* ---- Panel ---- */

.panel {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
}

.panel__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.panel__title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel__sub {
    margin-top: 2px;
    color: var(--fg-muted);
    font-size: 13px;
}

.panel__body {
    padding: 20px;
}

.panel__note {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    color: var(--fg-muted);
    font-size: 13px;
}

/* ---- Rows inside a panel ---- */

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 10px 20px;
}

.row + .row {
    border-top: 1px solid var(--border);
}

.row__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--subtle);
}

.row__main {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 500;
}

.row__title,
.row__meta,
.row__amount {
    display: block;
}

.row__link {
    color: inherit;
    text-decoration: none;
}

.row__link:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* A question from UI.confirm can list several lines. */
[data-confirm-message] {
    white-space: pre-line;
}

.row__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row__meta {
    color: var(--fg-muted);
    font-size: 12.5px;
    font-weight: 400;
}

.row__end {
    flex: none;
    text-align: right;
}

.row__amount {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---- Badge ---- */

.badge {
    display: inline-grid;
    place-items: center;
    min-width: 26px;
    height: 24px;
    padding: 0 8px;
    border: 1px solid var(--fg);
    border-radius: 999px;
    background: var(--fg);
    color: var(--bg);
    font-size: 12.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.badge--muted {
    border-color: var(--border);
    background: transparent;
    color: var(--fg-muted);
}

/* ---- Empty / unavailable state ---- */

.empty {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--fg-muted);
    font-size: 14px;
}

/* ---- Small utilities ---- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---- Medium controls (toolbars, dialogs) ---- */

.button--md {
    height: 40px;
    padding: 0 16px;
    font-size: 14px;
}

/* Small button, for rows */
.button--sm {
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
}

.button .icon {
    width: 16px;
    height: 16px;
}

a.button,
a.menu__item {
    text-decoration: none;
}

.input--md {
    height: 40px;
    font-size: 14px;
}

.select {
    width: 100%;
    height: var(--control-height);
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: 15px;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.select:hover {
    border-color: var(--border-hover);
}

.select:focus-visible {
    border-color: var(--fg);
    outline: 2px solid var(--fg);
    outline-offset: -1px;
}

.select:disabled {
    cursor: default;
    opacity: 0.55;
}

.select--sm {
    width: auto;
    min-width: 128px;
    height: 34px;
    border-radius: 8px;
    font-size: 14px;
}

.field-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.field__optional {
    margin-left: 4px;
    color: var(--fg-muted);
    font-weight: 400;
}

.search {
    position: relative;
    display: block;
}

.search .icon {
    position: absolute;
    top: 50%;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--fg-muted);
    transform: translateY(-50%);
    pointer-events: none;
}

.search .input {
    padding-left: 36px;
}

.copy-field {
    display: flex;
    gap: 8px;
}

.copy-field__value {
    flex: 1;
    min-width: 0;
    height: 40px;
    background: var(--subtle);
    font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 15px;
    letter-spacing: 0.04em;
}

/* ---- Segmented filter ---- */

.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius);
    background: var(--subtle);
}

.segmented button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--fg-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.segmented button:hover {
    color: var(--fg);
}

.segmented button[aria-pressed="true"] {
    background: var(--bg);
    color: var(--fg);
    box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.segmented button span {
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

/* ---- Tag (status label) ---- */

.tag {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 9px;
    border: 1px solid var(--border-hover);
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.tag--active {
    border-color: var(--border);
}

.tag--grace {
    border-color: var(--border-hover);
    background: var(--subtle);
}

.tag--locked {
    border-color: var(--fg);
    background: var(--fg);
    color: var(--bg);
}

.tag--quiet {
    height: 20px;
    padding: 0 7px;
    border-color: var(--border);
    color: var(--fg-muted);
    font-size: 11.5px;
    font-weight: 500;
}

/* Something that still needs doing */
.tag--solid {
    height: 20px;
    padding: 0 7px;
    border-color: var(--fg);
    background: var(--fg);
    color: var(--bg);
    font-size: 11.5px;
    font-weight: 600;
}

/* ---- Progress bar (a <progress> element) ---- */

.meter {
    display: block;
    width: 100%;
    height: 6px;
    border: 0;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
    -webkit-appearance: none;
    appearance: none;
}

.meter::-webkit-progress-bar {
    background: var(--border);
}

.meter::-webkit-progress-value {
    border-radius: 999px;
    background: var(--fg);
}

.meter::-moz-progress-bar {
    border-radius: 999px;
    background: var(--fg);
}

/* ---- Note above a list ---- */

.notice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
}

.notice__more {
    margin-top: 2px;
    color: var(--fg-muted);
}

/* ---- Search and filter bar above a table ---- */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
}

.toolbar .search {
    flex: 1 1 260px;
    max-width: 380px;
}

/* ---- A person: avatar, name and email ---- */

.person {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.person__text {
    min-width: 0;
}

.person__name {
    font-weight: 600;
}

.person__email {
    color: var(--fg-muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.avatar--soft {
    border: 1px solid var(--border);
    background: var(--subtle);
    color: var(--fg);
}

/* ---- Table ---- */

.panel--table {
    overflow: visible;   /* row menus must be able to open past the panel edge */
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    padding: 11px 16px;
    color: var(--fg-muted);
    font-size: 12.5px;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

.table-empty {
    padding: 36px 20px;
    color: var(--fg-muted);
    font-size: 14px;
    text-align: center;
}

/* ---- Dropdown menu (a <details> element) ---- */

.menu {
    position: relative;
    display: inline-block;
}

.menu > summary {
    list-style: none;
}

.menu > summary::-webkit-details-marker {
    display: none;
}

.menu[open] > summary {
    background: var(--subtle);
    color: var(--fg);
}

.menu__list {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 15;
    min-width: 200px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.14);
    text-align: left;
}

.menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--fg);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.menu__item:hover {
    background: var(--subtle);
}

.menu__item .icon {
    width: 16px;
    height: 16px;
}

.menu__sep {
    height: 1px;
    margin: 6px 0;
    background: var(--border);
}

/* ---- Dialog ---- */

.dialog {
    width: min(460px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--fg);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
    overflow-y: auto;
}

.dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
}

.dialog__head {
    padding: 22px 24px 0;
}

.dialog__title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.dialog__sub {
    margin-top: 6px;
    color: var(--fg-muted);
    font-size: 14px;
}

.dialog__body {
    display: grid;
    gap: 16px;
    padding: 20px 24px 0;
}

.dialog__note {
    color: var(--fg-muted);
    font-size: 13px;
}

.dialog__foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 22px 24px 24px;
}

/* ---- Toast ---- */

.toast-region {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 60;
    display: grid;
    gap: 8px;
    justify-items: center;
    width: max-content;
    max-width: calc(100vw - 32px);
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius);
    background: var(--fg);
    color: var(--bg);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: toast-in 0.2s ease;
    transition: opacity 0.3s ease;
}

.toast.is-leaving {
    opacity: 0;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

@media (max-width: 520px) {
    .field-row {
        grid-template-columns: minmax(0, 1fr);
    }
}
