/* MyFavBM styles */
:root {
    --icon-size: 56px;
    --text-size: 12px;
    --spacing: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-weight: 500;
    --tile-bg: transparent;
    --tile-text: #1f2937;
    --page-bg: #e9ecef;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --ink: #0f172a;
    --muted: #64748b;
    --accent: #0d6efd;
}

html, body { height: 100%; }
body {
    margin: 0;
    overflow: hidden;
    background-color: var(--page-bg);
    transition: background-color 0.25s;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.modal, .app-toast, input, textarea, select { user-select: text; -webkit-user-select: text; }

#desktop { position: fixed; inset: 0; overflow: hidden; }

/* ---------------- Link tiles ---------------- */
.link-icon {
    position: absolute;
    width: calc(var(--icon-size) + 40px);
    border-radius: 14px;
    touch-action: none;
    cursor: grab;
    transition: transform 0.15s, filter 0.15s;
}
.mode-profile .link-icon { cursor: pointer; touch-action: auto; }
.link-hit {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 8px 6px;
    border-radius: 14px;
    color: var(--l-text, var(--tile-text));
    background: var(--l-bg, var(--tile-bg));
    font-family: var(--l-font, var(--font));
    font-weight: var(--font-weight);
    text-decoration: none;
    -webkit-touch-callout: none;
    cursor: inherit;
    transition: background-color 0.15s, box-shadow 0.15s;
}
.link-hit:hover { color: var(--l-text, var(--tile-text)); }
.link-hit.has-bg { box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12); }
.link-icon:not(.edit-mode):hover .link-hit:not(.has-bg) { background-color: rgba(15, 23, 42, 0.06); }
.link-icon:not(.edit-mode):hover .link-hit.has-bg { filter: brightness(0.97); }
.link-hit:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.link-hit img {
    width: var(--icon-size);
    height: var(--icon-size);
    border-radius: 22%;
    background: #fff;
    padding: calc(var(--icon-size) * 0.08);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
    pointer-events: none;
    object-fit: contain;
}
.link-hit span {
    margin-top: var(--spacing);
    font-size: var(--l-size, var(--text-size));
    line-height: 1.25;
    width: 100%;
    overflow-wrap: anywhere;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.link-hit.has-bg span { text-shadow: none; }
.link-hit.no-icon { justify-content: center; min-height: calc(var(--icon-size) * 0.75); padding: 12px 10px; }
.link-hit.no-icon img { display: none; }
.link-hit.no-icon span { margin-top: 0; }

.link-icon.holding { transform: scale(0.95); }
.link-icon.dragging { cursor: grabbing; z-index: 1000; transform: scale(1.06); filter: drop-shadow(0 10px 18px rgba(15, 23, 42, 0.22)); }
.link-icon.edit-mode { z-index: 500; animation: wiggle 0.9s ease-in-out infinite; }
.link-icon.edit-mode .link-hit { box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.5); }
@keyframes wiggle {
    0%, 100% { transform: rotate(-1.2deg); }
    50% { transform: rotate(1.2deg); }
}
@media (prefers-reduced-motion: reduce) { .link-icon.edit-mode { animation: none; } }

.lock-badge {
    position: absolute;
    right: 10px;
    top: calc(var(--icon-size) - 6px);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
    pointer-events: none;
}
.link-icon.edit-mode .lock-badge { display: flex; }

.action-btn {
    position: absolute;
    top: -9px;
    width: 30px;
    height: 30px;
    border: 2px solid #fff;
    border-radius: 50%;
    color: #fff;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    visibility: hidden;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
}
.action-btn svg { width: 14px; height: 14px; }
.edit-btn { right: -9px; background: var(--accent); }
.delete-btn { left: -9px; background: #dc3545; }
.link-icon.edit-mode .action-btn { visibility: visible; opacity: 1; transform: scale(1); }

/* ---------------- Empty / welcome / profile ---------------- */
.empty-state {
    position: fixed;
    inset: 0 0 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    text-align: center;
    color: var(--muted);
    padding: 0 2rem;
}
.empty-state strong { display: block; color: var(--ink); font-size: 1.1rem; margin-bottom: 4px; }
.welcome {
    position: fixed;
    inset: 0 0 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    pointer-events: none;
}
.welcome-card {
    pointer-events: auto;
    max-width: 420px;
    text-align: center;
    padding: 2.25rem 2rem;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.1);
}
.welcome-mark {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    border-radius: 16px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(13, 110, 253, 0.35);
}
.welcome-mark svg { width: 28px; height: 28px; }
.welcome h1 { font-size: 1.6rem; font-weight: 700; color: var(--ink); margin-bottom: 0.4rem; }
.welcome p { color: var(--muted); margin-bottom: 1.4rem; }

.profile-chip {
    position: fixed;
    top: calc(12px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 6px 8px 6px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.1);
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
}
.profile-chip a {
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.07);
    color: var(--ink);
    text-decoration: none;
}

.profile-note {
    position: fixed;
    top: calc(62px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    width: min(92vw, 460px);
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff8e1;
    border: 1px solid #f5d77a;
    color: #6b5200;
    font-size: 13px;
    text-align: center;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

/* ---------------- Dock ---------------- */
#dock {
    position: fixed;
    left: 50%;
    bottom: calc(16px + var(--safe-bottom));
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 620px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.14), 0 1px 3px rgba(15, 23, 42, 0.08);
    z-index: 1000;
}
.dock-side { display: flex; align-items: center; gap: 4px; flex: none; }
.dock-side:empty { display: none; }
.dock-btn {
    flex: none;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #475569;
    transition: background-color 0.15s, color 0.15s, transform 0.15s;
    cursor: pointer;
}
.dock-btn svg { width: 22px; height: 22px; }
.dock-btn:hover { background: rgba(15, 23, 42, 0.07); color: var(--ink); }
.dock-btn:active { transform: scale(0.92); }
.dock-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dock-btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(13, 110, 253, 0.35); }
.dock-btn.primary:hover { background: #0b5ed7; color: #fff; }
.dock-btn.primary svg { width: 24px; height: 24px; }
.dock-btn.logout:hover { background: rgba(220, 53, 69, 0.1); color: #b02a37; }

#searchForm { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; }
#searchForm .search-icon { position: absolute; left: 14px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; display: flex; }
#searchForm .search-icon svg { width: 18px; height: 18px; }
#searchInput {
    width: 100%;
    height: 44px;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0 44px 0 40px;
    background: rgba(15, 23, 42, 0.06);
    color: var(--ink);
    font-size: 16px;
    outline: none;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}
#searchInput::placeholder { color: var(--muted); }
#searchInput::-webkit-search-cancel-button { display: none; }
#searchInput:focus { background: #fff; border-color: rgba(13, 110, 253, 0.5); box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12); }
.search-kbd {
    position: absolute;
    right: 12px;
    display: none;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid rgba(15, 23, 42, 0.15);
    background: rgba(255, 255, 255, 0.7);
    color: var(--muted);
    font: 600 12px/20px ui-monospace, SFMono-Regular, Menlo, monospace;
    text-align: center;
    pointer-events: none;
}
@media (hover: hover) and (pointer: fine) {
    .search-kbd { display: block; }
    #searchInput:focus + .search-kbd, #searchInput:not(:placeholder-shown) + .search-kbd { display: none; }
}
@media (max-width: 400px) {
    #dock { gap: 2px; padding: 5px; }
    .dock-btn { width: 40px; height: 40px; }
    .dock-side { gap: 2px; }
    #searchInput { padding-right: 12px; padding-left: 36px; }
    #searchForm .search-icon { left: 12px; }
}

/* ---------------- Toasts ---------------- */
/* Toasts sit just above the dock so they never cover the top row of links */
#toasts {
    position: fixed;
    bottom: calc(86px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    width: min(92vw, 440px);
    pointer-events: none;
}
.modal-open #toasts { z-index: 2000; }
.app-toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px 10px 16px;
    border-radius: 12px;
    color: #fff;
    background: #1e293b;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
    font-size: 14px;
    animation: toast-in 0.2s ease-out;
}
.app-toast.success { background: #146c43; }
.app-toast.danger { background: #b02a37; }
.app-toast.warning { background: #8a6d03; }
.app-toast .msg { flex: 1; }
.app-toast button { flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------------- Modals & forms ---------------- */
.modal-content { border: 0; border-radius: 18px; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25); }
.modal-header { border-bottom-color: rgba(15, 23, 42, 0.08); }
.modal-footer { border-top-color: rgba(15, 23, 42, 0.08); }
@media (min-width: 576px) { .modal-sm-wide { max-width: 420px; } }
.auth-view { display: none; }
.auth-view.active { display: block; }
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.preview-box {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 170px;
    padding: 16px;
    border-radius: 14px;
    background: var(--preview-bg, var(--page-bg));
    border: 1px solid rgba(15, 23, 42, 0.08);
    overflow: hidden;
}
.preview-tile { position: relative; cursor: default; }
.style-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.style-row .form-select, .style-row .form-range { min-width: 0; }
.style-row:has(.form-select), .style-row:has(.form-range) { grid-template-columns: 90px 1fr auto; }
.style-row .form-control-color { width: 46px; height: 34px; padding: 3px; }
.size-out { min-width: 38px; text-align: right; }
.segmented { display: flex; }
.segmented .btn { flex: 1; border-radius: 0; }
.segmented .btn:first-of-type { border-radius: 10px 0 0 10px; }
.segmented .btn:last-of-type { border-radius: 0 10px 10px 0; }
.flex-none { flex: none; }
.url-prefix { font-size: 14px; color: var(--muted); background: #f8fafc; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; line-height: 1.5; padding-top: 0.45rem; }
.username-status { min-height: 1.25em; }
.public-page-box { border: 1px solid rgba(15, 23, 42, 0.1); border-radius: 12px; padding: 12px 14px; background: #f8fafc; }
.public-page-box a { word-break: break-all; }
.danger-zone { border: 1px solid rgba(220, 53, 69, 0.3); border-radius: 12px; padding: 10px 14px; }
.danger-zone summary { color: #b02a37; font-weight: 600; cursor: pointer; }

/* ---------------- Admin ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat-card { background: #f8fafc; border: 1px solid rgba(15, 23, 42, 0.07); border-radius: 12px; padding: 12px 14px; }
.stat-card .num { font-size: 1.5rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.stat-card .lbl { font-size: 12px; color: var(--muted); }
.admin-table { font-size: 14px; }
.admin-table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
.admin-table td { vertical-align: middle; }
.admin-table tbody tr.clickable { cursor: pointer; }
.admin-table .sub { display: block; font-size: 12px; color: var(--muted); }
.admin-table .url { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; font-size: 12px; color: var(--muted); }
.badge-soft { font-weight: 600; font-size: 11px; border-radius: 6px; padding: 3px 7px; }

/* ---------------- Simple pages (setup / errors) ---------------- */
.simple-page { user-select: text; overflow: auto; display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.simple-card { background: #fff; max-width: 520px; width: 100%; padding: 2rem; border-radius: 16px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08); }
