/* Shared, token-driven UI: page chrome (desktop nav, mobile top bar, floating tab bar), theme picker, effect layer.
   Everything here uses var(--k-*) only, so every theme restyles it by changing tokens (and theme.css for extras). */

html { background: var(--k-page); }
body { background: var(--k-page) !important; color: var(--k-text); font-family: var(--k-font-body) !important; }
h1, h2, h3, h4, h5, h6 { font-family: var(--k-font-head) !important; text-transform: var(--k-head-transform); letter-spacing: var(--k-head-spacing); }
.btn, button { font-family: var(--k-font-head); }
::selection { background: var(--k-accent-soft); }
:focus-visible { outline: none; box-shadow: var(--k-focus); }

/* ---------- desktop nav ---------- */
header.navigation { background: var(--k-nav-bg) !important; border-bottom: 1px solid var(--k-border-soft) !important;
    -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px); }
.k-nav-link { color: var(--k-muted) !important; font-weight: 500; transition: color .2s; cursor: pointer; white-space: nowrap; }
.k-nav-link:hover, .k-nav-link.active { color: var(--k-link) !important; }
.k-nav-menu { background: var(--k-surface); border-radius: var(--k-radius-card); border: var(--k-card-border); box-shadow: var(--k-tabbar-shadow); padding: 8px; }
.k-nav-menu .dropdown-item { color: var(--k-text); border-radius: calc(var(--k-radius-btn) * .8); padding: 8px 16px; }
.k-nav-menu .dropdown-item:hover { background: var(--k-accent-soft); color: var(--k-text); }
.navbar-brand .k-brand-name { color: var(--k-text) !important; font-family: var(--k-font-head) !important; }

/* Theme button (nav, top bar, app bar) */
.k-theme-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 10px;
    border: 1px solid var(--k-border); border-radius: var(--k-radius-pill); background: var(--k-surface); color: var(--k-text);
    font: 600 13px var(--k-font-head); cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.k-theme-btn:hover { border-color: var(--k-accent); color: var(--k-link); }
.k-theme-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.k-theme-btn .k-theme-btn-label { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- mobile: top bar + floating tab bar ---------- */
.mobile-top-bar { display: none; }
@media (max-width: 768px) {
    body { padding-bottom: calc(104px + env(safe-area-inset-bottom)) !important; }
    .mobile-top-bar { display: flex !important; position: fixed; top: 0; left: 0; right: 0; z-index: 1001; align-items: center; justify-content: space-between;
        height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
        background: var(--k-nav-bg); border-bottom: 1px solid var(--k-border-soft);
        -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); }
    body { padding-top: calc(56px + env(safe-area-inset-top)) !important; }
    .mobile-top-bar .k-theme-btn { height: 38px; padding: 0 12px; }
    .mobile-top-bar .k-theme-btn-label { max-width: 84px; }
}
.mobile-top-user { display: flex; align-items: center; text-decoration: none !important; }
.mobile-top-user .user-avatar { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font: 700 14px var(--k-font-head); }
.mobile-top-user .user-avatar, .k-appbar-user { background: var(--k-btn-bg) !important; color: var(--k-on-accent) !important; border: var(--k-btn-border); }
.mobile-top-logo { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); }
.mobile-top-actions { display: flex; align-items: center; gap: 6px; }
.mobile-top-notification { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; color: var(--k-muted); text-decoration: none; border-radius: 50%; }
.mobile-top-notification:hover { color: var(--k-accent); }

.mobile-bottom-nav { display: none; }
@media (max-width: 768px) {
    .mobile-bottom-nav { display: flex; align-items: stretch; justify-content: space-around; position: fixed; z-index: 1000;
        left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom));
        height: 66px; padding: 0 6px; border-radius: var(--k-radius-nav); background: var(--k-tabbar-bg); border: var(--k-card-border);
        box-shadow: var(--k-tabbar-shadow); -webkit-backdrop-filter: saturate(1.6) blur(18px); backdrop-filter: saturate(1.6) blur(18px); }
}
.bottom-nav-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; flex: 1; min-width: 0;
    color: var(--k-muted); font: 600 10.5px var(--k-font-head); text-decoration: none !important; text-transform: var(--k-head-transform);
    letter-spacing: var(--k-head-spacing); touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: color .2s; }
.bottom-nav-item svg { width: 22px; height: 22px; transition: transform .2s; }
.bottom-nav-item::before { content: ''; position: absolute; top: 8px; width: 46px; height: 30px; border-radius: var(--k-radius-pill); background: var(--k-accent-soft);
    transform: scale(.4); opacity: 0; transition: transform .2s, opacity .2s; z-index: -1; }
.bottom-nav-item.active { color: var(--k-link); }
.bottom-nav-item.active::before { transform: none; opacity: 1; }
.bottom-nav-item:active svg { transform: scale(.9); }
.bottom-nav-center::before { display: none; }
.bottom-nav-center .center-btn { width: 54px; height: 54px; margin-top: -26px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
    background: var(--k-btn-bg); color: var(--k-on-accent); border: var(--k-btn-border); box-shadow: var(--k-btn-shadow), 0 8px 20px var(--k-accent-soft); }
.bottom-nav-center .center-btn svg { stroke: currentColor; width: 28px; height: 28px; }
.bottom-nav-center span { display: none; }
.mobile-quick-actions-backdrop { position: fixed; inset: 0; background: var(--k-backdrop); z-index: 1100; }
.mobile-quick-actions-sheet { position: fixed; left: 14px; right: 14px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 1101; overflow: hidden;
    background: var(--k-surface); border-radius: var(--k-radius-card); border: var(--k-card-border); box-shadow: var(--k-tabbar-shadow); }
.mobile-quick-action-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: var(--k-text) !important; text-decoration: none !important;
    font: 600 14px var(--k-font-head); border-bottom: 1px solid var(--k-border-soft); }
.mobile-quick-action-item:last-child { border-bottom: none; }
.mobile-quick-action-icon { width: 28px; text-align: center; font-size: 18px; }
.mobile-quick-actions-sheet[hidden], .mobile-quick-actions-backdrop[hidden] { display: none !important; }

/* ---------- theme picker (bottom sheet on phones, panel on desktop) ---------- */
.kt-sheet { position: fixed; inset: 0; z-index: 5000; }
.kt-sheet[hidden] { display: none; }
.kt-backdrop { position: absolute; inset: 0; background: var(--k-backdrop); animation: kt-fade .2s; }
.kt-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: min(86vh, 760px); overflow-y: auto; overscroll-behavior: contain;
    padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); background: var(--k-surface); color: var(--k-text);
    border-radius: var(--k-radius-card) var(--k-radius-card) 0 0; border: var(--k-card-border); box-shadow: 0 -12px 40px rgba(0, 0, 0, .25); animation: kt-up .25s ease-out; }
@media (min-width: 769px) {
    .kt-panel { left: 50%; right: auto; bottom: auto; top: 50%; width: min(720px, 92vw); transform: translate(-50%, -50%); border-radius: var(--k-radius-card);
        padding: 18px 22px 22px; animation: kt-fade .2s; }
    .kt-handle { display: none; }
}
.kt-handle { width: 42px; height: 5px; border-radius: 3px; background: var(--k-border); margin: 4px auto 10px; }
.kt-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.kt-head h2 { margin: 0; font-size: 20px; flex: 1; }
.kt-more { font-size: 13px; font-weight: 600; color: var(--k-link) !important; }
.kt-close { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--k-border); background: var(--k-surface-2); color: var(--k-text); cursor: pointer; font-size: 15px; }
.kt-modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 4px; margin-bottom: 14px; border-radius: var(--k-radius-pill); background: var(--k-surface-2); }
.kt-modes button { min-height: 40px; border: 0; border-radius: var(--k-radius-pill); background: transparent; color: var(--k-muted); font: 600 13px var(--k-font-head); cursor: pointer; }
.kt-modes button[aria-pressed="true"] { background: var(--k-surface); color: var(--k-text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.kt-modes button:disabled { opacity: .35; cursor: not-allowed; }
.kt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 400px) { .kt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kt-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; text-align: left; cursor: pointer; border: 2px solid var(--k-border);
    border-radius: calc(var(--k-radius-card) * .8); background: var(--k-surface); color: var(--k-text); transition: border-color .15s, transform .1s; font-family: var(--k-font-body); }
.kt-card:active { transform: scale(.98); }
.kt-card.is-on { border-color: var(--k-accent); box-shadow: 0 0 0 3px var(--k-accent-soft); }
.kt-preview { display: block; height: 74px; padding: 10px; border-radius: 10px; border: 1px solid; }
.kt-preview-card { display: flex; flex-direction: column; gap: 5px; height: 100%; padding: 8px; border-radius: 7px; border: 1px solid; }
.kt-preview-card i { display: block; height: 6px; border-radius: 3px; width: 70%; } .kt-preview-card i + i { width: 45%; opacity: .7; }
.kt-preview-card b { display: block; margin-top: auto; height: 12px; width: 48%; border-radius: 6px; }
.kt-name { font: 700 14px var(--k-font-head); }
.kt-desc { font-size: 11.5px; color: var(--k-muted); line-height: 1.3; }
html.kt-sheet-open { overflow: hidden; }
@keyframes kt-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes kt-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- theme effect layer (behind the content) ---------- */
#kiko-theme-fx { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
#kiko-theme-fx:empty { display: none; }
html.kt-fx body { background: transparent !important; }   /* the html element keeps the page colour; the effect sits between */

@media (prefers-reduced-motion: reduce) { .kt-panel, .kt-backdrop { animation: none; } }

/* App pages: the app bar carries the theme button on phones (desktop has it in the nav). */
.k-appbar .k-appbar-theme { display: none; flex-shrink: 0; }
@media (max-width: 768px) { .k-appbar .k-appbar-theme { display: inline-flex; } }

/* Dark modes: form details browsers don't theme by themselves */
html[data-theme="dark"] ::placeholder { color: var(--k-muted); opacity: .8; }
html[data-theme="dark"] input:-webkit-autofill { -webkit-text-fill-color: var(--k-text); -webkit-box-shadow: 0 0 0 1000px var(--k-surface) inset; }
html[data-theme="dark"] .navbar-light .navbar-toggler-icon { filter: invert(1); }
html[data-theme="dark"] hr { border-color: var(--k-border-soft); }

/* Appearance page */
.k-appearance-head h1 { margin: 0 0 6px; font-size: 28px; color: var(--k-text); }
.k-appearance-head p, .k-appearance-note { color: var(--k-muted); font-size: 14px; }
.k-appearance-gallery { margin-top: 16px; padding: 16px; background: var(--k-surface); border: var(--k-card-border); border-radius: var(--k-radius-card); box-shadow: var(--k-card-shadow); }
.k-appearance-gallery .kt-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.k-appearance-gallery .kt-preview { height: 96px; }
