:root {
    --ink: #17324d;
    --muted: #6a7d92;
    --line: #cfe4f7;
    --bg: #eef8ff;
    --panel: #ffffff;
    --accent: #42a5f5;
    --accent-2: #8bd8ff;
    --accent-soft: #dcf3ff;
}

* { box-sizing: border-box; }

/* พื้นหลังเดียวกับ body เพื่อไม่ให้เห็นจอขาวแวบตอนสลับหน้า */
html {
    background: #f2f9ff;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(139, 216, 255, .38), transparent 34%),
        linear-gradient(135deg, #f6fbff 0%, #e9f7ff 52%, #f7fbff 100%);
    color: var(--ink);
    font-family: 'Noto Sans Thai', sans-serif;
}

/* สลับหน้าแบบ cross-fade (เบราว์เซอร์ที่ไม่รองรับจะข้ามกฎนี้ไปเฉย ๆ) */
@view-transition {
    navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: .16s;
}

/* แถบโหลดบาง ๆ ด้านบน แทน overlay เต็มจอตอนเปลี่ยนหน้า */
.mycal-nav-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 4000;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.mycal-nav-progress::before {
    content: '';
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #42a5f5, #1e88e5);
    box-shadow: 0 0 8px rgba(30, 136, 229, .55);
}

.mycal-nav-progress.show {
    opacity: 1;
}

.mycal-nav-progress.show::before {
    animation: mycal-nav-progress-run 2.4s ease-out forwards;
}

@keyframes mycal-nav-progress-run {
    0% { width: 0; }
    35% { width: 48%; }
    70% { width: 76%; }
    100% { width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation: none;
    }

    .mycal-nav-progress.show::before {
        animation: none;
        width: 65%;
    }
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 250px 1fr;
    transition: grid-template-columns .18s ease;
}

.app-shell.sidebar-collapsed {
    grid-template-columns: 76px 1fr;
}

.sidebar {
    background: linear-gradient(180deg, #1f6fb2 0%, #15507f 100%);
    color: #fff;
    padding: 24px 16px;
    overflow: hidden;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 20px;
    min-width: 0;
    margin-bottom: 0;
}

.brand-toggle {
    border: 0;
    background: transparent;
    color: #fff;
    padding: 0;
    text-align: left;
    cursor: pointer;
}

.brand-toggle:hover {
    opacity: .92;
}

.sidebar-toggle {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    background: rgba(255,255,255,.13);
    font-size: 22px;
    flex: 0 0 auto;
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,.22);
}

.brand-logo {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    object-fit: cover;
    background: #fff;
    border: 2px solid rgba(255,255,255,.72);
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    color: #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    background: transparent;
    white-space: nowrap;
}

.sidebar .nav-link i {
    width: 22px;
    font-size: 20px;
    text-align: center;
    flex: 0 0 auto;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.sidebar .logout-link {
    font: inherit;
    color: #fff;
    background: #c2414b;
}

.sidebar .logout-link:hover,
.sidebar .logout-link:focus-visible {
    color: #fff;
    background: #9f2f39;
}

.mobile-menu-card.mobile-logout-link {
    color: #9f1239;
}

.mobile-menu-card.mobile-logout-link:hover,
.mobile-menu-card.mobile-logout-link:focus-visible {
    color: #881337;
    background-color: #fecaca !important;
}

.mobile-nav {
    display: none;
}

.sidebar-label,
.sidebar-user {
    transition: opacity .14s ease;
}

.sidebar-collapsed .sidebar {
    padding-left: 14px;
    padding-right: 14px;
}

.sidebar-collapsed .sidebar-head {
    justify-content: center;
}

.sidebar-collapsed .brand {
    display: none;
}

.sidebar-collapsed .sidebar-toggle {
    width: 44px;
}

.sidebar-collapsed .sidebar-label,
.sidebar-collapsed .sidebar-user {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
}

.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
}

.content {
    /* ใช้ระยะเดียวกับหน้า Calendar ทุกหน้า */
    padding: 18px 20px;
    min-width: 0;
}

.page-title {
    margin-bottom: 14px;
}

.page-title small {
    display: block;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
}

.card {
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 12px 28px rgba(45, 126, 190, .12);
}

.stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat strong {
    display: block;
    font-size: 32px;
}

.badge-soft {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 4px 10px;
    background: #e2f5ff;
    color: #1769aa;
    font-size: 12px;
    font-weight: 700;
}

.btn-dark {
    background: linear-gradient(135deg, #42a5f5, #1e88e5);
    border-color: #1e88e5;
}

.btn-dark:hover {
    background: linear-gradient(135deg, #1e88e5, #1565c0);
    border-color: #1565c0;
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 7vh 16px 28px;
    background:
        radial-gradient(circle at 16% 18%, rgba(138, 216, 255, .48), transparent 30%),
        radial-gradient(circle at 86% 12%, rgba(187, 232, 255, .62), transparent 28%),
        linear-gradient(135deg, #f6fcff 0%, #e7f6ff 54%, #f9fdff 100%);
}

.mycal-sync-overlay,
.mycal-busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, .32);
    backdrop-filter: blur(3px);
}

.mycal-sync-overlay.show,
.mycal-busy-overlay.show {
    display: flex;
}

.mycal-sync-panel,
.mycal-busy-panel {
    display: flex;
    align-items: center;
    gap: 16px;
    width: min(420px, calc(100vw - 32px));
    padding: 22px;
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, .28);
    background: rgba(255,255,255,.96);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .20);
}

.auth-card {
    width: 100%;
    max-width: 460px;
    border: 1px solid rgba(80, 166, 225, .24);
    border-radius: 22px;
    background: rgba(255,255,255,.92);
    box-shadow: 0 24px 56px rgba(57, 133, 196, .20);
    overflow: hidden;
}

.auth-card.wide {
    max-width: 560px;
}

.auth-card-body {
    padding: 30px 28px;
}

.auth-logo {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 24px;
    background: #fff;
    padding: 6px;
    box-shadow: 0 14px 28px rgba(45, 126, 190, .18);
    border: 1px solid rgba(80, 166, 225, .25);
}

.auth-title {
    color: #1769aa;
    font-size: 28px;
    font-weight: 800;
    margin: 14px 0 4px;
}

.auth-subtitle {
    color: #6a7d92;
    margin-bottom: 22px;
}

.auth-card .form-control {
    min-height: 46px;
    border-radius: 12px;
    border-color: #c9e3f7;
}

.auth-card .form-control:focus {
    border-color: #42a5f5;
    box-shadow: 0 0 0 .2rem rgba(66, 165, 245, .16);
}

.auth-card a {
    color: #1769aa;
    font-weight: 700;
    text-decoration: none;
}

.auth-card a:hover {
    text-decoration: underline;
}

.auth-card a.btn-primary,
.auth-card a.btn-success,
.auth-card a.btn-danger,
.auth-card a.btn-dark,
.auth-card a.btn-line {
    color: #fff;
    text-decoration: none;
}

.swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.1);
}

textarea.form-control {
    min-height: 130px;
}

@media (max-width: 900px) {
    .app-shell,
    .app-shell.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 1020;
        padding: 12px 12px 10px;
        overflow: visible;
        box-shadow: 0 10px 24px rgba(21, 80, 127, .18);
    }

    .sidebar-head {
        margin-bottom: 10px;
    }

    .brand,
    .sidebar-collapsed .brand {
        display: flex;
    }

    .brand-logo {
        width: 40px;
        height: 40px;
    }

    .sidebar-toggle,
    .sidebar-collapsed .sidebar-toggle {
        width: 42px;
        height: 42px;
    }

    .sidebar-user {
        margin-bottom: 10px !important;
    }

    .sidebar .nav {
        display: flex;
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 2px 0 8px;
        margin: 0 -2px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar .nav::-webkit-scrollbar {
        height: 4px;
    }

    .sidebar .nav::-webkit-scrollbar-thumb {
        background: rgba(255,255,255,.36);
        border-radius: 999px;
    }

    .sidebar .nav-link,
    .logout-link {
        flex: 0 0 auto;
        width: 112px !important;
        min-height: 68px;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        padding: 9px 8px;
        text-align: center !important;
        white-space: normal;
        line-height: 1.15;
        scroll-snap-align: start;
    }

    .sidebar .nav-link i {
        width: auto;
        font-size: 22px;
        line-height: 1;
    }

    .sidebar .nav-link .sidebar-label {
        display: block;
        max-width: 96px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 13px;
    }

    .sidebar-collapsed .sidebar-label,
    .sidebar-collapsed .sidebar-user {
        opacity: 1;
        width: auto;
        pointer-events: auto;
    }

    .sidebar-collapsed .sidebar .nav-link {
        justify-content: center;
        gap: 5px;
        padding: 9px 8px;
    }

    .content {
        padding: 18px;
    }
}

@media (max-width: 420px) {
    .sidebar {
        padding-left: 10px;
        padding-right: 10px;
    }

    .brand {
        font-size: 18px;
    }

    .sidebar .nav-link,
    .logout-link {
        width: 98px !important;
        min-height: 64px;
    }

    .sidebar .nav-link .sidebar-label {
        max-width: 84px;
        font-size: 12px;
    }

    .content {
        padding: 14px 10px;
    }
}

@media (max-width: 599.98px), (min-width: 600px) and (max-width: 1024px) and (orientation: portrait) {
    .app-shell,
    .app-shell.sidebar-collapsed {
        display: block;
        min-height: 100vh;
    }

    .sidebar {
        display: none !important;
    }

    .content {
        width: 100%;
        max-width: 100%;
        padding: 12px 10px 18px;
    }

    .mobile-nav {
        display: block;
        position: relative;
        margin: 0 0 14px;
        z-index: 60;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 8px 10px;
        background: #fff;
        border: 1px solid rgba(148, 163, 184, .34);
        border-radius: 14px;
        box-shadow: 0 6px 16px rgba(30, 136, 229, .10);
    }

    .mobile-topbar-brand {
        display: flex;
        align-items: center;
        gap: 9px;
        min-width: 0;
        color: #17324d;
        text-decoration: none;
    }

    .mobile-topbar-logo {
        width: 32px;
        height: 32px;
        border-radius: 9px;
        flex: 0 0 auto;
    }

    .mobile-topbar-name {
        font-weight: 800;
        font-size: .95rem;
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-topbar-toggle {
        flex: 0 0 auto;
        width: 42px;
        height: 42px;
        border: 1px solid rgba(148, 163, 184, .38);
        border-radius: 12px;
        background: #f8fbff;
        color: #17324d;
        font-size: 1.4rem;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-nav.open .mobile-topbar-toggle {
        background: #1e88e5;
        border-color: #1e88e5;
        color: #fff;
    }

    .mobile-menu-wrapper {
        display: none;
        position: absolute;
        top: calc(100% + 6px);
        left: 0;
        right: 0;
        z-index: 61;
        padding: 8px;
        background: #fff;
        border: 1px solid rgba(148, 163, 184, .34);
        border-radius: 14px;
        box-shadow: 0 18px 38px rgba(15, 23, 42, .18);
    }

    .mobile-nav.open .mobile-menu-wrapper {
        display: block;
    }

    .mobile-menu-container {
        display: grid;
        gap: 6px;
    }

    .mobile-menu-card {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 46px;
        border-radius: 11px;
        padding: 9px 12px;
        text-align: left;
        border: 2px solid transparent;
        cursor: pointer;
        color: #17324d;
        text-decoration: none;
    }

    .mobile-menu-card.active {
        border-color: rgba(30, 136, 229, .42);
        box-shadow: 0 5px 12px rgba(30, 136, 229, .16);
    }

    .mobile-menu-card i {
        font-size: 1.2rem;
        line-height: 1;
        flex: 0 0 auto;
    }

    .mobile-menu-card span {
        font-size: .92rem;
        font-weight: 800;
        line-height: 1.15;
    }

    /* มือถือ: ซ่อนหัวข้อหน้า (ชื่อเมนู/ชื่อ workspace/คำอธิบาย) ให้เนื้อหาขึ้นมาชิดด้านบน */
    .page-title {
        display: none;
    }
}

@media (min-width: 600px) and (max-width: 1024px) and (orientation: portrait) {
    .content {
        padding: 18px 16px 24px;
    }

    .mobile-nav {
        margin-bottom: 18px;
    }

    .mobile-menu-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .mobile-topbar-name {
        font-size: 1.05rem;
    }

    .mobile-menu-card {
        min-height: 54px;
        padding: 11px 14px;
    }

    .mobile-menu-card i {
        font-size: 1.4rem;
    }

    .mobile-menu-card span {
        font-size: 1rem;
    }
}
