@import url('typography.css');
@import url('buttons.css');
@import url('log_viewer.css');

/* Biến màu theme: public/assets/css/themes.css (load trước file này) */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: inherit;
}


/* Global Font update */
html {
    font-size: var(--fs-md);
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: var(--fs-base);
    line-height: 1.5;
    background-color: var(--background-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Utilities */
.hidden {
    display: none !important;
}
/* [hidden] của HTML chỉ là display:none từ UA stylesheet (specificity gần như 0), nên
   bất kỳ class nào đặt display (flex/inline-flex/grid…) đều ghi đè nó → phần tử vẫn
   hiện dù JS đã set hidden. Rule này làm thuộc tính hidden luôn thắng. */
[hidden] {
    display: none !important;
}


.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.w-full {
    width: 100%;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.gap-6 {
    gap: 1.5rem;
}

.gap-8 {
    gap: 2rem;
}

.mt-4 {
    margin-top: 1rem;
}

.p-4 {
    padding: 1rem;
}

.text-muted { color: var(--text-muted); }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }

/* Buttons — xem thêm buttons.css (ghost, compact, audit, toolbar) */
.btn {
    /* min-height bằng .form-input (2.5rem) để nút và ô nhập trên cùng một hàng filter
       không lệch chiều cao; .btn-sm dùng 2rem, khớp .form-input-compact. */
    box-sizing: border-box;
    min-height: var(--control-h);
    padding: 0.55rem 1.1rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-nowrap {
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-sm {
    min-height: var(--control-h-sm);
    padding: 0.35rem 0.75rem;
    font-size: var(--fs-sm);
    gap: 0.35rem;
}

.btn-sm .icon {
    width: 14px;
    height: 14px;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: var(--hover-surface, rgba(255, 255, 255, 0.05));
    border-color: var(--text-muted);
}

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

.btn-microsoft {
    background-color: #2f2f2f;
    color: white;
    border: 1px solid #555;
}

.btn-microsoft:hover {
    background-color: #3f3f3f;
}

.btn-microsoft .icon {
    width: 16px;
    height: 16px;
    margin-right: 4px;
}

/* Inputs */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: var(--fs-base);
}

.form-input,
.form-select {
    width: 100%;
    /* box-sizing + font: inherit + min-height để input / select / date / textarea cùng
       một chiều cao. Thiếu 3 thứ này thì mỗi loại control tự tính theo font mặc định
       của trình duyệt nên cao thấp lệch nhau trên cùng một hàng form. */
    box-sizing: border-box;
    min-height: var(--control-h);
    padding: 0.55rem 0.75rem;
    font: inherit;
    font-size: var(--fs-base, 0.875rem);
    line-height: 1.35;
    background-color: var(--input-bg, rgba(15, 23, 42, 0.5));
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-main);
    transition: border-color var(--transition-fast);
}

/* select không co giãn theo padding giống input → chốt chiều cao bằng nhau */
select.form-input,
select.form-select {
    height: var(--control-h);
}

/* WebKit thêm widget lịch bên trong nên date thường cao hơn input thường */
input[type="date"].form-input,
input[type="time"].form-input,
input[type="datetime-local"].form-input {
    height: var(--control-h);
}

textarea.form-input,
textarea.form-select {
    height: auto;
    min-height: 5rem;
    line-height: 1.5;
}


.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(24px);
}


/* Login Page Specific */
.login-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, #1e1b4b, var(--background-dark));
}

.login-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    padding: 2.5rem;
    border-radius: 1rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-title {
    font-size: var(--fs-2xl);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.divider span {
    padding: 0 10px;
    font-size: var(--fs-sm);
}

/* Dashboard Layout */
.dashboard-container {
    display: flex;
    width: 100%;
    height: 100vh;
}

.sidebar {
    width: 210px;
    background-color: var(--background-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    transition: width 0.3s ease, margin-left 0.3s ease;
}

.sidebar.collapsed {
    width: 70px;
    padding: 1rem 0.5rem;
}

.sidebar.collapsed .sidebar-logo {
    font-size: 0;
    justify-content: center;
}

.sidebar.collapsed .sidebar-logo span {
    font-size: var(--fs-2xl);
}

.sidebar.collapsed .nav-item {
    font-size: 0;
    padding: 0.75rem;
    justify-content: center;
    gap: 0;
}

.sidebar.collapsed .nav-item .icon {
    width: 24px;
    height: 24px;
    margin: 0;
}

.sidebar.collapsed .nav-item::after {
    display: none;
}

.sidebar-logo {
    font-size: var(--fs-xl);
    font-weight: bold;
    color: var(--primary-color);
    padding: 1rem 0;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.6rem 0.85rem;
    border-radius: 0.5rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    transition: all var(--transition-fast);
}

.nav-item:hover,
.nav-item.active {
    background-color: var(--nav-active-bg, rgba(99, 102, 241, 0.12));
    color: var(--primary-color);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: 54px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    background-color: var(--top-bar-bg, rgba(15, 23, 42, 0.85));
    backdrop-filter: blur(8px);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar-toggle-btn:hover {
    background-color: var(--hover-surface, rgba(255, 255, 255, 0.05));
    color: var(--text-main);
}

.content-area {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.card {
    background-color: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-title {
    font-size: var(--fs-md);
    font-weight: 600;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: var(--fs-md);
    line-height: 1.45;
}

.table td {
    font-size: var(--fs-base);
    line-height: 1.5;
}

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

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 1rem;
    font-size: var(--fs-xs);
    font-weight: 600;
}

.status-green {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--secondary-color);
}

.status-red {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

/**
 * Admin — tag quyền (module_/nav_) trong bảng user/role.
 * Tránh inline background:#333 (dark mode only) — ở light mode chữ tối trên nền tối = không đọc được.
 */
.admin-perm-chip {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: var(--fs-xs);
    font-weight: 500;
    font-family: ui-monospace, monospace;
    background: var(--hover-surface-strong);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    max-width: 100%;
    word-break: break-all;
}

/* Animation Utils */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Icons (using generic placeholders or SVG classes) */
.icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background-color: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    width: 95%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: var(--fs-lg);
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: var(--fs-2xl);
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Logs Page Styles */
.filter-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    background: var(--background-card);
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-label {
    font-size: var(--fs-base);
    color: var(--text-muted);
    font-weight: 500;
}

.log-details-pre {
    max-height: 300px;
}

/* Module Page Specifics */
.module-category {
    border-bottom: 1px solid var(--border-color);
}

.module-category-header {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    color: var(--secondary-color);
    font-weight: 800;
    letter-spacing: 0.05em;
    padding: 1.25rem 1rem 0.75rem 1.25rem;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.2s;
}

.module-category-header:hover {
    background: var(--module-cat-hover-bg, rgba(255, 255, 255, 0.03));
}

.module-category-title-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.module-category-title-group::before {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    background: currentColor;
    border-radius: 50%;
}

.category-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
    color: var(--text-muted);
}

.module-category.collapsed .category-chevron {
    transform: rotate(-90deg);
}

.module-category-content {
    max-height: 1000px;
    /* Large enough for content */
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    opacity: 1;
    padding-bottom: 0.5rem;
}

.module-category.collapsed .module-category-content {
    max-height: 0;
    opacity: 0;
    padding-bottom: 0;
}

.module-item {
    padding: 0.75rem 1rem;
    margin: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.module-item:hover {
    background: var(--module-item-hover-bg, rgba(255, 255, 255, 0.04));
    border-color: var(--module-item-hover-border, rgba(255, 255, 255, 0.08));
}

.module-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary-color);
}

.module-item.active .module-item-title {
    color: var(--primary-color);
    font-weight: 600;
}

.module-item-desc {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Workflow Steps Tracking */
.workflow-step {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem;
    background: var(--workflow-step-bg, rgba(15, 23, 42, 0.45));
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    transition: all 0.3s ease;
    opacity: 0.6;
    margin-bottom: 0.75rem;
}

.workflow-step.active {
    opacity: 1;
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.workflow-step.completed {
    opacity: 1;
    border-color: var(--secondary-color);
    background: rgba(16, 185, 129, 0.03);
}

.step-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--border-color);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: var(--fs-base);
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.workflow-step.active .step-icon {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 0 10px var(--primary-color);
}

.workflow-step.completed .step-icon {
    background: var(--secondary-color);
    color: white;
}

.step-info {
    flex: 1;
}

.step-title {
    font-weight: 600;
    font-size: var(--fs-md);
    color: var(--text-main);
}

.step-status {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.workflow-step.active .step-status {
    color: var(--primary-color);
}

.workflow-step.completed .step-status {
    color: var(--secondary-color);
}

/* Deploy Task Queue */
.task-queue-container {
    margin-top: 1.5rem;
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.25rem;
}

.task-queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-weight: 600;
    font-size: var(--fs-base);
    color: var(--text-muted);
}

.task-queue-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.queue-item.executing {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.queue-item.completed {
    border-color: var(--secondary-color);
    opacity: 0.8;
}

.queue-item.waiting {
    opacity: 0.7;
}

.queue-item-id {
    flex: 1;
    font-family: monospace;
    font-size: var(--fs-base);
    color: var(--text-main);
}

.queue-item-actions {
    display: flex;
    gap: 0.25rem;
}

.btn-icon-sm {
    padding: 0.25rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-sm:hover {
    background: var(--hover-surface, rgba(255, 255, 255, 0.05));
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-icon-sm.btn-danger-hover:hover {
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.2);
}

.queue-item-wrapper {
    position: relative;
}

.queue-item-details {
    overflow: hidden;
    animation: slideDown 0.3s ease-out forwards;
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
    }

    to {
        max-height: 100px;
        opacity: 1;
    }
}

.queue-item .btn-icon-sm {
    width: 28px;
    height: 28px;
}

/* Module Page Specifics */
.module-sidebar {
    width: 220px;
    flex-shrink: 0;
}

.module-sidebar-list {
    height: calc(100vh - 160px);
    background: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.module-content-wrapper {
    align-items: flex-start;
}

.module-console {
    width: 700px;
    min-width: 400px;
    max-width: 80%;
    /* Limit to 80% of screen */
    flex-shrink: 0;
    background: #000;
    padding: 1rem;
    border-radius: 0.75rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: var(--fs-sm);
    color: #10b981;
    border: 1px solid #334155;
    min-height: 320px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
    word-break: break-word;
}

/* Responsive Overrides */
@media (max-width: 1200px) {
    .content-area.flex.gap-4 {
        flex-direction: column;
    }

    .module-sidebar {
        width: 100% !important;
    }

    .module-sidebar-list {
        height: 350px !important;
    }

    .module-content-wrapper {
        flex-direction: column !important;
    }

    .module-console {
        width: 100% !important;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 70px;
        padding: 1rem 0.5rem;
    }

    .sidebar-logo {
        font-size: 0;
        justify-content: center;
    }

    .sidebar-logo span {
        font-size: var(--fs-2xl);
    }

    .nav-item {
        font-size: 0;
        padding: 0.75rem;
        justify-content: center;
        gap: 0;
    }

    .nav-item .icon {
        width: 24px;
        height: 24px;
        margin: 0;
    }

    .nav-item::after {
        display: none;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .card {
        padding: 1rem;
    }

    .module-action-buttons {
        margin-top: 1rem;
        width: 100%;
        justify-content: flex-start;
    }

    .module-header-flex {
        flex-direction: column;
        align-items: flex-start !important;
    }
}