/* ════════════════════════════════════════════════════════════
   Shared UI components - the single source for everything that
   must look identical everywhere: dialogs, notification cards
   and the waiting animation.

   Loaded by both shells: the BroAdmin app (index.php, before
   style.css) and the broadmin.hu website (website.php's app_head,
   deployed there by tools/release.ps1). No rule here may be
   repeated in either shell's own CSS.

   Colours: BroAdmin design tokens with a literal fallback, so the
   website - which defines none of them - renders the same. The two
   token names the website DOES define with other values (--text,
   --gray) are written out as literals instead, or its dark theme
   would bleed into these components.
   ════════════════════════════════════════════════════════════ */

/* ── Dialogs (page.php CRUD forms, confirmDialog(), the cores' own pickers) ── */

dialog {
    position: fixed;
    background-color: rgba(0, 0, 0, 0.75);
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    box-sizing: border-box;
    z-index: 999;
}

/* lifts the browser's own dialog:modal size cap, which keeps the dark cover off the edges */
dialog:modal {
    max-width: 100%;
    max-height: 100%;
}

dialog .header {
    display: flex;
    justify-content: space-between;
    background: var(--bmxgreen, #B7E81F);
    color: var(--header, #424242);
    font-size: 18px;
    font-weight: bold;
    line-height: 40px;
    padding: 0px 20px;
    margin: -10px -10px 20px -10px;
    border-radius: 10px 10px 0 0;
}

dialog .close-button {
    font-family: sans-serif;
    font-size: 32px;
    color: var(--bmxgray, #76777B);
    cursor: pointer;
    margin-right: -10px
}

dialog .close-button:hover {
    color: var(--white, #FFFFFF);
}

/* The popup card itself: a CRUD dialog's form is one, and .popup-card is the same card
   for the popups whose body is not a form (the advert scheduler's block details, the AI
   generator's thinking card). Whatever sits on top of the dark cover is one of these. */
dialog form,
.popup-card {
    background: var(--bright, #EEEEEE);
    border: 2px solid var(--bmxgreen, #B7E81F);
    border-radius: 10px;
    padding: 10px;
    margin: 120px auto;
    max-width: 800px;
    color: #283338;
}

/* pageCfg.wide: true widens the popup for forms with many/wide fields (see page.php) */
dialog.wide-dialog form {
    max-width: calc(100% - 80px);
}

dialog form label {
    display: inline-block;
    width: 160px;
    margin-top: 2px;
    margin-right: 10px;
    font-weight: 500;
    color: #283338;
    text-align: right;
    vertical-align: top;
}

dialog form .custom-field-wrapper {
    display: inline-block;
    width: calc(100% - 180px);
}

/* Two fields rendered under one shared label (field.pairWith, e.g. segmentStart/segmentStop) */
dialog form .field-pair {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

dialog form .field-pair-separator {
    color: #283338;
}

dialog form .button-wrap {
    text-align: center;
    margin-top: 10px;
}

dialog form .form-field {
    min-height: 28px;
    margin-bottom: 2px;
}

dialog form input {
    display: inline-block;
    padding: 2px;
    margin-bottom: 5px;
    border: 1px solid var(--bright, #EEEEEE);
    border-radius: 4px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

dialog form input:focus {
    outline: none;
    border-color: var(--bmxgreen, #B7E81F);
    box-shadow: 0 0 0 2px rgba(183, 232, 31, 0.2);
}

dialog form input[type="text"],
dialog form input[type="email"],
dialog form input[type="password"],
dialog form input[type="file"] {
    padding: 2px 6px;
    width: calc(100% - 180px);
}

dialog form input[type="number"] {
    width: 100px;
}

dialog form input[type="date"] {
    width: 180px;
}

dialog form input[type="time"] {
    width: 140px;
}

dialog form input[type="datetime-local"] {
    width: 220px;
}

dialog form input[type="color"] {
    width: 50px;
    height: 28px;
    padding: 1px;
    cursor: pointer;
    vertical-align: middle;
}

dialog form select {
    width: calc(100% - 380px);
    padding: 2px 2px;
    border: 1px solid var(--bright, #EEEEEE);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    background-color: var(--white, #FFFFFF);
    color: #283338;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

dialog form textarea {
    width: calc(100% - 180px);
    resize: vertical;
    height: 100px;
    padding: 5px;
    border: 1px solid var(--bright, #EEEEEE);
    border-radius: 4px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

dialog form input[type="checkbox"] {
    width: auto;
    margin-left: 1px;
    transform: scale(1.2);
}

dialog form button {
    padding: 5px 12px;
    margin: 0 10px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    display: inline-block;
}

dialog form button[type="submit"] {
    background-color: var(--bmxgreen, #B7E81F);
    color: #283338;
}

dialog form button[type="submit"]:hover {
    background-color: var(--hover, #E6FF9A);
    transform: translateY(-1px);
}

dialog form button:not([type="submit"]) {
    background-color: #BBBBBB;
    color: #283338;
}

dialog form button:not([type="submit"]):hover {
    background-color: var(--bmxgray, #76777B);
    transform: translateY(-1px);
}

dialog form .required-asterisk {
    color: var(--error-text, #A95442);
    margin-right: 2px;
    font-weight: bold;
    cursor: help;
}

dialog .button-cancel {
    background: #BBBBBB;
    color: var(--white, #FFFFFF);
    border: none;
    padding: 6px 12px;
    cursor: pointer;
}

dialog .button-submit {
    background: var(--bmxgreen, #B7E81F);
    color: var(--white, #FFFFFF);
    border: none;
    padding: 6px 12px;
    cursor: pointer;
}

dialog .help-icon {
    font-size: 18px;
    color: var(--info, #2299FF);
    cursor: help;
    margin: 5px;
}

/* ── Fancy confirm dialog (confirmDialog() in script.js, replaces window.confirm) ── */

dialog.confirm-dialog form {
    max-width: 420px;
    margin: 160px auto;
    text-align: center;
    animation: notify-in 0.2s cubic-bezier(0.21, 1.02, 0.73, 1);
}

dialog.confirm-dialog .header-title-wrap {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

dialog.confirm-dialog .confirm-icon {
    font-size: 20px;
}

dialog.confirm-dialog .confirm-message {
    font-size: 16px;
    font-weight: 500;
    color: #283338;
    white-space: pre-line;
    margin: 20px 0;
}

dialog.confirm-dialog .button-wrap {
    margin: 24px 0 14px 0;
}

/* both buttons are type="submit" (so method="dialog" auto-closes on either),
   so this must out-specificity the generic "dialog form button[type=submit]"
   green rule to keep Cancel looking like a cancel button */
dialog.confirm-dialog form button.button-cancel {
    background: #BBBBBB;
    color: var(--white, #FFFFFF);
}

dialog.confirm-dialog form button.button-cancel:hover {
    background: var(--bmxgray, #76777B);
}

/* Article-link input of the AI News dialog (newsgenLinkDialog() in page.php), which borrows the
   confirm dialog's chrome but holds an input instead of a message. */
dialog.confirm-dialog .newsgen-link {
    width: 100%;
    text-align: left;
    font-size: 14px;
    font-weight: 400;
}

/* ── Notification stack (script.js showNotify / the website shell's own showNotify) ──
   Success/info cards auto-dismiss (the bottom bar counts down the remaining time, a
   click dismisses early); error cards stay until their OK button is clicked. */

#notify-stack {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 9000;
    width: min(680px, 90vw);
    pointer-events: none;
}

.notify {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    width: 100%;
    box-sizing: border-box;
    padding: 14px 20px;
    border-radius: 10px;
    color: var(--white, #FFFFFF);
    font-family: 'Asap', 'Segoe UI', sans-serif;
    font-size: 15px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    position: relative;
    overflow: hidden;
    animation: notify-in 0.3s cubic-bezier(0.21, 1.02, 0.73, 1);
}

.notify.notify-closing {
    animation: notify-out 0.25s ease-in forwards;
}

@keyframes notify-in {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes notify-out {
    to {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
}

.notify-success {
    background: linear-gradient(135deg, var(--success-text, #1E8449), var(--success, #27AE60));
    border: 1px solid var(--bmxgreen, #B7E81F);
    cursor: pointer;
}

.notify-info {
    background: var(--darkgray, #303030);
    border: 1px solid var(--bmxgray, #76777B);
    cursor: pointer;
}

.notify-error {
    background: linear-gradient(135deg, #8E2418, var(--danger, #C0392B));
    border: 1px solid var(--danger-accent, #E74C3C);
}

.notify-icon {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: bold;
}

.notify-body {
    flex: 1;
    min-width: 0;
    align-self: center;
}

.notify-message {
    font-weight: 600;
    overflow-wrap: break-word;
}

/* per-record failure list inside an error card */
.notify-details {
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: normal;
    max-height: 40vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.notify-detail {
    overflow-wrap: break-word;
}

.notify-detail.clickable {
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
}

.notify-detail.clickable:hover {
    background: rgba(255, 255, 255, 0.15);
}

.notify-ok {
    flex: 0 0 auto;
    align-self: center;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.7);
    color: var(--white, #FFFFFF);
    font-family: inherit;
    font-size: 14px;
    font-weight: bold;
    padding: 8px 24px;
    border-radius: 6px;
    cursor: pointer;
}

.notify-ok:hover {
    background: var(--white, #FFFFFF);
    color: var(--danger, #C0392B);
}

.notify-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background: rgba(255, 255, 255, 0.7);
    transform-origin: left;
    animation: notify-progress linear forwards;
}

@keyframes notify-progress {
    from {
        transform: scaleX(1);
    }

    to {
        transform: scaleX(0);
    }
}

/* ── Waiting animation: five pulsing bars over a label, for anything the server is
   still working on - the CRUD file field's generation, the record sheet's file load
   and its server-side processing strip. The label takes the colour of whatever it
   sits on, so the same markup reads on the dark waveform box and on a white page. ── */

.wait {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.wait-bars {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 30px;
}

.wait-bars span {
    width: 5px;
    height: 100%;
    border-radius: 3px;
    background: var(--bmxgreen, #B7E81F);
    animation: wait-bar 1.1s ease-in-out infinite;
}

.wait-bars span:nth-child(2) {
    animation-delay: .15s;
}

.wait-bars span:nth-child(3) {
    animation-delay: .3s;
}

.wait-bars span:nth-child(4) {
    animation-delay: .45s;
}

.wait-bars span:nth-child(5) {
    animation-delay: .6s;
}

@keyframes wait-bar {

    0%,
    100% {
        transform: scaleY(.25);
    }

    50% {
        transform: scaleY(1);
    }
}
