/* TotalTH — Main app shell (ระบบหลัก แยกจากโมดูลแชท) */
:root {
    --td-primary: #06c755;
    --td-primary-dark: #05a847;
    --td-ink: #0f172a;
    --td-muted: #64748b;
    --td-border: #e2e8f0;
    --td-surface: #ffffff;
    --td-bg: #f1f5f9;
    --td-sidebar-w: 248px;
    --td-topbar-h: 56px;
    --td-radius: 12px;
    --td-shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .04);
    --td-font: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body.td-app,
body.td-guest {
    font-family: var(--td-font);
    font-size: 14px;
    color: var(--td-ink);
    background: var(--td-bg);
    -webkit-font-smoothing: antialiased;
}

a { color: #2563eb; text-decoration: none; }
a:hover { color: #1d4ed8; }

/* ── App shell ── */
.td-shell {
    display: flex;
    min-height: 100vh;
}

.td-sidebar {
    width: var(--td-sidebar-w);
    flex-shrink: 0;
    background: var(--td-surface);
    border-right: 1px solid var(--td-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    transition: transform .2s ease;
}

.td-sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--td-border);
    text-decoration: none !important;
    color: var(--td-ink) !important;
}
.td-sidebar__brand img {
    max-height: 36px;
    width: auto;
}
.td-sidebar__brand span {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.02em;
}

.td-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px 20px;
}

.td-nav-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #94a3b8;
    padding: 12px 12px 6px;
    margin: 0;
}

.td-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    color: #475569 !important;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 600;
    transition: background .15s, color .15s;
    margin-bottom: 2px;
}
.td-nav-item i {
    width: 18px;
    text-align: center;
    font-size: 14px;
    opacity: .85;
}
.td-nav-item:hover {
    background: #f8fafc;
    color: var(--td-ink) !important;
}
.td-nav-item.is-active {
    background: #ecfdf3;
    color: #15803d !important;
}
.td-nav-item.is-active i { color: var(--td-primary); }

.td-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--td-sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.td-topbar {
    height: var(--td-topbar-h);
    flex-shrink: 0;
    background: var(--td-surface);
    border-bottom: 1px solid var(--td-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.td-topbar__left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.td-topbar__menu-btn {
    display: none;
    border: 1px solid var(--td-border);
    background: var(--td-surface);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    color: var(--td-ink);
}

.td-topbar__title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.td-topbar__right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.td-topbar__chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--td-border);
    background: #f8fafc;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    text-decoration: none !important;
}
.td-topbar__chip:hover {
    background: #f1f5f9;
    color: var(--td-ink) !important;
}
.td-topbar__chip i { font-size: 13px; }

.td-user-menu { position: relative; }
.td-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--td-border);
    background: var(--td-surface);
    border-radius: 999px;
    padding: 5px 12px 5px 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--td-ink);
}
.td-user-btn__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ecfdf3;
    color: var(--td-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
.td-user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: var(--td-surface);
    border: 1px solid var(--td-border);
    border-radius: var(--td-radius);
    box-shadow: 0 12px 32px rgba(15, 23, 42, .12);
    padding: 6px;
    z-index: 1050;
}
.td-user-dropdown.is-open { display: block; }
.td-user-dropdown a,
.td-user-dropdown button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    text-decoration: none;
    cursor: pointer;
    text-align: left;
}
.td-user-dropdown a:hover,
.td-user-dropdown button:hover {
    background: #f8fafc;
    color: var(--td-ink);
}
.td-user-dropdown hr {
    border: none;
    border-top: 1px solid var(--td-border);
    margin: 4px 0;
}

.td-content {
    flex: 1;
    padding: 20px 24px 28px;
    width: 100%;
    min-width: 0;
}

.td-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--td-border);
    background: var(--td-surface);
    font-size: 11px;
    color: var(--td-muted);
}

.td-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .4);
    z-index: 1035;
}

/* ── Auth (login/register) ── */
body.td-guest {
    background: linear-gradient(160deg, #f0fdf4 0%, #f8fafc 45%, #eff6ff 100%);
}

.td-auth-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px 20px;
}

.td-auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--td-surface);
    border: 1px solid var(--td-border);
    border-radius: 16px;
    box-shadow: var(--td-shadow);
    padding: 28px 28px 24px;
}

.td-auth-logo {
    text-align: center;
    margin-bottom: 20px;
}
.td-auth-logo img {
    max-width: 180px;
    height: auto;
}

.td-auth-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin: 0 0 20px;
    color: var(--td-ink);
}

.td-auth-card .form-group { margin-bottom: 14px; }
.td-auth-card label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
}
.td-auth-card .form-control {
    border-radius: 10px;
    border: 1px solid var(--td-border);
    padding: 10px 12px;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
.td-auth-card .form-control:focus {
    border-color: var(--td-primary);
    box-shadow: 0 0 0 3px rgba(6, 199, 85, .15);
    outline: none;
}

.td-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .12s, box-shadow .12s;
    text-decoration: none !important;
}
.td-btn--primary {
    background: linear-gradient(135deg, #06c755, #00b900);
    color: #fff !important;
    width: 100%;
}
.td-btn--primary:hover {
    box-shadow: 0 4px 14px rgba(6, 199, 85, .3);
    transform: translateY(-1px);
    color: #fff !important;
}
.td-btn--ghost {
    background: var(--td-surface);
    color: #374151 !important;
    border: 1px solid var(--td-border);
    width: 100%;
    margin-top: 10px;
}
.td-btn--ghost:hover {
    background: #f8fafc;
    color: var(--td-ink) !important;
}

.td-auth-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 11px;
    color: var(--td-muted);
    max-width: 480px;
    line-height: 1.5;
}

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

/* ── Legacy panel reset inside shell ── */
.td-content .panel,
.td-content .panel-body {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
}

/* ── Mobile ── */
@media (max-width: 991px) {
    .td-sidebar {
        transform: translateX(-100%);
    }
    .td-sidebar.is-open {
        transform: translateX(0);
    }
    .td-sidebar-overlay.is-open {
        display: block;
    }
    .td-main {
        margin-left: 0;
    }
    .td-topbar__menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .td-content {
        padding: 16px;
    }
    .td-topbar__chip--member {
        display: none;
    }
}
