/* DiTeR UI shell — layout, forms, modal, theme toggle.
   Page sheets: dashboard.css, login.css, email.css, users.css, help.css, credits.css
   Manage extras: containers-css-addon.css
*/

/* ==========================================
   Base Styles
   ========================================== */

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

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 700;
}

html {
    font-size: 17px;
}

body {
    font-family: var(--font-sans), -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================
   Layout
   ========================================== */

body:not(.login-page) {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    height: 100vh;
}

/* ==========================================
   Sidebar
   ========================================== */

.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    position: relative;
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: var(--spacing-xl);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.logo .logo-image {
    height: 40px;
    width: auto;
    transition: filter 0.3s ease;
}

/* Make logo white in dark theme for sidebar */
[data-theme="dark"] .sidebar .logo .logo-image {
    filter: brightness(0) invert(1);
}

/* Keep logo normal in light theme for sidebar */
[data-theme="light"] .sidebar .logo .logo-image {
    filter: none;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-lg);
    transition: all 0.2s ease;
    font-weight: 500;
    position: relative;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--card-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-color);
    color: white;
}

.nav-item.active svg {
    stroke: white;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: white;
    border-radius: 0 3px 3px 0;
    opacity: 0.9;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

/* ==========================================
   Main Content
   ========================================== */

.main-content {
    background: var(--bg-primary);
    overflow-x: clip;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    max-width: 100%;
}

/* Progress Tracker Panel */
.progress-tracker {
    position: fixed;
    top: 5rem;
    right: 2rem;
    width: 320px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 900;
    animation: slideInRight 0.3s ease-out;
}

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

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

.progress-tracker-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-tracker-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.progress-tracker-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.progress-tracker-body {
    padding: 1.5rem 1.25rem;
    text-align: center;
}

.progress-tracker-icon {
    margin-bottom: 1rem;
}

.progress-spinner {
    width: 50px;
    height: 50px;
    color: var(--primary);
    animation: rotate 2s linear infinite;
}

@keyframes rotate {
    100% {
        transform: rotate(360deg);
    }
}

.progress-spinner circle:last-child {
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes dash {
    0% {
        stroke-dashoffset: 126;
    }
    50% {
        stroke-dashoffset: 31.5;
    }
    100% {
        stroke-dashoffset: 126;
    }
}

.progress-tracker-body h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-tracker-body p {
    margin: 0 0 1rem 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.progress-tracker-status {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-muted);
    font-family: monospace;
}

.progress-info {
    margin: 1.5rem 0 1rem 0;
}

.progress-process-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    min-height: 1.2em;
}

.progress-percentage {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.4);
}

.progress-bar.progress-bar--error {
    background: linear-gradient(90deg, #b91c1c, #dc2626);
    box-shadow: 0 0 10px rgba(220, 38, 38, 0.35);
}

.progress-bar.progress-bar--success {
    background: linear-gradient(90deg, #15803d, #22c55e);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.35);
}

.progress-tracker.progress-tracker--error {
    border-color: #dc2626;
}

.progress-tracker.progress-tracker--success {
    border-color: #22c55e;
}

@media (max-width: 768px) {
    .progress-tracker {
        right: 1rem;
        width: calc(100vw - 2rem);
        max-width: 320px;
    }
    
    .progress-percentage {
        font-size: 1.5rem;
    }
}

/* ==========================================
   Top Bar
   ========================================== */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
}

.topbar-left {
    flex: 1;
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    min-width: 0;
}

.sidebar-toggle {
    display: none;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-top: 0.1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--glass-bg);
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

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

.topbar-titles {
    min-width: 0;
    flex: 1;
}

.sidebar-backdrop {
    display: none;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 0.25rem 0;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0;
    font-weight: 400;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.icon-button {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--glass-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-button:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.icon-button svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-primary);
}

.server-email-toggle.is-on {
    border-color: var(--primary-color);
    background: var(--accent-light, rgba(99, 102, 241, 0.12));
}
.server-email-toggle.is-on svg {
    stroke: var(--primary-color);
}
.server-email-toggle:not(.is-on) {
    opacity: 0.55;
}
.server-email-toggle:not(.is-on):hover {
    opacity: 1;
}

/* Add Menu Dropdown */
.add-menu-wrapper {
    position: relative;
}

.add-button {
    background: var(--accent-color) !important;
    border-color: var(--accent-color) !important;
}

.add-button:hover {
    background: var(--accent-hover) !important;
    transform: translateY(-2px) rotate(90deg);
}

.add-button svg {
    stroke: white !important;
    transition: transform 0.3s ease;
}

.add-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    min-width: 200px;
    box-shadow: var(--shadow-xl);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
    overflow: hidden;
}

.add-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.add-menu-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

.add-menu-item:last-child {
    border-bottom: none;
}

.add-menu-item:hover {
    background: var(--card-hover);
    color: var(--accent-color);
}

.add-menu-item svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-muted);
    flex-shrink: 0;
    transition: stroke 0.2s ease;
}

.add-menu-item:hover svg {
    stroke: var(--accent-color);
}

.add-menu-item span {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Hide email option if email system is not active */
.add-menu-item.email-only.hidden {
    display: none;
}

/* ==========================================
   Forms
   ========================================== */

.form-container {
    padding: 0 var(--spacing-xl) var(--spacing-xl);
    max-width: 800px;
}

.form-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
}

.form-card--no-box {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding-left: 0;
    padding-right: 0;
}

.form-card--centered {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* SMTP Warning - Fixed on right side */
.smtp-warning-fixed {
    position: fixed;
    top: 9rem;
    right: 6rem;
    width: 470px;
    max-width: calc(100vw - 4rem);
    z-index: 100;
}

.smtp-warning-fixed .alert-box {
    margin: 0;
    box-shadow: var(--shadow-xl);
}

@media (max-width: 1024px) {
    .smtp-warning-fixed {
        position: static;
        width: 100%;
        max-width: 100%;
        margin-bottom: 1.5rem;
    }
    
    .smtp-warning-fixed .alert-box {
        box-shadow: var(--shadow-md);
    }
}

.form-title {
    font-size: 1.375rem;
    font-weight: 700;
    margin-bottom: var(--spacing-lg);
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.form-group > label {
    white-space: nowrap;
}

.container-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.form-group label {
    font-weight: 500;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="search"],
.form-group input[type="tel"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
    padding: 0.625rem 0.875rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    min-height: 2.5rem;
    color: var(--text-primary);
    font-family: inherit;
    transition: all 0.2s ease;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}
.form-group input[type="number"]::-webkit-outer-spin-button,
.form-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(0, 116, 212, 0.1);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    -webkit-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='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Select2 multi/tag search is a <textarea>; do not inherit form textarea sizing */
.form-group .select2-search--inline .select2-search__field,
.form-group textarea.select2-search__field {
    min-height: 0 !important;
    height: 1.5rem !important;
    margin: 0;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    resize: none !important;
    line-height: 1.5rem;
}

.form-help {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.form-help.is-ok {
    color: #0a7a3e;
}

.form-help.is-err {
    color: #b42318;
}

.form-prereq {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0 0 1.5rem 0;
}

.form-group--narrow {
    max-width: 16rem;
}

.form-group--wide {
    max-width: 36rem;
}

.form-group--wide > label {
    white-space: normal;
}

.form-section + .form-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.form-section .form-title {
    margin-bottom: 0.35rem;
}

.form-section > .form-help,
.form-section > .form-prereq {
    margin-bottom: 1rem;
}

.form-section .form-actions {
    margin-top: 1rem;
}

.form-section .domain-control-bar {
    margin-top: 0.25rem;
}

.form-section .subsection-title {
    margin-top: 1.75rem;
}

.form-section .dashboard-backup-meta {
    margin: 0.25rem 0 0.25rem;
}

.log-output {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 12rem;
    max-height: 16rem;
    overflow: auto;
    margin: 0;
    padding: 0.625rem 0.875rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    font-size: 0.9375rem;
}

.checkbox-container input[type="checkbox"] {
    display: none;
}

.checkbox-container .checkbox-custom {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.checkbox-container input[type="checkbox"]:checked + .checkbox-custom {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

.checkbox-container input[type="checkbox"]:checked + .checkbox-custom::after {
    content: '✓';
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
}

.form-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-start;
    margin-top: var(--spacing-xl);
    padding-top: 0.25rem;
}

.btn-primary {
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-md);
    color: #ffffff;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--primary-hover, var(--accent-color, #0088cc));
    color: #ffffff;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    padding: var(--spacing-md) var(--spacing-lg);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--card-hover);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

[data-theme="light"] .form-card {
    background: #ffffff;
}

.alert-box {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-xl);
    border: 1px solid;
}

.alert-box.warning {
    background: rgba(255, 152, 0, 0.1);
    border-color: rgba(255, 152, 0, 0.3);
    color: #ff9800;
}

.alert-box svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    stroke: currentColor;
}

.alert-box strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.alert-box p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.alert-box a {
    color: var(--accent-color);
    text-decoration: underline;
}

.email-tabs {
    display: flex;
    gap: 0.25rem;
    margin: 0 0 var(--spacing-xl);
    padding-bottom: 0;
    border-bottom: 1px solid var(--border-color);
}

.tab-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-button svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    opacity: 0.85;
}

.tab-button:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: transparent;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

.user-profile {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-lg);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-profile:hover {
    background: transparent;
}

/* Flat topbar: no box around profile, minimal look */
.topbar-flat {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.user-profile-flat {
    background: transparent;
    border: none;
    padding: 0;
}

.user-profile-flat:hover {
    background: transparent;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: visible;
    position: relative;
}

.user-avatar img {
    width: 120%;
    height: 120%;
    object-fit: cover;
    object-position: center 20%;
    position: relative;
    top: -10%;
    left: -10%;
    border-radius: 50%;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.user-profile:hover .user-name {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.users-nickname {
    cursor: pointer;
}

.users-nickname:hover {
    color: var(--primary-color);
}

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

.user-role {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ==========================================
   Scrollbar
   ========================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* ==========================================
   Theme Toggle Button
   ========================================== */

.theme-toggle {
    position: fixed;
    bottom: 6rem;
    right: 1.8rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-xl);
    transition: all 0.3s ease;
    z-index: 1000;
}

.theme-toggle:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 25px 35px -5px rgba(0, 0, 0, 0.2);
}

.theme-toggle:active {
    transform: translateY(-2px) scale(1);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
    transition: all 0.3s ease;
}

/* Icon animations */
.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
    position: absolute;
    transition: all 0.3s ease;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    opacity: 0;
    transform: rotate(180deg) scale(0);
}

[data-theme="dark"] .theme-toggle .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

[data-theme="light"] .theme-toggle .sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

[data-theme="light"] .theme-toggle .moon-icon {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
}

/* Tooltip for theme toggle */
.theme-toggle::before {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 12px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    box-shadow: var(--shadow-md);
}

.theme-toggle:hover::before {
    opacity: 1;
}

[data-theme="light"] .sidebar {
    background: #ffffff;
    box-shadow: var(--shadow-md);
}

[data-theme="light"] .topbar {
    background: #ffffff;
}


[data-theme="light"] .icon-button {
    background: var(--bg-tertiary);
}

[data-theme="light"] .icon-button:hover {
    background: #e2e8f0;
}

[data-theme="light"] body {
    background: var(--bg-primary);
    color: var(--text-primary);
}

[data-theme="light"] .page-title,
[data-theme="light"] .nav-item,
[data-theme="light"] .user-name,
[data-theme="light"] .form-title {
    color: var(--text-primary);
}

[data-theme="light"] .form-group label,
[data-theme="light"] .page-subtitle {
    color: var(--text-secondary);
}

[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea,
[data-theme="light"] .btn-secondary {
    color: var(--text-primary);
}

[data-theme="light"] .nav-item svg,
[data-theme="light"] .dashboard-row-icon {
    color: #000000;
    stroke: #000000;
}

[data-theme="light"] .nav-item.active,
[data-theme="light"] .nav-item.active svg {
    color: #ffffff;
    stroke: #ffffff;
}

[data-theme="light"] .btn-primary,
[data-theme="light"] .btn-primary svg,
[data-theme="light"] .dashboard-btn.btn-primary {
    color: #ffffff;
    stroke: #ffffff;
}

[data-theme="dark"] body:not(.login-page) {
    background: #000000;
}

[data-theme="dark"] .main-content {
    background: #000000;
}

[data-theme="light"] .theme-toggle {
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .theme-toggle:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

/* Responsive adjustments for theme toggle */
@media (max-width: 768px) {
    .theme-toggle {
        bottom: 3rem;
        right: 1.5rem;
        width: 48px;
        height: 48px;
    }
    
    .theme-toggle svg {
        width: 20px;
        height: 20px;
    }
    
    .theme-toggle::before {
        display: none;
    }
}

/* ==========================================
   Utility Classes
   ========================================== */
.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.admin-badge {
    display: inline-block;
    font-size: 0.5em;
    font-weight: 600;
    vertical-align: middle;
    padding: 0.2em 0.5em;
    margin-left: 0.5rem;
    background: var(--accent-light);
    color: var(--accent-color);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* ==========================================
   DiTeR modal (alert / confirm / busy / forms)
   ========================================== */
.diter-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
    animation: diter-modal-fade-in 0.18s ease;
}
@keyframes diter-modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.diter-modal-box {
    background: var(--bg-secondary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 1rem;
    box-shadow:
        0 0 0 1px rgba(15, 23, 42, 0.03),
        0 18px 40px -12px rgba(15, 23, 42, 0.28);
    max-width: 24rem;
    width: calc(100% - 0.5rem);
    padding: 1.5rem 1.5rem 1.25rem;
    text-align: center;
    animation: diter-modal-pop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes diter-modal-pop {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(6px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.diter-modal-icon {
    width: 2.75rem;
    height: 2.75rem;
    margin: 0 auto 0.85rem;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color, #0074d4);
    background: color-mix(in srgb, var(--primary-color, #0074d4) 12%, transparent);
}
.diter-modal-icon:empty,
.diter-modal-icon[hidden] {
    display: none;
}
.diter-modal--info .diter-modal-icon {
    color: var(--primary-color, #0074d4);
    background: color-mix(in srgb, var(--primary-color, #0074d4) 12%, transparent);
}
.diter-modal--success .diter-modal-icon {
    color: #15803d;
    background: rgba(21, 128, 61, 0.12);
}
.diter-modal--warn .diter-modal-icon {
    color: #b45309;
    background: rgba(180, 83, 9, 0.12);
}
.diter-modal--error .diter-modal-icon {
    color: #b91c1c;
    background: rgba(185, 28, 28, 0.12);
}

.diter-modal-title {
    margin: 0 0 0.4rem;
    color: var(--text-primary, #111827);
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.3;
}
.diter-modal-title[hidden] {
    display: none;
}

.diter-modal-message {
    color: var(--text-secondary, #4b5563);
    font-size: 0.9375rem;
    line-height: 1.55;
    white-space: pre-line;
    margin: 0 0 1.35rem;
}
.diter-modal-message[hidden] {
    display: none;
}
.diter-modal-message:empty {
    margin-bottom: 0;
}

.diter-modal-busy {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    white-space: normal;
    color: var(--text-secondary, #4b5563);
}

.diter-modal-spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--border-color, #e5e7eb);
    border-top-color: var(--primary-color, #0074d4);
    border-radius: 50%;
    animation: diter-modal-spin 0.7s linear infinite;
}

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

.diter-modal-actions {
    display: flex;
    gap: 0.65rem;
    justify-content: center;
    flex-wrap: wrap;
}
.diter-modal-actions .diter-modal-btn {
    padding: 0.55rem 1.2rem;
    border-radius: 0.65rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, filter 0.15s ease;
    border: 1px solid transparent;
    min-width: 5.5rem;
}
.diter-modal-actions .diter-modal-btn--primary {
    background: var(--primary-color, #0074d4);
    color: #fff;
}
.diter-modal-actions .diter-modal-btn--primary:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}
.diter-modal-actions .diter-modal-btn--ghost,
.diter-modal-actions .diter-modal-btn--secondary {
    background: transparent;
    color: var(--text-primary, #111827);
    border-color: var(--border-color, #d1d5db);
}
.diter-modal-actions .diter-modal-btn--ghost:hover,
.diter-modal-actions .diter-modal-btn--secondary:hover {
    background: var(--bg-primary, #f3f4f6);
}
.diter-modal-actions .diter-modal-btn--danger {
    background: #b91c1c;
    color: #fff;
    border-color: #991b1b;
}
.diter-modal-actions .diter-modal-btn--danger:hover {
    filter: brightness(1.06);
}

/* FTP modals – custom content */
.diter-modal-message .diter-modal-ftp-sub {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0.25rem 0 0.75rem;
}
.diter-modal-ftp-creds {
    text-align: left;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.diter-modal-ftp-row {
    margin-bottom: 0.5rem;
}
.diter-modal-ftp-row:last-child {
    margin-bottom: 0;
}
.diter-modal-ftp-row label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
.diter-modal-ftp-row code {
    font-size: 0.875rem;
    padding: 0.2rem 0.4rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}
.diter-modal-ftp-placeholder {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin: 0.5rem 0 0;
}
.diter-modal-ftp-input {
    width: 100%;
    padding: 0.375rem 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

/* Panel-password step-up (site DB credentials) */
.diter-unlock {
    text-align: left;
    max-width: 22rem;
    margin: 0 auto;
}
.diter-unlock-domain {
    margin: 0 0 0.35rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}
.diter-unlock-hint {
    margin: 0 0 1.1rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--text-muted);
}
.diter-unlock-label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}
.diter-unlock-pass {
    width: 100%;
    box-sizing: border-box;
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
    letter-spacing: 0.08em;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.diter-unlock-pass:focus {
    border-color: var(--accent, #3b82f6);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #3b82f6) 22%, transparent);
}
.diter-unlock-error {
    margin: 0.55rem 0 0;
    font-size: 0.8125rem;
    color: var(--danger, #dc2626);
    min-height: 1.2em;
}
.diter-unlock--shake {
    animation: diter-unlock-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes diter-unlock-shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}
.diter-unlock--revealed {
    max-width: 26rem;
}
.diter-unlock--revealed .ftp-conn-info {
    margin-top: 0.35rem;
}
.diter-unlock-meta {
    margin: 0.75rem 0 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.diter-unlock-note {
    margin: 0.4rem 0 0;
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-muted);
}

/* Email Plus request modal – locked (only X closes) */
.emailplus-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1.5rem;
    overflow-y: auto;
}
.emailplus-modal-overlay.hidden {
    display: none;
}
.emailplus-modal-box {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: var(--spacing-xl);
    max-width: 640px;
    width: 100%;
}
.emailplus-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    background: var(--bg-tertiary);
    color: #e53935;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.emailplus-modal-close:hover {
    background: rgba(229, 57, 53, 0.15);
    color: #f44336;
}
.emailplus-modal-box .form-title {
    margin-bottom: 1rem;
    padding-right: 2.5rem;
}
.emailplus-modal-box .iframe-wrapper {
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.emailplus-modal-box .iframe-wrapper iframe {
    width: 100%;
    min-height: 560px;
    border: none;
}
.emailplus-modal-after {
    margin-top: 1rem;
    margin-bottom: 0;
}
.emailplus-requested-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}
.emailplus-requested-badge svg {
    width: 1rem;
    height: 1rem;
    stroke: #00bfa5;
}

.lang-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    width: auto;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.625rem 0.875rem;
    min-height: 2.5rem;
    border-radius: var(--radius-md, 0.5rem);
    border: 1px solid var(--border-color, rgba(127, 127, 127, 0.28));
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #111827);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.lang-switcher:hover {
    border-color: color-mix(in srgb, var(--primary-color, #0074d4) 40%, var(--border-color, #d1d5db));
    background: var(--bg-secondary, #f3f4f6);
}
.lang-switcher-icon {
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
    opacity: 0.85;
}
.lang-switcher-select {
    appearance: none;
    -webkit-appearance: none;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: normal;
    color: inherit;
    background-color: transparent;
    border: none;
    padding: 0 1.25rem 0 0;
    margin: 0;
    line-height: 1.35;
    cursor: pointer;
    width: auto;
    min-width: 5.5rem;
    flex: 0 1 auto;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0 center;
    background-size: 0.85rem;
}
.lang-switcher-select:focus {
    outline: none;
}
.lang-switcher:focus-within {
    border-color: var(--primary-color, #0074d4);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color, #0074d4) 18%, transparent);
}
.login-lang-switcher {
    margin-top: 0.85rem;
    display: flex;
    justify-content: center;
}
.login-lang-switcher .lang-switcher {
    width: auto;
}
.sidebar-lang {
    width: 100%;
    padding: 0.35rem var(--spacing-md, 1rem) 0.75rem;
    box-sizing: border-box;
}
.sidebar-lang .lang-switcher {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
.sidebar-lang .lang-switcher-select {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
}
.form-hint {
    margin: 0.25rem 0 0;
    font-size: 0.8rem;
    line-height: 1.35;
    color: var(--text-secondary, #6b7280);
}
.form-group--check {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    justify-content: flex-end;
}
/* display:flex above would otherwise override the HTML hidden attribute */
.form-group[hidden] {
    display: none !important;
}
.form-group--check[hidden] {
    display: none !important;
}
.form-group--check > label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    margin: 0;
}
.form-group--check input[type="checkbox"] {
    width: 1.05rem;
    height: 1.05rem;
    min-height: 0;
    margin: 0;
    accent-color: var(--accent-color, #0074d4);
    flex-shrink: 0;
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.form-group input:focus-visible,
.form-group select:focus-visible,
.form-group textarea:focus-visible,
.input-wrapper input:focus-visible,
.theme-toggle:focus-visible,
.sidebar-toggle:focus-visible,
.icon-button:focus-visible,
.lang-switcher-select:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    body:not(.login-page) {
        grid-template-columns: 1fr;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(280px, 86vw);
        height: 100vh;
        z-index: 9500;
        transform: translateX(-100%);
        transition: transform var(--transition-fast);
        box-shadow: var(--shadow-xl);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 9400;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .topbar {
        padding: var(--spacing-md);
    }

    .page-title {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    .user-info {
        display: none;
    }
}

@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;
    }
}
