/* ==========================================================================
   Toasts — one card for every Flash message and $.notify call
   --------------------------------------------------------------------------
   Loaded by every admin layout (Layout/default.ctp, superadmin.ctp, frame.ctp), so pages that
   never include Element/admin_header.ctp (login, delivery sheet Users/orderv2, delivery-map
   frames) get the same card as the rest of the panel. Was section 53 of ui-refresh.css.
   Selectors carry :not(#toast-x) (id-level specificity) so they win over AdminLTE.min.css,
   modern-admin.css (.skin-blue div.message.error { ... !important }) and per-page sheets
   regardless of load order.
   ========================================================================== */

/*
   Two message systems run side by side: CakePHP Flash (div.message.success / .error, rendered by
   Layout/default.ctp, hidden after 5s by message.js) and notify.js (~1,000 AJAX success/error calls).
   Both render here as the same white card: tinted round icon, dark message text, a close cross and,
   on success, a 5s countdown bar matching both auto-hide delays. Clicking anywhere on either
   dismisses it (Flash's inline onclick, notify's clickToHide), so the cross is a cue, not a target.

   Overrides it has to beat: AdminLTE.min.css (div.message.error pink fill, !important), cake.css
   (div.message blue fill + "i" disc) and modern-admin.css:1746 (.skin-blue fill, !important).
   notify.js injects its own <style> into <head> at runtime, after this file, so its selectors are
   qualified with .notifyjs-wrapper to win on specificity. notify's arrow on field-anchored notices
   takes its colour from border-color, so the card border doubles as the arrow colour.
   Layout/default.ctp + frame.ctp move notify's default corner to top centre.
*/

:root {
    --toast-success: #16a34a;
    --toast-success-bg: #dcfce7;
    --toast-info: #4f46e5;
    --toast-info-bg: #e0e7ff;
    --toast-warn: #b45309;
    --toast-warn-bg: #fef3c7;
    --toast-error: #dc2626;
    --toast-error-bg: #fee2e2;
    --toast-icon-success: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2316a34a' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
    --toast-icon-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10.2'/%3E%3Cpath d='M12 11v6M12 7.2v.01'/%3E%3C/svg%3E");
    --toast-icon-warn: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b45309' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2.6L1.6 20.6h20.8L12 2.6z'/%3E%3Cpath d='M12 9.6v5M12 17.6v.01'/%3E%3C/svg%3E");
    --toast-icon-error: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23dc2626' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10.2'/%3E%3Cpath d='M8.6 8.6l6.8 6.8M15.4 8.6l-6.8 6.8'/%3E%3C/svg%3E");
}

@keyframes toast-countdown {
    from { background-size: 100% 4px, 100% 4px; }
    to { background-size: 0% 4px, 100% 4px; }
}

/* --- shared card ------------------------------------------------------------------ */
body:not(#toast-x) div.message.success,
body:not(#toast-x) div.message.error,
body:not(#toast-x) div.message.info,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-base {
    position: relative;
    box-sizing: border-box;
    min-height: 64px;
    padding: 20px 48px 20px 64px;
    background-color: #ffffff !important;
    background-image: none;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .06);
    color: #111827;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.45;
    text-align: left;
    text-shadow: none;
    white-space: normal;
    overflow: hidden;
}

/* icon disc */
body:not(#toast-x) div.message.success::before,
body:not(#toast-x) div.message.error::before,
body:not(#toast-x) div.message.info::before,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-base::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 16px;
    width: 34px;
    height: 34px;
    margin-top: -17px;
    padding: 0;
    border-radius: 50%;
    background-color: var(--toast-info-bg);
    background-image: var(--toast-icon-info);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 22px 22px;
    line-height: normal;
    font-size: 0;
}

/* close cross */
body:not(#toast-x) div.message.success::after,
body:not(#toast-x) div.message.error::after,
body:not(#toast-x) div.message.info::after,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-base::after {
    content: "\00d7";
    position: absolute;
    top: 50%;
    right: 18px;
    margin-top: -12px;
    color: #6b7280;
    font: 400 22px/24px Arial, sans-serif;
}

/* --- per type ---------------------------------------------------------------------- */
body:not(#toast-x) div.message.success,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-success {
    background-image: linear-gradient(var(--toast-success), var(--toast-success)),
                      linear-gradient(#eef0f3, #eef0f3);
    background-repeat: no-repeat;
    background-position: left bottom, left bottom;
    background-size: 100% 4px, 100% 4px;
    animation: toast-countdown 5s linear forwards;
}

body:not(#toast-x) div.message.success::before,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-success::before {
    background-color: var(--toast-success-bg);
    background-image: var(--toast-icon-success);
}

.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-warn::before {
    background-color: var(--toast-warn-bg);
    background-image: var(--toast-icon-warn);
}

body:not(#toast-x) div.message.error::before,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-error::before {
    background-color: var(--toast-error-bg);
    background-image: var(--toast-icon-error);
}

/* notify's per-type classes paint their own colour, border and base64 icon */
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-info,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-warn,
.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-error {
    color: #111827;
    background-color: #ffffff;
    background-image: none;
    border-color: #e5e7eb;
}

.notifyjs-wrapper:not(#toast-x) .notifyjs-bootstrap-success {
    color: #111827;
    background-color: #ffffff;
    border-color: #e5e7eb;
}

/* --- placement ----------------------------------------------------------------------- */
/* Flash: the success/error elements pin it at right:50% with a fixed 340px width */
body:not(#toast-x) div.message.success,
body:not(#toast-x) div.message.error,
body:not(#toast-x) div.message.info {
    position: fixed;
    top: 24px;
    left: 50%;
    right: auto;
    width: min(440px, calc(100vw - 32px)) !important; /* AdminLTE.min.css sets 449px !important */
    margin: 0;
    transform: translateX(-50%);
    z-index: 999999;
    cursor: pointer;
}

/* page-level notify toasts get the Flash width; field-anchored notices stay compact */
.notifyjs-corner .notifyjs-bootstrap-base {
    width: min(440px, calc(100vw - 32px));
}

.notifyjs-wrapper:not(.notifyjs-corner .notifyjs-wrapper):not(#toast-x) .notifyjs-bootstrap-base {
    min-height: 0;
    padding: 10px 40px 10px 50px;
    font-size: 13.5px;
    border-radius: 10px;
}

.notifyjs-wrapper:not(.notifyjs-corner .notifyjs-wrapper):not(#toast-x) .notifyjs-bootstrap-base::before {
    left: 12px;
    width: 26px;
    height: 26px;
    margin-top: -13px;
    background-size: 18px 18px;
}

.notifyjs-wrapper:not(.notifyjs-corner .notifyjs-wrapper):not(#toast-x) .notifyjs-bootstrap-base::after {
    right: 12px;
    font-size: 18px;
}

/* notify.js anchors "top center" at left:45%; centre it for real, level with the Flash toast */
.notifyjs-corner[style*="left: 45%"][style*="top: 0"] {
    top: 24px !important;
    left: 50% !important;
    margin: 0;
    transform: translateX(-50%);
    z-index: 1000000;
}

.notifyjs-corner .notifyjs-wrapper + .notifyjs-wrapper {
    margin-top: 12px;
}

/* Flash's onclick adds .hidden, whose legacy rule only zeroes the height - the card's padding and
   min-height would keep it on screen */
body:not(#toast-x) div.message.hidden {
    display: none !important;
}
