/* ============================================================
   SAISEE Service — Shared UI Foundation (app.css)
   โหลดเป็นไฟล์ CSS แรกของทุกหน้า (ก่อน Bootstrap / inline style)
   มีเฉพาะ: tokens, nav, toast, modal, input, table-scroll
   ไม่แตะ component เฉพาะหน้า (ให้แต่ละหน้าจัดเองตาม tokens)
   ============================================================ */

/* ===== Design Tokens v2 — ดำนุ่มนวล สบายตา ===== */
:root {
    --bg-main: #10141a;
    --bg-card: #171c24;
    --bg-inset: #0c0f14;
    --border-color: #2a3140;
    --border-soft: #1f2530;

    --text-main: #e6edf3;
    --text-muted: #9aa7b5;

    --accent-blue: #4c8dff;
    --accent-blue-soft: rgba(76, 141, 255, 0.15);
    --accent-green: #2ea043;
    --accent-orange: #d29922;
    --danger: #e5534b;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    --card-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    --card-shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* ===== Unified Top Nav ===== */
.app-nav {
    position: fixed;
    top: 17px;
    right: 28px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 14px;
    background: rgba(244, 246, 248, 0.9);
    border: 1px solid rgba(27, 31, 36, 0.1);
    box-shadow: 0 14px 30px rgba(22, 27, 34, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(18px) saturate(135%);
    -webkit-backdrop-filter: blur(18px) saturate(135%);
    max-width: calc(100vw - 20px);
    overflow-x: auto;
    scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.app-nav .nav-btn {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: #4b5563;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    box-shadow: none;
    white-space: nowrap;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.app-nav .nav-btn i {
    width: 18px;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #4b5563;
    font-size: 1rem;
}

.app-nav .nav-btn:hover {
    background: rgba(255, 255, 255, 0.7);
    color: #1f2937;
    border-color: rgba(27, 31, 36, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.app-nav .nav-btn:hover i { color: #1f2937; }

.app-nav .nav-btn.active {
    background: linear-gradient(180deg, #ffffff 0%, #e9edf2 100%);
    color: #1f2937;
    border-color: rgba(27, 31, 36, 0.1);
    box-shadow: 0 8px 18px rgba(22, 27, 34, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.98);
}

.app-nav .nav-btn.active i { color: #111827; }

@media (max-width: 768px) {
    .app-nav {
        top: 10px;
        right: 10px;
        left: 10px;
        justify-content: space-between;
        gap: 4px;
        padding: 6px;
    }
    .app-nav .nav-btn {
        flex: 1 1 0;
        padding: 9px 8px;
        font-size: 0.78rem;
    }
    .app-nav .nav-btn span { display: none; }
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 76px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
    width: min(480px, calc(100vw - 32px));
}

.toast-msg {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius);
    font-family: 'Kanit', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--card-shadow-hover);
    pointer-events: auto;
    text-align: center;
    animation: toast-in 0.25s ease, toast-out 0.3s ease 3.7s forwards;
    max-width: 100%;
}

.toast-msg.success { background: var(--accent-green); color: #fff; border: 1px solid #2ea043; }
.toast-msg.error   { background: var(--danger); color: #fff; border: 1px solid #f85149; }
.toast-msg.info    { background: var(--accent-blue); color: #fff; border: 1px solid #58a6ff; }
.toast-msg.warning { background: var(--accent-orange); color: #10141a; border: 1px solid #e3b341; }

@keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* ===== Modal (confirm / prompt / info) ===== */
.app-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    animation: modal-fade 0.2s ease;
}

.app-modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--card-shadow-hover);
    animation: modal-pop 0.25s ease;
}

.app-modal h4 {
    margin: 0 0 var(--space-3);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    font-family: 'Kanit', sans-serif;
}

.app-modal p {
    margin: 0 0 var(--space-5);
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-line;
    font-family: 'Kanit', sans-serif;
}

.app-modal input.app-modal-input {
    width: 100%;
    margin: 0 0 var(--space-5);
    padding: 10px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: 'Kanit', sans-serif;
    font-size: 0.95rem;
    outline: none;
    box-sizing: border-box;
}

.app-modal input.app-modal-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-soft);
}

.app-modal .modal-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-pop { from { opacity: 0; transform: scale(0.95) translateY(8px); } }

/* ===== Buttons ===== */
.btn-app {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Kanit', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.1s ease;
}

.btn-app:hover { filter: brightness(1.1); }
.btn-app:active { transform: scale(0.97); }

.btn-app.primary { background: var(--accent-blue); color: #fff; }
.btn-app.success { background: var(--accent-green); color: #fff; }
.btn-app.danger  { background: var(--danger); color: #fff; }
.btn-app.ghost {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

/* ===== Form baseline ===== */
input.app-input, select.app-input {
    background: var(--bg-inset);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    padding: 8px 12px;
    font-family: 'Kanit', sans-serif;
    font-size: 0.9rem;
}

input.app-input:focus, select.app-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-soft);
}

/* ===== Responsive table: scroll + sticky first column ===== */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-scroll table { border-collapse: collapse; }

.table-scroll td:first-child, .table-scroll th:first-child {
    position: sticky;
    left: 0;
    background: var(--bg-inset);
    z-index: 1;
}

.table-scroll th:first-child {
    background: var(--bg-card);
    z-index: 2;
}
