/* ============================================================
   GLOBAL RESET
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ============================================================
   UTILITY CLASSES — Reusable patterns (thay inline styles)
   ============================================================ */
/* Bố cục */
.d-flex {
    display: flex;
}

.d-flex-center {
    display: flex;
    align-items: center;
}

.d-inline {
    display: inline;
}

.d-none {
    display: none;
}

.flex-1 {
    flex: 1;
}

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

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

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

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

.justify-end {
    justify-content: flex-end;
}

.flex-wrap {
    flex-wrap: wrap;
}

.gap-4 {
    gap: 4px;
}

.gap-6 {
    gap: 6px;
}

.gap-8 {
    gap: 8px;
}

.gap-10 {
    gap: 10px;
}

.gap-12 {
    gap: 12px;
}

.gap-16 {
    gap: 16px;
}

.w-full {
    width: 100%;
}

.max-w-sm {
    max-width: 420px;
}

.max-w-md {
    max-width: 520px;
}

/* Khoảng cách */
.m-0 {
    margin: 0;
}

.mt-xs {
    margin-top: 4px;
}

.mt-sm {
    margin-top: 8px;
}

.mt-md {
    margin-top: 12px;
}

.mt-lg {
    margin-top: 20px;
}

.mb-xs {
    margin-bottom: 4px;
}

.mb-sm {
    margin-bottom: 8px;
}

.mb-md {
    margin-bottom: 12px;
}

.mb-lg {
    margin-bottom: 1.5rem;
}

.mb-0 {
    margin-bottom: 0;
}

.ml-auto {
    margin-left: auto;
}

.ml-xs {
    margin-left: 4px;
}

.p-0 {
    padding: 0;
}

.px-sm {
    padding: 3px 8px;
}

.pos-relative {
    position: relative;
}

/* Chữ & Phông */
.text-xxs {
    font-size: 10px;
}

.text-xs {
    font-size: 11px;
}

.text-sm {
    font-size: 12px;
}

.text-md {
    font-size: 13px;
}

.text-base {
    font-size: 14px;
}

.text-lg {
    font-size: 16px;
}

.text-xl {
    font-size: 18px;
}

.text-bold {
    font-weight: 600;
}

.text-700 {
    font-weight: 700;
}

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

.text-right {
    text-align: right;
}

.nowrap {
    white-space: nowrap;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Màu sắc */
.text-primary {
    color: var(--color-primary);
}

.text-success {
    color: var(--color-success);
}

.text-warning {
    color: var(--color-warning);
}

.text-danger {
    color: var(--color-error);
}

.text-info {
    color: var(--color-info);
}

.text-muted {
    color: var(--text-tertiary);
}

.text-secondary {
    color: var(--text-secondary);
}

/* Tiện ích gộp */
.meta-info {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 0;
}

.text-sm-muted {
    font-size: 12px;
    color: var(--text-secondary);
}

.cursor-pointer {
    cursor: pointer;
}

.text-5xl {
    font-size: 48px;
}

.text-success-alt {
    color: #34d399;
}

.max-w-lg {
    max-width: 600px;
}

.bg-tertiary {
    background: var(--bg-tertiary);
}

.w-80 {
    flex: 0 0 80px;
}

/* Tiện ích Dashboard */
.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card-mini {
    flex: 1;
    min-width: 120px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    text-align: center;
}

.label-fixed {
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 100px;
}

.code-textarea {
    font-family: monospace;
    font-size: 12px;
    resize: vertical;
}

.scroll-text {
    flex: 1;
    font-size: 11px;
    overflow-x: auto;
    white-space: nowrap;
}

.hint-text {
    display: block;
    opacity: .55;
    font-size: 11px;
    margin-top: 1px;
}

.form-section-label {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 8px;
    display: block;
}

.scroll-panel {
    max-height: 60vh;
    overflow-y: auto;
}

.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

.badge-purple {
    font-size: 10px;
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1;
}

.badge-pink {
    font-size: 10px;
    background: rgba(236, 72, 153, 0.15);
    color: #ec4899;
}

.tag-sm {
    font-size: 11px;
    background: var(--bg-secondary);
    padding: 1px 6px;
    border-radius: 4px;
}

.p-md {
    padding: 12px;
}

.badge-warning-sm {
    font-size: 10px;
    background: var(--color-warning);
    color: #000;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
}

.input-inline {
    padding: 7px 10px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}

/* Ẩn spinner input number (khi có nút ± custom) */
input[type="number"].no-spin::-webkit-outer-spin-button,
input[type="number"].no-spin::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"].no-spin {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Segmented Control — Toggle tabs */
.seg-control {
    display: flex;
    position: relative;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
}

.seg-control-item {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: calc(var(--radius-sm) - 3px);
    cursor: pointer;
    transition: all 0.25s ease;
}

.seg-control-item:hover:not(.active) {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.seg-control-item.active {
    color: #fff;
    background: var(--color-primary);
    box-shadow: 0 2px 8px rgba(var(--color-primary-rgb, 139, 92, 246), 0.35);
}

.seg-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #22c55e;
    color: #fff;
}

.seg-control-item.active .seg-badge {
    background: rgba(255, 255, 255, 0.25);
}

.border-top-sep {
    border-top: 1px solid var(--border-primary);
    margin-top: 4px;
    padding-top: 6px;
}

/* Ô nhập & Textarea — Thống nhất toàn hệ thống */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="datetime-local"],
textarea {
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-tertiary);
    font-size: 12px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="datetime-local"]:focus,
textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb, 139, 92, 246), 0.12);
}

/* Hiệu ứng chuyển giao diện */
html {
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color var(--transition-base), color var(--transition-base);
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.6;
}

code {
    background: var(--bg-tertiary);
    color: var(--color-primary);
}

pre {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Nút bấm */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s ease, color 0.2s ease;
    white-space: nowrap;
}

.btn:hover {
    background: var(--color-primary);
    color: var(--btn-hover-color);
    border-color: var(--color-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}


.btn-delete {
    background-color: transparent;
    color: var(--color-error);
    border-color: rgba(239, 68, 68, 0.4);
}

.btn-delete:hover {
    background-color: var(--color-error);
    border-color: var(--color-error);
    color: var(--btn-hover-color);
    transform: translateY(-1px);
}

/* Ô chọn thống nhất */
.sys-select {
    padding: 0.5rem 0.7rem;
    background: transparent;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.15s ease;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 1.8rem;
}

.sys-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb, 139, 92, 246), 0.12);
}

.sys-select:hover {
    border-color: var(--color-primary);
}

.sys-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Trang đăng nhập */
.login-container,
.setup-container {
    max-width: 500px;
    margin: 2rem auto;
    padding: 2rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-container h2,
.setup-container h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--color-primary);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
}

.form-group .sys-select {
    width: 100%;
}

/* Trang xác thực */
.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.auth-links {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-primary);
}

.auth-links p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-links a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.auth-links a:hover {
    color: var(--color-primary-hover, var(--color-secondary));
    text-decoration: underline;
}



/* ============================================================
   ACCESSIBILITY — Reduced Motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
