/* LPG1 Smart Portal — Portal */
:root {
    --brand-1: #4c1d95;
    --brand-2: #7c3aed;
    --brand-3: #a78bfa;
    --ink: #1f2937;
    --muted: #6b7280;
    --surface: #ffffff;
    --bg: #f4f2fb;
    --radius: 18px;
}

html, body { min-height: 100%; }
body {
    font-family: 'Sarabun', system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
}
body.is-bare {
    background: linear-gradient(150deg, var(--brand-1) 0%, var(--brand-2) 60%, var(--brand-3) 100%);
}

/* ---------- App bar ---------- */
.appbar {
    position: sticky; top: 0; z-index: 1030;
    display: flex; align-items: center; justify-content: space-between;
    gap: .75rem;
    padding: calc(.55rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .55rem max(1rem, env(safe-area-inset-left));
    background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
    color: #fff;
    box-shadow: 0 2px 14px rgba(76, 29, 149, .25);
}
.appbar-brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
.appbar-brand img { border-radius: 9px; background: #fff; }
.appbar-brand span { display: flex; flex-direction: column; line-height: 1.1; }
.appbar-brand strong { font-size: 1rem; }
.appbar-brand small { font-size: .72rem; opacity: .8; }
.appbar-actions { display: flex; align-items: center; gap: .5rem; }
.appbar-user, .btn-install {
    display: inline-flex; align-items: center; gap: .45rem;
    border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12);
    color: #fff; border-radius: 999px; padding: .3rem .7rem .3rem .3rem; font-size: .9rem;
}
.btn-install { padding: .35rem .8rem; }
.appbar-user .avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: inline-grid; place-items: center;
    background: #fff; color: var(--brand-1); font-weight: 700;
}

/* ---------- Hero ---------- */
.hero-card {
    display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: stretch;
    background: linear-gradient(135deg, var(--brand-1) 0%, var(--brand-2) 70%, #8b5cf6 100%);
    color: #fff; border-radius: var(--radius); padding: 1.25rem 1.4rem;
    box-shadow: 0 10px 30px rgba(76, 29, 149, .25);
}
.hero-greet { opacity: .85; font-size: .95rem; }
.hero-name { font-size: clamp(1.25rem, 4vw, 1.75rem); font-weight: 700; margin: .1rem 0 .4rem; }
.hero-meta { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .88rem; opacity: .9; }
.hero-date { margin-top: .6rem; font-size: .85rem; opacity: .8; }
.hero-status {
    min-width: 200px; flex: 0 1 260px;
    background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25);
    border-radius: 14px; padding: .9rem 1rem; color: #fff; text-decoration: none;
    transition: background .15s;
}
.hero-status:hover { background: rgba(255,255,255,.22); color: #fff; }
.hero-status .label { font-size: .75rem; opacity: .75; }
.hero-status .time { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }

/* ---------- Install card ---------- */
.install-card {
    display: flex; align-items: center; gap: 1rem;
    background: var(--surface); border-radius: var(--radius);
    padding: 1rem 1.2rem; border: 1px dashed #c4b5fd; color: var(--brand-1);
}

/* ---------- App grid ---------- */
.section-title { font-size: 1.05rem; font-weight: 700; color: var(--brand-1); margin-bottom: .8rem; }
.app-grid {
    display: grid; gap: .9rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 576px) { .app-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 992px) { .app-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.app-tile {
    position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: .25rem;
    background: var(--surface); border-radius: var(--radius); padding: 1.1rem 1rem 1rem;
    color: var(--ink); text-decoration: none; min-height: 140px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 18px rgba(31, 41, 55, .06);
    border: 1px solid #ede9fe;
    transition: transform .12s ease, box-shadow .12s ease;
}
a.app-tile:hover, a.app-tile:focus-visible { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(76,29,149,.14); color: var(--ink); }
a.app-tile:active { transform: scale(.98); }
.app-icon {
    width: 50px; height: 50px; border-radius: 14px; margin-bottom: .45rem;
    display: grid; place-items: center; font-size: 1.35rem; color: #fff;
    background: var(--tile);
    box-shadow: 0 6px 14px color-mix(in srgb, var(--tile) 35%, transparent);
}
.app-title { font-weight: 700; font-size: 1rem; line-height: 1.25; }
.app-sub { font-size: .8rem; color: var(--muted); }
/* การ์ดที่มีเมนูดรอปดาวน์ */
.app-dd { position: relative; display: flex; }
button.app-tile { width: 100%; text-align: left; font: inherit; cursor: pointer; }
.app-tile.is-menu:hover, .app-tile.is-menu:focus-visible, .app-tile.is-menu[aria-expanded="true"] {
    transform: translateY(-2px); box-shadow: 0 10px 26px rgba(76,29,149,.14); outline: none;
}
.app-tile.is-menu[aria-expanded="true"] { border-color: var(--tile); }
.app-caret {
    position: absolute; top: .9rem; right: .9rem;
    width: 26px; height: 26px; border-radius: 50%;
    display: grid; place-items: center; font-size: .7rem;
    color: var(--tile); background: color-mix(in srgb, var(--tile) 12%, transparent);
    transition: transform .2s ease;
}
.app-tile.is-menu[aria-expanded="true"] .app-caret { transform: rotate(180deg); }
.app-menu {
    min-width: 100%; padding: .4rem; border: 1px solid #ede9fe; border-radius: 14px;
    box-shadow: 0 12px 30px rgba(31, 41, 55, .14);
}
.app-menu .dropdown-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .55rem .7rem; border-radius: 10px; font-size: .92rem; color: var(--ink);
}
.app-menu .dropdown-item i { color: var(--tile); }
.app-menu .dropdown-item:hover, .app-menu .dropdown-item:focus {
    background: color-mix(in srgb, var(--tile) 10%, transparent); color: var(--ink);
}
.app-menu .dropdown-item:active { background: var(--tile); color: #fff; }
.app-menu .dropdown-item:active i { color: #fff; }

.app-tile.is-soon { opacity: .6; cursor: not-allowed; }
.app-tile.is-soon .app-icon { filter: grayscale(.35); }
.soon-badge {
    position: absolute; top: .7rem; right: .7rem;
    font-size: .68rem; background: #f3f4f6; color: var(--muted);
    border-radius: 999px; padding: .1rem .5rem;
}

/* ---------- Buttons ---------- */
.btn-portal {
    background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
    color: #fff; border: 0; font-weight: 600;
}
.btn-portal:hover, .btn-portal:focus { color: #fff; filter: brightness(1.08); }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; min-height: 100dvh;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: calc(1.5rem + env(safe-area-inset-top)) 1rem calc(1.5rem + env(safe-area-inset-bottom));
}
.login-card {
    width: 100%; max-width: 410px; background: #fff; border-radius: 22px; overflow: hidden;
    box-shadow: 0 20px 50px rgba(30, 10, 70, .35);
}
.login-head { text-align: center; padding: 1.8rem 1.5rem 1.2rem; background: linear-gradient(180deg, #f5f3ff, #fff); }
.login-head img { border-radius: 18px; box-shadow: 0 8px 20px rgba(76,29,149,.25); }
.login-head h1 { font-size: 1.35rem; font-weight: 700; color: var(--brand-1); margin: .9rem 0 .2rem; }
.login-head p { font-size: .88rem; color: var(--muted); margin: 0; }
.login-body { padding: .6rem 1.5rem 1.6rem; }
.login-body .form-label { font-size: .88rem; font-weight: 600; }

/* ---------- Footer ---------- */
.portal-footer {
    text-align: center; font-size: .78rem; color: var(--muted);
    padding: 1.2rem 1rem calc(1.2rem + env(safe-area-inset-bottom));
}

/* ---------- กระดิ่งแจ้งเตือน ---------- */
.appbar-bell {
    position: relative; width: 38px; height: 38px; border-radius: 50%;
    display: inline-grid; place-items: center; font-size: 1.05rem;
    border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff;
}
.appbar-bell:hover { background: rgba(255,255,255,.22); }
.appbar-bell.ring i { animation: bell-ring .9s ease; transform-origin: 50% 10%; }
@keyframes bell-ring { 0%,100% { transform: rotate(0) } 20% { transform: rotate(16deg) } 40% { transform: rotate(-14deg) } 60% { transform: rotate(9deg) } 80% { transform: rotate(-5deg) } }
@media (prefers-reduced-motion: reduce) { .appbar-bell.ring i { animation: none; } }
.bell-badge {
    position: absolute; top: -4px; right: -4px; min-width: 19px; height: 19px; padding: 0 5px;
    border-radius: 999px; background: #ef4444; color: #fff; font-size: .7rem; font-weight: 700;
    line-height: 19px; text-align: center; box-shadow: 0 0 0 2px var(--brand-1);
}
.bell-menu { width: min(380px, calc(100vw - 24px)); border-radius: 14px; overflow: hidden; }
.bell-head, .bell-foot { display: flex; align-items: center; gap: .5rem; padding: .6rem .9rem; font-size: .9rem; }
.bell-head { border-bottom: 1px solid #eee; }
.bell-foot { border-top: 1px solid #eee; justify-content: space-between; font-size: .85rem; }
.bell-foot a { text-decoration: none; }
.bell-list { max-height: min(420px, 60vh); overflow-y: auto; }
.bell-empty { text-align: center; color: var(--muted); padding: 1.6rem 1rem; font-size: .9rem; }

/* ---------- รายการแจ้งเตือน ---------- */
.notif-list { overflow: hidden; border-radius: var(--radius); border: 1px solid #ede9fe; }
.notif-item {
    position: relative; display: flex; gap: .75rem; align-items: flex-start;
    padding: .85rem 1rem; color: var(--ink); text-decoration: none; border-bottom: 1px solid #f1f0f7;
    --lvl: var(--brand-2);
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: #faf8ff; color: var(--ink); }
.notif-item.is-unread { background: #f7f3ff; }
.notif-item.lvl-success { --lvl: #16a34a; }
.notif-item.lvl-warning { --lvl: #d97706; }
.notif-item.lvl-danger  { --lvl: #dc2626; }
.notif-ic {
    flex: 0 0 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
    color: var(--lvl); background: color-mix(in srgb, var(--lvl) 12%, #fff);
}
.notif-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.notif-title { font-weight: 600; line-height: 1.3; }
.notif-item.is-unread .notif-title { font-weight: 700; }
.notif-body { font-size: .88rem; color: #4b5563; margin-top: .15rem; overflow-wrap: anywhere; }
.notif-meta { font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.notif-dot { flex: 0 0 9px; height: 9px; border-radius: 50%; background: #ef4444; margin-top: .4rem; }
.notif-item.compact { padding: .65rem .9rem; }
.notif-item.compact .notif-body { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.line-code-box { background: #f0fdf4; border: 1px dashed #86efac; border-radius: 12px; padding: .8rem 1rem; text-align: center; }
.line-code { font-size: 2rem; font-weight: 700; letter-spacing: .35em; color: #15803d; font-variant-numeric: tabular-nums; }

/* standalone (ติดตั้งเป็นแอปแล้ว) */
@media (display-mode: standalone) {
    .btn-install, #installCard { display: none !important; }
}
