/*
 * Everything that is not a Pico default. Kept deliberately small: badges, flash messages, a
 * credentials grid and a handful of layout helpers. No page-specific rules — if a page needs
 * spacing, it uses one of the classes below.
 */

/* --- page skeleton ------------------------------------------------------ */

/* Every page: one h1, optional actions on the same row, then content. */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-head h1 {
    margin: 0;
}

/* Database names are identifiers; monospace without the <code> chip background. */
h1.mono {
    font-family: var(--pico-font-family-monospace);
    font-size: 1.75rem;
    word-break: break-all;
}

.page-head .page-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.page-head .page-actions a[role="button"],
.page-head .page-actions button {
    margin: 0;
    width: auto;
}

/* Section headings inside a page. */
main h2 {
    margin-top: 2.5rem;
    font-size: 1.25rem;
}

/* --- login page --------------------------------------------------------- */

.login-page {
    max-width: 26rem;
    margin-top: 6rem;
    text-align: center;
}

.login-page .button-row {
    justify-content: center;
}

/* --- header / nav ------------------------------------------------------- */

.user-chip {
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    white-space: nowrap;
}

.user-chip code {
    font-size: 0.75rem;
}

nav a[aria-current="page"] {
    font-weight: 600;
    text-decoration: underline;
}

.inline-form {
    display: inline;
    margin: 0;
}

.mode-switch {
    display: inline-flex;
    gap: 0.25rem;
}

.mode-switch button[disabled] {
    opacity: 1;
    cursor: default;
}

button.tiny,
a[role="button"].tiny {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    margin: 0;
    width: auto;
    /* Wide enough for the transient "Copied"/"Failed" labels, so rows don't shift. */
    min-width: 4.6rem;
}

/* --- buttons ------------------------------------------------------------ */

/* Horizontal group: page actions, form actions, dialog actions, credential buttons. */
.button-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.button-row button,
.button-row a[role="button"] {
    margin: 0;
    width: auto;
}

/* A form's trailing button row needs air before whatever section follows it. */
form > .button-row:last-child {
    margin-bottom: 2rem;
}

/* Buttons inside a table cell — kept on one line so rows stay a uniform height. */
.row-actions {
    display: flex;
    gap: 0.3rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.row-actions form {
    margin: 0;
}

/* --- badges ------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    border: 1px solid var(--pico-muted-border-color);
    color: var(--pico-muted-color);
    vertical-align: middle;
}

.badge-mysql {
    border-color: #a97400;
    color: #a97400;
}

.badge-postgres {
    border-color: #3d6da5;
    color: #3d6da5;
}

.badge-ok {
    border-color: #2e8b57;
    color: #2e8b57;
}

.badge-warn {
    border-color: #c76a00;
    color: #c76a00;
}

.badge-info {
    border-color: #3d6da5;
    color: #3d6da5;
}

.badge-muted {
    border-color: var(--pico-muted-border-color);
    color: var(--pico-muted-color);
}

/* --- flash messages and banners ----------------------------------------- */

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--pico-border-radius);
    margin-bottom: 1.25rem;
    border-left: 4px solid;
}

.flash-success {
    border-color: #2e8b57;
    background: rgba(46, 139, 87, 0.08);
}

.flash-warning {
    border-color: #c76a00;
    background: rgba(199, 106, 0, 0.08);
}

.flash-error {
    border-color: #c0392b;
    background: rgba(192, 57, 43, 0.08);
}

.banner {
    padding: 0.9rem 1.1rem;
    border-radius: var(--pico-border-radius);
    border-left: 4px solid #c76a00;
    background: rgba(199, 106, 0, 0.08);
    margin-bottom: 1.5rem;
}

.banner > :last-child {
    margin-bottom: 0;
}

/* --- credentials panel -------------------------------------------------- */

.cred-grid {
    display: grid;
    grid-template-columns: minmax(7rem, max-content) 1fr auto;
    gap: 0.4rem 0.75rem;
    align-items: center;
}

.cred-grid > label {
    margin: 0;
    color: var(--pico-muted-color);
    font-size: 0.85rem;
}

.cred-grid input[readonly] {
    margin: 0;
    font-family: var(--pico-font-family-monospace);
    font-size: 0.85rem;
}

/* Password field with the reveal toggle inside the input. */
.input-icon-wrap {
    position: relative;
}

.input-icon-wrap input {
    padding-right: 2.5rem;
}

.reveal-toggle {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    width: auto;
    margin: 0;
    padding: 0.25rem 0.35rem;
    border: none;
    background: transparent;
    box-shadow: none;
    line-height: 0;
    /* Concrete colors on purpose: Pico's button rules redefine --pico-color per
       state (white on hover), which would make the icon vanish. Light theme only. */
    color: #646b79;
}

.reveal-toggle:hover,
.reveal-toggle:focus,
.reveal-toggle:active {
    border: none;
    background: transparent;
    box-shadow: none;
    color: #2a2f3a;
}

.reveal-toggle svg {
    width: 1.1rem;
    height: 1.1rem;
}

.reveal-toggle .icon-eye-off,
.reveal-toggle.is-revealed .icon-eye {
    display: none;
}

.reveal-toggle.is-revealed .icon-eye-off {
    display: inline;
}

.reveal-toggle.failed {
    color: #c62828;
}

@media (max-width: 720px) {
    .cred-grid {
        grid-template-columns: 1fr;
    }

    .cred-grid .button-row {
        margin-bottom: 0.75rem;
    }
}

/* --- tables ------------------------------------------------------------- */

table {
    font-size: 0.9rem;
}

/* Counts and sizes read better right-aligned; everything else stays left. */
th.num,
td.num {
    text-align: right;
}

.muted {
    color: var(--pico-muted-color);
}

.warn-text {
    color: #c76a00;
}

.nowrap {
    white-space: nowrap;
}

/* --- forms -------------------------------------------------------------- */

/* Inline row of fields: filter bars and one-line forms. */
.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.form-row label {
    margin: 0;
    font-size: 0.85rem;
}

.form-row select,
.form-row input,
.form-row button,
.form-row a[role="button"] {
    margin: 0;
    width: auto;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
}

@media (max-width: 720px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.field-error {
    color: var(--pico-del-color, #c0392b);
    font-size: 0.8rem;
    display: block;
    margin-top: -0.6rem;
    margin-bottom: 0.75rem;
}

fieldset.engines label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-right: 1.25rem;
}

fieldset.engines small {
    display: block;
    margin-top: 0.25rem;
}

/* --- dialogs ------------------------------------------------------------ */

dialog article {
    max-width: 32rem;
}

dialog .button-row {
    justify-content: flex-start;
}
