/* ===== CDN Assets Manager — Dark Theme ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0e1015;
    --surface: #14161d;
    --surface-2: #191c25;
    --surface-3: #1f2330;
    --border: #262a36;
    --border-strong: #333949;
    --text: #edeff4;
    --text-muted: #949cb0;
    --text-faint: #5f6779;
    --primary: #6366f1;
    --primary-2: #8b5cf6;
    --primary-hover: #7c7ff5;
    --primary-soft: rgba(99, 102, 241, 0.14);
    --primary-soft-text: #a5b4fc;
    --accent: #34d399;
    --accent-soft: rgba(52, 211, 153, 0.14);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --success: #34d399;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.6);
    --glow: 0 0 0 1px rgba(99, 102, 241, 0.35), 0 4px 20px rgba(99, 102, 241, 0.25);
}

html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Segoe UI', 'Leelawadee UI', 'Noto Sans Thai', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.55;
}

::selection { background: rgba(99, 102, 241, 0.4); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2f3d; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

a { color: var(--primary-soft-text); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-muted); font-weight: 400; font-size: 0.85em; }
.inline { display: inline; }
.hidden-form { display: none; }
.spacer { flex: 1; }
code {
    background: #1b1f2a;
    border: 1px solid var(--border);
    padding: 1px 6px;
    border-radius: 5px;
    font-size: 0.88em;
    word-break: break-all;
    color: #c7d2fe;
}
.ic { flex-shrink: 0; vertical-align: -3px; }

/* ===== ปุ่ม ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 15px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    text-decoration: none;
}
.btn:hover { background: var(--surface-3); border-color: #414a61; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { filter: brightness(1.12); box-shadow: 0 4px 18px rgba(99, 102, 241, 0.5); }
.btn-danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
.btn-danger:hover { background: var(--danger-soft); border-color: rgba(248, 113, 113, 0.55); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--text); }
.btn-small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    border-radius: 7px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-mini:hover { color: var(--primary-soft-text); background: var(--primary-soft); border-color: var(--primary); }

/* ===== แถบบน ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    height: 62px;
    background: rgba(20, 22, 29, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--text);
}
.logo-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 14px rgba(99, 102, 241, 0.45);
}
.search-form { flex: 1; max-width: 460px; position: relative; }
.search-form .ic {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}
.topbar .search-form input {
    width: 100%;
    padding: 9px 14px 9px 40px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.topbar .search-form input::placeholder { color: var(--text-faint); }
.topbar .search-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
.topbar-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.sidebar-toggle { display: none; }

/* ===== โครงหน้า ===== */
.layout { display: flex; min-height: calc(100vh - 62px); }

.sidebar {
    width: 252px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
}
.sidebar-section { margin-bottom: 22px; }
.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-faint);
    padding: 0 10px 8px;
}
.sidebar-empty { padding: 4px 10px; color: var(--text-faint); font-size: 13px; }
.side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 11px;
    border-radius: 9px;
    color: var(--text);
    margin-bottom: 2px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
}
.side-link:hover { background: var(--surface-2); text-decoration: none; }
.side-link.active {
    background: var(--primary-soft);
    color: var(--primary-soft-text);
    border-color: rgba(99, 102, 241, 0.3);
}
.side-link .ic { color: var(--text-faint); }
.side-link.active .ic { color: var(--primary-soft-text); }
.side-link .count {
    margin-left: auto;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-3);
    border-radius: 999px;
    padding: 1px 9px;
}
.side-link.active .count { color: var(--primary-soft-text); background: rgba(99, 102, 241, 0.25); }

.content { flex: 1; padding: 24px 28px; min-width: 0; }
.content-narrow { max-width: 780px; margin: 0 auto; }
.content-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.content h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}
.content h1 .ic { color: var(--primary-soft-text); }
.content h2 { font-size: 16px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.content h2 .ic { color: var(--primary-soft-text); }
.content h3 { font-size: 14.5px; font-weight: 600; margin: 18px 0 10px; }

/* ===== แถบกรองหมวดหมู่ ===== */
.cat-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.cat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.cat-chip:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.cat-chip.active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary-soft-text);
}
.chip-count { font-size: 11.5px; opacity: 0.75; }
.cat-add { border-style: dashed; }
.cat-add:hover { color: var(--primary-soft-text); border-color: var(--primary); }
.cat-del { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
.cat-del:hover { background: var(--danger-soft); color: var(--danger); }

/* ===== แจ้งเตือน ===== */
.flash {
    padding: 11px 16px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    border: 1px solid;
    font-size: 14px;
}
.flash-success { background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.35); color: #6ee7b7; }
.flash-error   { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.35); color: #fca5a5; }
.flash-warn    { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.3); color: #fcd34d; }

/* ===== การ์ดไฟล์ ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}
.card:hover {
    border-color: rgba(99, 102, 241, 0.45);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.card-preview {
    height: 140px;
    background: repeating-conic-gradient(#181b24 0% 25%, #12141c 0% 50%) 0 0 / 18px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.card-preview { position: relative; }
.card-preview img, .card-preview video { max-width: 100%; max-height: 100%; object-fit: contain; }
.video-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    background: rgba(5, 6, 10, 0.75);
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    pointer-events: none;
}
.file-icon {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--primary-soft-text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 12px 16px;
}
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.card-name {
    font-size: 13.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}
.card-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 12.5px;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.card-meta .ic { vertical-align: -2px; color: var(--text-faint); }
.tag {
    background: var(--primary-soft);
    color: var(--primary-soft-text);
    border-radius: 6px;
    padding: 1px 8px;
    font-size: 11.5px;
    font-weight: 600;
}
.tag-cat { background: var(--accent-soft); color: #6ee7b7; }

/* แถบลิงก์ CDN บนการ์ด — คลิกเพื่อคัดลอก */
.link-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    margin-top: 2px;
    padding: 7px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--primary-soft-text);
    font-family: Consolas, 'Courier New', monospace;
    font-size: 11.5px;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.link-chip .ic { color: var(--text-faint); }
.link-chip .link-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;          /* ตัดข้อความด้านหน้า โชว์ท้ายลิงก์ (ชื่อไฟล์) */
    text-align: left;
}
.link-chip:hover { border-color: var(--primary); background: rgba(99, 102, 241, 0.08); }
.link-chip.copied {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}
.link-chip.copied .ic { color: var(--accent); }

.card-actions { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.btn-copy.copied { background: var(--accent); border-color: var(--accent); color: #06281c; }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 64px 20px;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}
.empty-state .ic { color: var(--text-faint); margin-bottom: 10px; }

/* ===== Dialog ===== */
dialog {
    margin: auto;
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    padding: 0;
    width: min(460px, calc(100vw - 32px));
    box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(5, 6, 10, 0.7); backdrop-filter: blur(3px); }
.dialog-form { padding: 24px; }
.dialog-form h2 { font-size: 17px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
.dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
    align-items: center;
}

/* ===== ฟอร์ม ===== */
label { display: block; margin-bottom: 14px; font-size: 13.5px; font-weight: 600; color: #c3c9d8; }
input[type="text"], input[type="password"], input[type="search"],
input[type="url"], select {
    width: 100%;
    margin-top: 6px;
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-weight: 400;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--text-faint); }
input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
select option { background: var(--surface-2); }
.hint { font-size: 12.5px; font-weight: 400; color: var(--text-muted); margin: 6px 0 14px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row input, .form-row select { width: auto; flex: 1; min-width: 150px; margin-top: 0; }

/* ===== Dropzone อัปโหลด ===== */
.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--bg);
    padding: 28px 16px;
    text-align: center;
    margin-top: 8px;
    color: var(--text-muted);
    transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone p { margin-bottom: 4px; }
.upload-list { list-style: none; margin-top: 12px; max-height: 220px; overflow-y: auto; }
.upload-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}
.upload-list .u-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-status-wait { color: var(--text-muted); }
.u-status-ok { color: var(--success); font-weight: 600; }
.u-status-fail { color: var(--danger); font-weight: 600; }

/* ===== หน้า Login ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background:
        radial-gradient(700px 400px at 15% 0%, rgba(99, 102, 241, 0.12), transparent 60%),
        radial-gradient(700px 400px at 85% 100%, rgba(139, 92, 246, 0.1), transparent 60%),
        var(--bg);
}
.login-box {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    padding: 36px 32px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.login-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 17px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    margin-bottom: 14px;
    box-shadow: 0 4px 24px rgba(99, 102, 241, 0.5);
}
.login-box h1 { font-size: 19px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.login-sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: 22px; }
.login-box form { text-align: left; }
.login-box .flash { text-align: left; }

/* ===== หน้า Settings ===== */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    margin: 18px 0;
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: var(--surface-2);
}
.table tr:last-child td { border-bottom: none; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translate(-50%, 80px);
    background: var(--surface-3);
    border: 1px solid var(--accent);
    color: #a7f3d0;
    padding: 10px 22px;
    border-radius: 999px;
    font-size: 13.5px;
    opacity: 0;
    transition: transform 0.25s, opacity 0.25s;
    pointer-events: none;
    z-index: 100;
    max-width: calc(100vw - 40px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ===== มือถือ ===== */
@media (max-width: 760px) {
    .sidebar-toggle { display: inline-flex; }
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; }
    .search-form { order: 3; max-width: none; flex-basis: 100%; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 0.2s;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 16px 14px; }
    .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .card-preview { height: 110px; }
}
