/* ===== Design System ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.08);
    --border-active: rgba(79, 172, 254, 0.4);
    --text-primary: #f0f0f5;
    --text-secondary: #8a8a9a;
    --text-muted: #5a5a6a;
    --accent: #4facfe;
    --accent-2: #00f2fe;
    --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --danger: #ff4757;
    --success: #2ed573;
    --warning: #ffa502;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== Login Page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

.animated-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 400px; height: 400px;
    background: #4facfe;
    top: -10%; left: -5%;
    animation-delay: 0s;
}

.orb-2 {
    width: 350px; height: 350px;
    background: #00f2fe;
    bottom: -10%; right: -5%;
    animation-delay: -7s;
}

.orb-3 {
    width: 300px; height: 300px;
    background: #7c3aed;
    top: 50%; left: 60%;
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(50px, -30px) scale(1.1); }
    50% { transform: translate(-20px, 40px) scale(0.95); }
    75% { transform: translate(30px, 20px) scale(1.05); }
}

.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: rgba(18, 18, 26, 0.85);
    backdrop-filter: blur(40px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    box-shadow: var(--shadow), 0 0 80px rgba(79, 172, 254, 0.05);
}

.login-header {
    text-align: center;
    margin-bottom: 36px;
}

.logo-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: inline-block;
    animation: glow 3s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { filter: drop-shadow(0 0 8px rgba(79, 172, 254, 0.3)); }
    50% { filter: drop-shadow(0 0 16px rgba(79, 172, 254, 0.6)); }
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-header .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    transition: all 0.2s;
    outline: none;
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.password-input-wrap {
    position: relative;
}

.password-input-wrap input {
    padding-right: 52px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.password-toggle:hover {
    background: rgba(79, 172, 254, 0.12);
    color: var(--accent);
}

.password-toggle svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.error-msg {
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

#login-form button[type="submit"] {
    width: 100%;
    padding: 14px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-sm);
    color: #000;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 4px;
}

#login-form button[type="submit"]:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(79, 172, 254, 0.3);
}

#login-form button[type="submit"]:active {
    transform: translateY(0);
}

#login-form button[type="submit"]:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.btn-loader {
    display: inline-block;
    animation: spin 1s linear infinite;
}

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

.login-helper-links {
    margin-top: 16px;
    text-align: center;
}

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}

.link-button:hover {
    color: var(--accent-2);
}

.inline-message {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-top: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.inline-message.success {
    background: rgba(46, 213, 115, 0.12);
    border: 1px solid rgba(46, 213, 115, 0.28);
    color: #8df0b2;
}

.inline-message.error {
    background: rgba(255, 71, 87, 0.12);
    border: 1px solid rgba(255, 71, 87, 0.28);
    color: #ff9ba4;
}

.inline-message.info {
    background: rgba(79, 172, 254, 0.12);
    border: 1px solid rgba(79, 172, 254, 0.28);
    color: #a9d4ff;
}

/* ===== Dashboard Layout ===== */
.dashboard {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-header .user-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.tenant-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tenant-item {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.tenant-item:hover {
    background: var(--bg-card-hover);
}

.tenant-item.active {
    background: rgba(79, 172, 254, 0.12);
    border: 1px solid rgba(79, 172, 254, 0.2);
}

.tenant-item .count {
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.06);
    padding: 2px 8px;
    border-radius: 12px;
}

.sidebar-actions {
    padding: 16px;
    margin-top: auto;
    border-top: 1px solid var(--border);
}

.sidebar-account .btn + .btn {
    margin-top: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #000;
    width: 100%;
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(79, 172, 254, 0.25);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    width: 100%;
    margin-top: 8px;
}

.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger);
    border: 1px solid rgba(255, 71, 87, 0.2);
}

.btn-danger:hover {
    background: rgba(255, 71, 87, 0.2);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

.btn-inline {
    width: auto;
    margin-top: 0;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.page-header .badge {
    background: rgba(79, 172, 254, 0.12);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.branding-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    margin-bottom: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.branding-preview {
    width: 120px;
    height: 120px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.branding-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.02);
}

.branding-fallback {
    width: 76px;
    height: 76px;
    border-radius: 22px;
    background: var(--accent-gradient);
    color: #07111f;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.branding-copy {
    flex: 1;
    min-width: 0;
}

.branding-copy h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.branding-copy p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
}

.branding-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.branding-hint {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.branding-domain-settings {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.branding-domain-settings .input-group {
    margin-top: 0;
}

.public-link-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.public-link-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.public-link-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.public-link-item a {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    word-break: break-all;
}

.public-link-item a:hover {
    text-decoration: underline;
}

/* Tool Type Tabs */
.tool-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    width: fit-content;
}

.tool-tab {
    padding: 8px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
    font-family: var(--font);
}

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

.tool-tab.active {
    background: var(--accent-gradient);
    color: #000;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    transition: all 0.2s;
    margin-bottom: 24px;
    cursor: pointer;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(79, 172, 254, 0.04);
}

.upload-zone .upload-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 14px;
}

.upload-zone .browse-link {
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
}

.upload-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 24px;
}

.upload-controls input[type="text"],
.upload-controls select {
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}

.upload-controls input[type="text"]:focus,
.upload-controls select:focus {
    border-color: var(--accent);
}

.upload-controls select option {
    background: var(--bg-secondary);
}

/* Category Cards */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.15s;
}

.category-card:hover {
    border-color: rgba(255,255,255,0.12);
    background: var(--bg-card-hover);
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.category-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.category-header .file-count {
    font-size: 12px;
    color: var(--accent);
    background: rgba(79, 172, 254, 0.1);
    padding: 2px 10px;
    border-radius: 12px;
}

.file-list {
    max-height: 160px;
    overflow-y: auto;
    font-size: 12px;
    color: var(--text-secondary);
}

.file-list::-webkit-scrollbar {
    width: 4px;
}

.file-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

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

.file-item .delete-file {
    color: var(--danger);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    background: none;
    border: none;
    font-size: 14px;
    padding: 2px 6px;
}

.file-item:hover .delete-file {
    opacity: 1;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

#modal-create-user {
    z-index: 1001;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow);
}

.modal-lg {
    max-width: 760px;
}

.modal h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.modal-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.modal-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.modal .input-group {
    margin-bottom: 16px;
}

.modal .input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.modal .input-group input,
.modal .input-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
}

.modal .input-group input:focus,
.modal .input-group select:focus {
    border-color: var(--accent);
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    font-size: 13px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

.user-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
}

.user-card-main {
    min-width: 0;
    flex: 1;
}

.user-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.user-card-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.mini-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(79, 172, 254, 0.12);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
}

.mini-badge.role-superadmin {
    background: rgba(79, 172, 254, 0.12);
    color: var(--accent);
}

.mini-badge.role-admin {
    background: rgba(46, 213, 115, 0.12);
    color: #8df0b2;
}

.mini-badge.is-muted {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
}

.user-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.compact-empty {
    padding: 24px 12px;
}

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

/* Responsive */
@media (max-width: 768px) {
    .dashboard { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
    .main-content { padding: 16px; }
    .categories-grid { grid-template-columns: 1fr; }
    .branding-card {
        flex-direction: column;
        align-items: stretch;
    }

    .branding-preview {
        width: 100%;
        height: 180px;
    }

    .modal {
        padding: 24px 20px;
        max-width: calc(100vw - 24px);
    }
    .modal-header-row,
    .user-card {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-header-actions,
    .user-card-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .btn-inline {
        width: 100%;
    }
}
