/* === BIẾN TOÀN CỤC === */
:root {
    --font-primary: 'Inter', sans-serif;
    --font-display: 'Orbitron', sans-serif;
    --color-bg-dark: #060b16;
    --color-bg-light: #0e1629;
    --color-bg-panel: #0e1a2f;
    --color-cyan-bright: #00ffff;
    --color-cyan-dim: #00cccc;
    --color-cyan-dark: #00ffff55;
    --color-cyan-glow: #00ffff22;
    --color-red: #ff3355;
    --color-red-dark: #ff0033;
    --color-text-light: #ffffff;
    --color-text-dim: #bbbbbb;
    --border-radius-lg: 20px;
    --border-radius-md: 12px;
    --border-radius-sm: 8px;
    --shadow-glow: 0 0 30px var(--color-cyan-glow);
    --shadow-glow-focus: 0 0 15px var(--color-cyan-dark);
}

/* === RESET VÀ THIẾT LẬP CƠ BẢN === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: radial-gradient(ellipse at center, #0a0f1c 0%, var(--color-bg-dark) 100%);
    color: var(--color-cyan-bright);
    font-family: var(--font-primary);
    padding: 20px;
    margin: 0;
    overflow-x: hidden;
}

.main-container {
    max-width: 1000px;
    margin: auto;
    padding: 20px;
    background: var(--color-bg-light);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-glow);
    position: relative;
}

/* === HEADER === */
.header {
    text-align: center;
    margin-bottom: 20px;
    padding: 24px;
    background: linear-gradient(135deg, var(--color-bg-panel), var(--color-bg-light));
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-cyan-dark);
}

.header h1 {
    font-family: var(--font-display);
    font-size: 32px;
    color: var(--color-text-light);
    text-shadow: 0 0 10px var(--color-cyan-dark);
}

.header p {
    color: var(--color-cyan-dim);
    font-size: 16px;
    margin-top: 8px;
}

/* === USER INFO (DROPDOWN) === */
#user-info-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.user-info-button {
    background: var(--color-bg-panel);
    border: 1px solid var(--color-cyan-dark);
    border-radius: var(--border-radius-md);
    padding: 8px 12px;
    box-shadow: 0 0 15px var(--color-cyan-glow);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
    color: var(--color-text-light);
    font-family: var(--font-primary);
    font-size: 14px;
}

.user-info-button:hover {
    transform: scale(1.03);
    background: var(--color-bg-light);
}

.user-info-button .fa-chevron-down {
    transition: transform 0.3s ease;
}

.user-info-button.open .fa-chevron-down {
    transform: rotate(180deg);
}

.avatar-circle {
    background: linear-gradient(135deg, #00f2fe, #4facfe);
    color: var(--color-bg-dark);
    font-weight: bold;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 0 8px #00ffff88;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    background: var(--color-bg-panel);
    border: 1px solid var(--color-cyan-dark);
    border-radius: var(--border-radius-md);
    padding: 8px;
    box-shadow: 0 0 15px var(--color-cyan-glow);
    z-index: 1000;
    min-width: 160px;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.dropdown-menu button {
    width: 100%;
    padding: 10px 14px;
    background: linear-gradient(145deg, var(--color-red), var(--color-red-dark));
    color: var(--color-text-light);
    border: none;
    border-radius: var(--border-radius-sm);
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 10px #ff3355aa;
    font-family: var(--font-primary);
    transition: background 0.3s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.dropdown-menu button:hover {
    background: #ff3355;
    transform: scale(1.02);
}

/* === PANEL CHUNG === */
.glass-panel {
    background: var(--color-bg-panel);
    padding: 30px;
    border-radius: var(--border-radius-md);
    box-shadow: 0 0 20px var(--color-cyan-glow);
    margin-top: 20px;
    border: 1px solid var(--color-cyan-dark);
}

.glass-panel h2 {
    font-family: var(--font-display);
    color: var(--color-cyan-bright);
    font-size: 22px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--color-cyan-dark);
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title {
    font-family: var(--font-display);
    font-size: 22px;
    color: var(--color-cyan-bright);
    margin-bottom: 12px;
    padding-left: 8px;
}

/* === FORM VÀ INPUT === */
.input-group {
    position: relative;
    margin-bottom: 18px;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-cyan-dim);
    margin-bottom: 6px;
    padding-left: 5px;
}

input[type="text"], 
input[type="number"], 
input[type="password"],
input[type="date"] {
    width: 100%;
    padding: 12px 15px;
    padding-right: 40px; /* Cho icon mắt */
    background: #0a1b2f;
    border: 1px solid var(--color-cyan-dark);
    border-radius: var(--border-radius-sm);
    color: var(--color-text-light);
    font-family: var(--font-primary);
    font-size: 15px;
    outline: none;
    box-shadow: inset 0 0 10px var(--color-cyan-glow);
    transition: all 0.3s ease;
}

input[type="date"] {
    padding-right: 15px;
    color-scheme: dark;
}

input:focus {
    border-color: var(--color-cyan-bright);
    box-shadow: var(--shadow-glow-focus);
}

.toggle-eye {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(10%); /* Điều chỉnh cho label */
    cursor: pointer;
    color: var(--color-cyan-dim);
}

.form-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 15px;
    align-items: flex-end;
}

/* === NÚT BẤM (BUTTON) === */
button {
    font-family: var(--font-primary);
    font-size: 15px;
    font-weight: bold;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    padding: 12px 20px;
    border: none;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.button-primary {
    background: linear-gradient(145deg, var(--color-cyan-bright), var(--color-cyan-dim));
    color: var(--color-bg-dark);
    box-shadow: 0 0 15px var(--color-cyan-dark);
    width: 100%;
}

.button-primary:hover {
    background: linear-gradient(145deg, #2affff, #1affff);
    box-shadow: 0 0 25px var(--color-cyan-dark);
    transform: scale(1.02);
}

.button-secondary {
    background: var(--color-bg-panel);
    color: var(--color-cyan-dim);
    border: 1px solid var(--color-cyan-dark);
}

.button-secondary:hover {
    background: var(--color-bg-light);
    color: var(--color-cyan-bright);
    border-color: var(--color-cyan-dim);
}

/* Trạng thái Loading cho nút */
button.loading {
    color: transparent !important;
    pointer-events: none;
}

button .button-text {
    transition: opacity 0.2s ease;
}

button.loading .button-text {
    opacity: 0;
}

button.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-top: -10px;
    margin-left: -10px;
    border: 3px solid var(--color-bg-dark);
    border-top-color: var(--color-cyan-bright);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.button-secondary.loading::after {
    border: 3px solid var(--color-bg-light);
    border-top-color: var(--color-cyan-bright);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === KHU VỰC LỖI (LOGIN) === */
#error-container {
    color: var(--color-red);
    background: #1a1f30;
    padding: 12px;
    border: 1px solid var(--color-red);
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    margin-top: 20px;
    text-align: center;
    display: none; /* Sẽ được bật bằng JS */
}

/* === KHU VỰC DANH SÁCH KEY (BẢNG) === */
.filter-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-controls .input-group {
    margin-bottom: 0;
}

.filter-controls .search-group {
    flex-grow: 1;
}

.filter-controls .date-group {
    flex-basis: 180px;
}

.key-table-wrapper {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--color-cyan-dark);
    border-radius: var(--border-radius-sm);
    box-shadow: inset 0 0 10px var(--color-cyan-glow);
}

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

.styled-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.styled-table th, .styled-table td {
    padding: 14px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-cyan-dark);
    color: var(--color-text-light);
    font-size: 14px;
    white-space: nowrap;
}

.styled-table th {
    background: #0f1d32;
    color: var(--color-cyan-bright);
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
}

.styled-table tbody tr:hover {
    background-color: #13243a;
    transition: background 0.2s;
}

/* Thao tác (Nút xóa) */
.styled-table td:last-child {
    text-align: center;
}

.styled-table .button-danger {
    background: transparent;
    color: var(--color-red);
    border: 1px solid var(--color-red);
    padding: 6px 10px;
    font-size: 14px;
}

.styled-table .button-danger:hover {
    background: var(--color-red);
    color: var(--color-text-light);
    box-shadow: 0 0 10px var(--color-red);
}

.styled-table .key-cell,
.styled-table .device-cell {
    cursor: pointer;
    font-weight: 500;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.styled-table .key-cell:hover,
.styled-table .device-cell:hover {
    color: var(--color-cyan-bright);
}

.table-caption {
    text-align: right;
    font-size: 12px;
    color: var(--color-cyan-dim);
    margin-top: 10px;
    font-style: italic;
}

/* === MODAL === */
.modal-overlay {
    display: none; /* Hiển thị bằng JS */
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    animation: fadeInModal 0.3s ease;
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: linear-gradient(145deg, #0c1b2f, #142744);
    padding: 30px 40px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-cyan-dark);
    color: var(--color-text-light);
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 30px var(--color-cyan-glow);
    font-family: var(--font-primary);
    animation: slideInModal 0.3s ease-out;
}

@keyframes slideInModal {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h2 {
    color: var(--color-cyan-bright);
    margin-bottom: 20px;
    font-family: var(--font-display);
}

.modal-content p {
    margin-bottom: 12px;
    line-height: 1.6;
    color: var(--color-text-dim);
}
.modal-content p a {
    color: var(--color-cyan-bright);
    text-decoration: none;
    font-weight: 500;
}

.api-box-upgraded {
    position: relative;
    background: #000f1f;
    border: 1px solid var(--color-cyan-dark);
    border-left: 5px solid var(--color-cyan-bright);
    border-radius: var(--border-radius-sm);
    padding: 14px 50px 14px 14px;
    margin-top: 10px;
    font-family: monospace;
    font-size: 13px;
    color: var(--color-cyan-bright);
    word-break: break-all;
    box-shadow: 0 0 10px var(--color-cyan-glow);
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
}
.api-box-upgraded .api-label {
    background: var(--color-cyan-bright);
    color: var(--color-bg-dark);
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.api-copy-btn {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    background: var(--color-cyan-dark);
    color: var(--color-cyan-bright);
    border: none;
    padding: 6px 10px;
    font-size: 14px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s ease;
}
.api-copy-btn:hover {
    background: var(--color-cyan-bright);
    color: var(--color-bg-dark);
}

.modal-close {
    margin-top: 25px;
    background: var(--color-cyan-bright);
    color: var(--color-bg-dark);
    border: none;
    padding: 12px 28px;
    font-weight: bold;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    box-shadow: 0 0 15px var(--color-cyan-dark);
    width: auto;
}
.modal-close:hover {
    background: #2affff;
    box-shadow: 0 0 25px var(--color-cyan-dark);
}

/* === HỆ THỐNG THÔNG BÁO TOAST === */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 20000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--color-bg-panel);
    color: var(--color-text-light);
    padding: 15px 20px;
    border-radius: var(--border-radius-sm);
    border-left: 5px solid var(--color-cyan-bright);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    animation: slideInToast 0.3s ease-out, fadeOutToast 0.5s ease-out 3s forwards;
}

.toast.toast-success {
    border-left-color: #00ff88;
}

.toast.toast-error {
    border-left-color: var(--color-red);
    color: var(--color-red);
}

.toast i {
    font-size: 18px;
}

.toast.toast-success i { color: #00ff88; }
.toast.toast-error i { color: var(--color-red); }
.toast.toast-info i { color: var(--color-cyan-bright); }

@keyframes slideInToast {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOutToast {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* === FOOTER === */
.footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    font-size: 14px;
    color: var(--color-cyan-dim);
    border-top: 1px solid var(--color-cyan-dark);
}
.footer a {
    color: var(--color-cyan-bright);
    text-decoration: none;
    font-weight: 500;
}
.footer a:hover {
    text-decoration: underline;
}

/* === RESPONSIVE === */
@media screen and (max-width: 768px) {
    body {
        padding: 10px;
    }
    .main-container {
        padding: 10px;
    }
    .glass-panel {
        padding: 20px;
    }
    .header h1 {
        font-size: 24px;
    }
    .header p {
        font-size: 14px;
    }

    #user-info-container {
        top: 10px;
        right: 10px;
    }
    .user-info-button {
        padding: 6px 8px;
        gap: 6px;
    }
    .user-info-button #display-username {
        display: none; /* Ẩn tên trên mobile, chỉ hiện avatar */
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .form-grid button {
        margin-top: 10px;
    }

    .filter-controls {
        flex-direction: column;
        gap: 10px;
    }
    .filter-controls .date-group,
    .filter-controls .search-group {
        flex-basis: auto;
    }

    .styled-table th, .styled-table td {
        font-size: 12px;
        padding: 10px 8px;
        white-space: normal;
        word-break: break-all;
    }
    .styled-table .key-cell,
    .styled-table .device-cell {
        max-width: 100px;
    }

    .modal-content {
        padding: 20px;
    }
    .api-box-upgraded {
        font-size: 11px;
        flex-direction: column;
        align-items: flex-start;
        padding-right: 14px;
    }
    .api-copy-btn {
        top: 10px;
        right: 10px;
        transform: translateY(0);
    }
}

@media screen and (max-width: 480px) {
    .header h1 {
        font-size: 20px;
    }
    .glass-panel h2 {
        font-size: 18px;
    }
    button {
        font-size: 14px;
        padding: 12px 15px;
    }
    input[type="text"], 
    input[type="number"], 
    input[type="password"],
    input[type="date"] {
        font-size: 14px;
        padding: 12px 15px;
    }
    .styled-table th:nth-child(3), .styled-table td:nth-child(3) {
         display: none; /* Ẩn cột ngày tạo trên màn hình quá nhỏ */
    }
}
