/* ── GS Chat — UTCC Graduate School CI ── */

:root {
    --primary: #d4891c;
    --primary-dark: #b8741a;
    --primary-light: #f0a83c;
    --primary-gradient: linear-gradient(135deg, #c77b18 0%, #e8a838 50%, #f5c563 100%);
    --accent: #1a1a1a;
    --accent-light: #2d2d2d;
    --bg-main: #f7f5f2;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e2dc;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --sidebar-w: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Noto Sans Thai', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ── Login / Register ── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    width: 700px;
    height: 700px;
    background: rgba(26, 26, 26, 0.06);
    border-radius: 50%;
    top: -250px;
    right: -250px;
}

.login-wrapper::after {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: rgba(26, 26, 26, 0.04);
    border-radius: 50%;
    bottom: -150px;
    left: -150px;
}

.login-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 48px 40px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .logo-icon {
    width: 72px;
    height: 72px;
    background: var(--accent);
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--primary-light);
    font-size: 28px;
    font-weight: 800;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.3px;
}

.login-logo .logo-sub {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    margin-top: 2px;
    letter-spacing: 0.5px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 6px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    font-family: inherit;
    background: white;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(212, 137, 28, 0.12);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
}

.btn-primary:hover {
    background: var(--accent-light);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    width: 100%;
    padding: 12px;
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
    display: block;
    text-align: center;
}

.btn-secondary:hover {
    border-color: var(--accent);
}

.form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.form-footer label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

.form-footer label input {
    accent-color: var(--primary);
}

.form-footer a {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.form-footer a:hover {
    text-decoration: underline;
}

.form-divider {
    text-align: center;
    margin: 20px 0;
    font-size: 13px;
    color: var(--text-muted);
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 20px;
}

.alert-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #059669;
    border: 1px solid #bbf7d0;
}

/* ── Layout ── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--accent);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: transform 0.3s;
}

.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
}

.sidebar-brand h2 {
    font-size: 18px;
    font-weight: 700;
}

.sidebar-brand small {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    display: block;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.3);
    padding: 0 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: white;
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-item .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--primary-light);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    color: white;
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.06);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-info .name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info .role {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

/* ── Top bar ── */
.topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar h1 {
    font-size: 20px;
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
    position: relative;
    text-decoration: none;
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-icon .dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid white;
}

/* ── Page content ── */
.page-content {
    padding: 32px;
    flex: 1;
}

/* ── Stat Cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    border: 1px solid var(--border);
    transition: box-shadow 0.2s;
}

.stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.stat-header .label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.stat-icon.orange { background: #fef3c7; color: #d97706; }
.stat-icon.green { background: #d1fae5; color: #059669; }
.stat-icon.amber { background: #fff7ed; color: #c2410c; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-change {
    font-size: 12px;
    font-weight: 600;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ── Cards / Panels ── */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 28px;
}

/* ── Chart placeholder ── */
.chart-placeholder {
    height: 240px;
    background: linear-gradient(180deg, rgba(212, 137, 28, 0.06) 0%, rgba(212, 137, 28, 0.01) 100%);
    border-radius: 8px;
    display: flex;
    align-items: flex-end;
    padding: 0 16px 16px;
    gap: 8px;
}

.chart-bar {
    flex: 1;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 20px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.chart-bar:hover {
    opacity: 1;
}

/* ── Activity list ── */
.activity-list {
    list-style: none;
}

.activity-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}

.activity-dot.orange { background: var(--primary); }
.activity-dot.green { background: var(--success); }
.activity-dot.amber { background: var(--warning); }

/* ── Table ── */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(212, 137, 28, 0.03);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ── Status badge ── */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.status.online { background: #d1fae5; color: #059669; }
.status.offline { background: #fee2e2; color: #dc2626; }
.status.pending { background: #fef3c7; color: #d97706; }
.status.active { background: #fff7ed; color: #c2410c; }

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Messages ── */
.msg-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    height: calc(100vh - 130px);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-card);
}

.msg-list {
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.msg-list-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.msg-search {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
}

.msg-search:focus {
    border-color: var(--primary);
}

.msg-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}

.msg-item:hover { background: rgba(212, 137, 28, 0.04); }
.msg-item.active { background: rgba(212, 137, 28, 0.08); }

.msg-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.msg-preview {
    flex: 1;
    min-width: 0;
}

.msg-preview-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.msg-preview .sender {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-preview .time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.msg-preview .text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-preview .unread-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 8px;
}

.msg-chat {
    display: flex;
    flex-direction: column;
}

.msg-chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.msg-chat-header .name {
    font-weight: 600;
    font-size: 15px;
}

.msg-chat-header .platform {
    font-size: 12px;
    color: var(--text-muted);
}

.msg-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-bubble {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.chat-bubble.incoming {
    background: #f3f4f6;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-bubble.outgoing {
    background: var(--accent);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-bubble .bubble-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
}

.msg-chat-input {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

.msg-chat-input input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}

.msg-chat-input input:focus {
    border-color: var(--primary);
}

.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.btn-send:hover {
    background: var(--accent-light);
}

/* ── Graph API page ── */
.api-status-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 10px;
    margin-bottom: 24px;
}

.api-status-bar.disconnected {
    background: #fef2f2;
    border-color: #fecaca;
}

.api-status-bar .status-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--success);
}

.api-status-bar.disconnected .status-text {
    color: var(--danger);
}

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.config-item {
    margin-bottom: 16px;
}

.config-item label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.config-item .value {
    padding: 10px 14px;
    background: var(--bg-main);
    border-radius: 8px;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
    word-break: break-all;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    font-family: inherit;
    text-decoration: none;
}

.btn-outline {
    background: white;
    border: 1.5px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-filled {
    background: var(--accent);
    color: white;
}

.btn-filled:hover {
    background: var(--accent-light);
}

.btn-danger {
    background: white;
    border: 1.5px solid var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

/* ── Webhook log ── */
.webhook-log {
    list-style: none;
    font-size: 13px;
}

.webhook-log li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.webhook-log li:last-child { border-bottom: none; }

.webhook-method {
    font-size: 11px;
    font-weight: 700;
    font-family: monospace;
    padding: 2px 8px;
    border-radius: 4px;
    background: #dbeafe;
    color: #2563eb;
}

.webhook-method.post { background: #d1fae5; color: #059669; }

.webhook-path {
    font-family: monospace;
    color: var(--text-primary);
}

.webhook-status {
    margin-left: auto;
    font-weight: 600;
}

.webhook-status.ok { color: var(--success); }

/* ── Toggle switch ── */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.toggle-label {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.toggle-label.on { color: var(--success); }
.toggle-label.off { color: var(--text-muted); }

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--success);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* ── Agent badge in chat header ── */
.agent-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
}

.agent-badge.on {
    background: #d1fae5;
    color: #059669;
}

.agent-badge.off {
    background: #f3f4f6;
    color: var(--text-muted);
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .content-grid, .config-grid { grid-template-columns: 1fr; }
    .msg-layout { grid-template-columns: 1fr; }
    .msg-chat { display: none; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar { padding: 12px 16px; }
    .page-content { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
}
