/* Portal — phong cach "Organization Link Hub": nen sang/trung tinh, card gon, hierarchy ro
   giua He thong (to chuc quan ly) va Cua toi (ca nhan). Toggle Sang/Toi/Theo he thong qua
   [data-theme] tren <html> (xem app.js cycleTheme()). */

:root {
    --bg: #f6f6f4;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #ebebe8;
    --text: #1c1d20;
    --text-muted: #8b8d97;
    --accent: #5b6cf5;
    --accent-text: #ffffff;
    --danger: #e5484d;
    --shadow-sm: 0 1px 2px rgba(20, 20, 25, 0.04);
    --shadow-md: 0 10px 30px rgba(20, 20, 25, 0.08);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0d1117;
    --bg-elevated: #151a21;
    --card: #171c24;
    --border: #262c36;
    --text: #eceef1;
    --text-muted: #8b93a1;
    --accent: #7c8cff;
    --accent-text: #10111a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d1117;
        --bg-elevated: #151a21;
        --card: #171c24;
        --border: #262c36;
        --text: #eceef1;
        --text-muted: #8b93a1;
        --accent: #7c8cff;
        --accent-text: #10111a;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden; /* chan cuon ngang neu co phan tu nao tinh sai be rong tren man hinh nho */
}

body {
    font-family: "Pretendard", Inter, -apple-system, BlinkMacSystemFont, "Noto Sans KR", "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

button, input { font-family: inherit; }

a { color: inherit; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 24px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
    cursor: pointer;
    user-select: none;
    flex: none;
}
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

.nav-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 11px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--card); color: var(--text); border-color: var(--border); }
.icon-btn.is-active { background: var(--card); color: var(--accent); border-color: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.lang-btn { font-size: 11px; font-weight: 800; letter-spacing: .02em; width: auto; padding: 0 9px; }

.account-wrap { position: relative; min-width: 0; }

.avatar-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    max-width: 180px;
}
.avatar-img, .avatar-fallback {
    width: 28px; height: 28px; border-radius: 50%;
    flex: none;
    object-fit: cover;
    background: var(--accent);
    color: var(--accent-text);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
}
.avatar-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dropdown, .card-menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    min-width: 190px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 6px;
    display: flex; flex-direction: column; gap: 2px;
    z-index: 40;
}
.dropdown .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown .who .name { font-weight: 700; font-size: 13px; }
.dropdown .who .email { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.dropdown-item {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    background: none; border: none; text-align: left;
    font-size: 13px; color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.dropdown-item:hover { background: var(--card); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item svg { width: 15px; height: 15px; flex: none; }

#gbtn-nav { line-height: 0; }

/* ---------- Layout ---------- */

main.container {
    flex: 1;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 32px 64px;
}

/* ---------- Welcome / search ---------- */

.welcome { margin-bottom: 30px; }
.welcome-head {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.welcome-head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.welcome-head p { margin: 6px 0 0; font-size: 14px; color: var(--text-muted); }
.welcome-head .admin-hint { color: var(--accent); font-weight: 600; }
.welcome-clock {
    font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.search-wrap {
    display: flex; align-items: center; gap: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}
.search-wrap svg { width: 18px; height: 18px; color: var(--text-muted); flex: none; }
.search-wrap input {
    flex: 1; min-width: 0;
    border: none; background: none; outline: none;
    font-size: 14px; color: var(--text);
}
.search-wrap input::placeholder { color: var(--text-muted); }

.kbd-hint {
    display: flex; align-items: center; gap: 3px; flex: none;
    border: none; background: none; cursor: pointer; padding: 2px;
}
kbd {
    font-family: inherit; font-size: 11px; font-weight: 700; color: var(--text-muted);
    background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
    padding: 2px 6px; line-height: 1.4;
}

/* ---------- Sections ---------- */

.section { margin-bottom: 34px; }
.section-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.section-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.section-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Card grid (He thong / Cua toi) ---------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
    gap: 12px;
}

.link-card {
    position: relative;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.link-card.is-hidden { display: none; }
.link-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }

.card-body {
    display: block;
    padding: 0 14px 14px;
    text-decoration: none;
    color: inherit;
    min-height: 84px;
}
.card-icon {
    width: 38px; height: 38px; border-radius: 11px; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
    background: var(--bg); color: var(--text-muted);
    overflow: hidden;
    margin-bottom: 12px;
}
.card-icon.is-image { background: var(--bg); padding: 6px; }
.card-icon img { width: 100%; height: 100%; object-fit: contain; }
.card-title { font-size: 14.5px; font-weight: 700; line-height: 1.3; }
.card-desc {
    font-size: 12.5px; color: var(--text-muted); margin-top: 3px; line-height: 1.35;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* Hang nut hanh dong (yeu thich + kebab) nam TREN <a>, khong long ben trong no - xem ghi chu
   o renderLinkCard() trong app.js. Mac dinh mo nhat, ro khi hover the/focus - luon hien tren
   thiet bi cam ung (khong co :hover that su). */
.card-actions-row {
    display: flex; align-items: center; justify-content: flex-end; gap: 6px;
    padding: 8px 8px 0;
    opacity: 0; transition: opacity .12s ease;
}
.link-card:hover .card-actions-row, .card-actions-row:focus-within { opacity: 1; }
@media (hover: none) {
    .card-actions-row { opacity: 1; }
}
.card-fav-btn, .card-menu-btn {
    width: 26px; height: 26px; border-radius: 8px; flex: none;
    border: 1px solid var(--border); background: var(--bg-elevated);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.card-fav-btn svg, .card-menu-btn svg { width: 14px; height: 14px; }
.card-fav-btn.is-fav { color: #e0a72e; border-color: color-mix(in srgb, #e0a72e 40%, var(--border)); }
.card-fav-btn.is-fav svg { fill: currentColor; }
.card-menu-wrap { position: relative; }
.card-menu-wrap .card-menu { top: calc(100% + 6px); }

.empty-hint {
    grid-column: 1 / -1;
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
}

.empty-card {
    grid-column: 1 / -1;
    text-align: center;
    padding: 36px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
}
.empty-card-icon { font-size: 28px; margin-bottom: 10px; }
.empty-card-title { font-size: 15px; font-weight: 700; }
.empty-card-sub { font-size: 13px; color: var(--text-muted); margin-top: 6px; max-width: 320px; margin-inline: auto; }
.empty-card .btn { margin-top: 16px; }

/* ---------- Settings view ---------- */

.settings-grid { display: flex; flex-direction: column; gap: 22px; max-width: 640px; margin: 0 auto; }

.panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.panel-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; margin-bottom: 14px; }
.panel-title .badge { margin-left: 6px; }

.profile-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; row-gap: 10px; }
.profile-row .avatar-img, .profile-row .avatar-fallback { width: 52px; height: 52px; font-size: 18px; }
.profile-row .info { flex: 1; min-width: 120px; }
.profile-row .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-row .email { font-size: 13px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
    display: inline-block;
    font-size: 10px; font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    color: var(--accent);
    text-transform: none;
    letter-spacing: 0;
}

.link-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 6px;
    border-bottom: 1px solid var(--border);
}
.link-row:last-child { border-bottom: none; }
.link-row .swatch { width: 34px; height: 34px; border-radius: 9px; flex: none; display:flex; align-items:center; justify-content:center; overflow:hidden; font-size: 12px; font-weight: 700; color: #fff; }
.link-row .swatch img { width: 100%; height: 100%; object-fit: contain; background: var(--card); }
.link-row .meta { flex: 1; min-width: 0; }
.link-row .meta .t { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row .meta .u, .link-row .meta .d { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row .actions { display: flex; gap: 3px; flex: none; }

.iconbtn-sm {
    width: 28px; height: 28px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--card);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.iconbtn-sm:hover { color: var(--text); }
.iconbtn-sm.danger:hover { color: var(--danger); border-color: var(--danger); }
.iconbtn-sm svg { width: 13px; height: 13px; }
.iconbtn-sm:disabled { opacity: .3; cursor: default; }

.add-link-btn {
    width: 100%; margin-top: 12px;
    padding: 10px; border-radius: var(--radius-sm);
    border: 1.5px dashed var(--border);
    background: none; color: var(--text-muted);
    font-size: 13px; font-weight: 600; cursor: pointer;
}
.add-link-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(10, 10, 12, .45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal {
    width: 100%; max-width: 400px;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 22px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.field input[type="text"], .field input[type="url"] {
    width: 100%; padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 16px; /* >=16px de Safari iOS khong tu zoom khi focus vao input */
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
    flex: 1; padding: 9px; border: none; background: var(--card); color: var(--text-muted);
    font-size: 13px; font-weight: 600; cursor: pointer;
}
.segmented button.active { background: var(--accent); color: var(--accent-text); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.swatch-btn {
    width: 30px; height: 30px; border-radius: 9px; border: 2px solid transparent;
    cursor: pointer;
}
.swatch-btn.active { border-color: var(--text); }

.dropzone {
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12.5px;
    position: relative;
}
.dropzone.has-image { border-style: solid; }
.dropzone img { max-width: 100%; max-height: 90px; object-fit: contain; margin-bottom: 6px; }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.tile-preview {
    width: 84px; height: 68px; margin: 0 auto 14px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    text-align: center; font-size: 11px; font-weight: 700; padding: 6px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.tile-preview img { width: 60%; height: 60%; object-fit: contain; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.btn {
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600;
    cursor: pointer;
}
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: none; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--card); }
.btn-danger-outline { background: none; border-color: var(--danger); color: var(--danger); }

.form-error { font-size: 12px; color: var(--danger); margin-top: 8px; }

.footer-note {
    text-align: center; font-size: 11.5px; color: var(--text-muted);
    padding: 20px 0 0;
}

/* ---------- Picker (chon tu Thu vien de them vao Cua toi) ---------- */

.picker-modal { max-width: 460px; }
.picker-section-label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; margin-bottom: 10px; }
.picker-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; margin-bottom: 14px; }
.picker-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--card);
    cursor: pointer; text-align: left;
}
.picker-item:hover:not(:disabled) { border-color: var(--accent); }
.picker-item:disabled, .picker-item.is-added { cursor: default; opacity: .6; }
.picker-item .card-icon { width: 32px; height: 32px; font-size: 12px; border-radius: 9px; }
.picker-item-meta { flex: 1; min-width: 0; }
.picker-item-meta .t { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item-meta .d { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-added-badge { font-size: 11px; font-weight: 700; color: var(--accent); flex: none; }

/* ---------- Command palette (Ctrl+K) ---------- */

.palette-modal { max-width: 520px; padding: 12px; }
.palette-search {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.palette-search svg { width: 18px; height: 18px; color: var(--text-muted); flex: none; }
.palette-search input { flex: 1; min-width: 0; border: none; background: none; outline: none; font-size: 14.5px; color: var(--text); }
.palette-search kbd { flex: none; }
.palette-list { max-height: 400px; overflow-y: auto; padding: 0 4px 4px; }
.palette-list .picker-section-label { padding: 8px 8px 4px; margin-bottom: 0; }
.palette-item {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 9px 8px; border-radius: var(--radius-sm);
    border: none; background: none; cursor: pointer; text-align: left;
}
.palette-item .card-icon { width: 30px; height: 30px; font-size: 12px; border-radius: 9px; margin-bottom: 0; }
.palette-item.active, .palette-item:hover { background: var(--card); }
.palette-item-meta { flex: 1; min-width: 0; }
.palette-item-meta .t { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item-meta .d { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 720px) {
    main.container { padding: 22px 18px 56px; }
    .card-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .welcome-head h1 { font-size: 21px; }
    /* Nut Google Sign-In tren nav khong co giga, du dai lam tran ngang topbar tren man hinh
       hep - khach van dang nhap duoc binh thuong qua nut hero o giua trang "Cua toi". */
    #gbtn-nav { display: none; }
}

@media (max-width: 480px) {
    .topbar { padding: 10px 14px; }
    .welcome-head { flex-direction: column; align-items: flex-start; }
    .card-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    /* Man hinh hep: bo ten canh avatar, chi giu vong tron, tranh tran ngang topbar */
    .avatar-btn span { display: none; }
    .avatar-btn { padding: 4px; }
    .swatch-btn { width: 34px; height: 34px; }
    .swatches { gap: 10px; }
    .kbd-hint { display: none; } /* thieu cho, "Ctrl K" cung khong dung duoc tot tren mobile */
}
