/* ========================================================= */
/* --- 1. THEME VARIABLES (Light & Dark) --- */
/* ========================================================= */
:root {
    /* --- LIGHT THEME (Default) --- */
    --primary-color: #4f46e5;    /* Indigo */
    --primary-hover: #4338ca;
    --secondary-color: #64748b;  /* Slate Grey */
    --danger-color: #ef4444;     /* Red */
    --success-color: #10b981;    /* Green */
    
    --bg-color: #f1f5f9;         /* Page Background: Light Grey */
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    
    --card-bg: #ffffff;          /* Wrappers: White */
    --input-bg: #f8fafc;         /* Inputs: Off-White */
    --hover-bg: #f1f5f9;         /* Hover state */
    
    --text-main: #1e293b;        /* Text: Dark Slate */
    --text-muted: #64748b;       /* Text: Grey */
    --border-color: #e2e8f0;     /* Border: Light Grey */
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    --radius: 12px;
}

/* --- DARK THEME DEFINITIONS --- */
[data-theme="dark"] {
    --bg-color: #0f172a;       /* Page Background: Very Dark Slate (Almost Black) */
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    
    --card-bg: #1e293b;        /* Wrappers: Dark Slate (Lighter than background) */
    --input-bg: #334155;       /* Inputs: Greyish Slate */
    --hover-bg: #334155;       /* Hover state */
    
    --text-main: #f8fafc;      /* Text: White */
    --text-muted: #94a3b8;     /* Text: Light Grey */
    --border-color: #334155;   /* Border: Dark Grey */
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    background: var(--bg-gradient);
    color: var(--text-main);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    line-height: 1.5;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ========================================================= */
/* --- 2. MAIN CONTAINER --- */
/* ========================================================= */
.container {
    background-color: var(--card-bg); /* Uses variable */
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 900px;
    margin: 20px auto;
    box-sizing: border-box;
    border: 1px solid var(--border-color); /* Added border for definition in dark mode */
}

.app-logo {
    display: block;
    max-width: 250px;
    width: 100%;
    height: auto;
    margin: 0 auto 30px auto;
}

h2, h3, h4, h5 {
    color: var(--text-main);
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 20px;
}

h2 { text-align: center; font-size: 1.8rem; }
h3 { font-size: 1.4rem; border-bottom: 2px solid var(--border-color); padding-bottom: 10px; }

hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 30px 0;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}
a:hover { color: var(--primary-hover); }

/* ========================================================= */
/* --- 3. INPUTS & FORMS --- */
/* ========================================================= */
form { margin: 20px 0; }

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.9rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg); /* Uses variable */
    color: var(--text-main);           /* Uses variable */
    box-sizing: border-box;
    font-size: 15px;
    transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    background-color: var(--card-bg);
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

/* ========================================================= */
/* --- 4. BUTTONS & TOGGLES --- */
/* ========================================================= */
.btn, button, input[type="submit"] {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
    color: white;
    background-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
    text-align: center;
    line-height: normal;
}

.btn:hover, button:hover, input[type="submit"]:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary { 
    background-color: var(--card-bg); 
    color: var(--text-main); 
    border: 1px solid var(--border-color); 
}
.btn-secondary:hover { 
    background-color: var(--hover-bg); 
    color: var(--text-main); 
}

.btn-danger { background-color: var(--danger-color); }
.btn-danger:hover { background-color: #dc2626; }

/* Theme Toggle Button */
.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    margin-right: 10px;
    flex-shrink: 0;
}
.theme-toggle-btn:hover {
    background-color: var(--hover-bg);
    border-color: var(--primary-color);
}

.group-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.group-actions .btn { padding: 8px 12px; font-size: 0.85rem; }

/* ========================================================= */
/* --- 5. DASHBOARD & TREE VIEW --- */
/* ========================================================= */
.file-browser-tree {
    list-style: none;
    padding-left: 0;
    margin-top: 20px;
}

.tree-node-header {
    display: flex;
    align-items: center;
    padding: 15px;
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    background-color: var(--card-bg); /* Uses variable */
    color: var(--text-main);          /* Uses variable */
    border-radius: var(--radius);
    cursor: pointer;
    gap: 12px;
    transition: background 0.2s, border-color 0.2s;
}

.tree-node-header:hover {
    background-color: var(--hover-bg);
    border-color: var(--primary-color);
}

.tree-toggle {
    background: rgba(79, 70, 229, 0.1); /* Transparent Primary */
    color: var(--primary-color);
    width: 24px;
    height: 24px;
    line-height: 24px;
    border-radius: 50%;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    flex-shrink: 0;
}

.tree-node-header h4 { margin: 0; font-size: 1rem; color: var(--primary-color); font-weight: 600; flex-grow: 1; }
.tree-node-header h5 { margin: 0; font-size: 0.95rem; font-weight: 500; flex-grow: 1; color: var(--text-main); }

.tree-node-content {
    padding: 10px 0 10px 20px;
    margin-left: 12px;
    border-left: 2px solid var(--border-color);
}

.permission-tag {
    background-color: var(--input-bg);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-left: 10px;
    border: 1px solid var(--border-color);
}

.document-item {
    padding: 12px 15px;
    background-color: var(--card-bg); /* Uses variable */
    color: var(--text-main);          /* Uses variable */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.document-actions a {
    font-size: 0.85rem;
    margin-left: 10px;
    color: var(--text-muted);
}
.document-actions a:hover { color: var(--primary-color); text-decoration: underline; }

/* ========================================================= */
/* --- 6. FILE UPLOAD --- */
/* ========================================================= */
.upload-form-group {
    border: 2px dashed var(--border-color);
    padding: 20px;
    border-radius: var(--radius);
    background-color: var(--input-bg); /* Uses variable */
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    transition: all 0.2s;
}

.upload-form-group.drag-active {
    background-color: rgba(79, 70, 229, 0.1);
    border-color: var(--primary-color);
}

.file-upload-input {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; opacity: 0;
}

.custom-file-upload {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
}
.custom-file-upload:hover { background-color: var(--primary-hover); }

.file-name-display {
    color: var(--text-muted);
}

/* ========================================================= */
/* --- 7. CREDIT PACKAGES --- */
/* ========================================================= */
.credit-package-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.credit-package {
    background-color: var(--card-bg); /* Uses variable */
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 25px 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: var(--shadow-sm);
}

.credit-package:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.credit-package.selected {
    background-color: rgba(79, 70, 229, 0.05); /* Very light indigo tint */
    border: 2px solid var(--primary-color);
    box-shadow: var(--shadow-lg);
    transform: translateY(-5px);
}

.credit-package h4 {
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.credit-package p {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0;
}

.amount-display {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 5px;
    display: block;
}

.payment-methods { max-width: 100%; margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.stripe-button {
    background-color: #635bff;
    color: white; padding: 14px; font-weight: 600; font-size: 1.1rem;
    border-radius: 8px; width: 100%; border: none; cursor: pointer;
}
.stripe-button:hover { background-color: #4b44d6; }

/* ========================================================= */
/* --- 10. BILLING TABS & SUBSCRIPTIONS --- */
/* ========================================================= */
.tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    font-weight: bold;
    color: #666;
    background: none; /* Ensure no button background interferes */
}

.tab.active {
    border: 1px solid #ddd;
    border-bottom: 1px solid #fff;
    background: #fff;
    color: #007bff;
    border-radius: 5px 5px 0 0;
    margin-bottom: -1px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

.sub-badge {
    background: #28a745;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    margin-left: 5px;
    vertical-align: middle;
}

/* Optional: Simple fade animation for smoother tab switching */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ========================================================= */
/* --- 8. ACCOUNT HEADER & ALERTS --- */
/* ========================================================= */
.credit-display-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--card-bg); /* Uses variable */
    padding: 15px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.credit-display { color: var(--text-main); font-weight: 600; margin: 0; }
.credit-display a { margin-left: 10px; font-size: 0.9em; }

/* Account Dropdown Logic */
.account-dropdown {
    position: relative;
    display: inline-block;
}

.account-icon-btn {
    width: 42px; height: 42px;
    background: var(--input-bg);
    color: var(--text-main);
    border-radius: 50%; 
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.account-icon-btn:hover { background: var(--primary-color); color: white; border-color: var(--primary-color); }

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 50px;
    z-index: 1000;
    background-color: var(--card-bg); /* Uses variable */
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg); 
    border-radius: 8px; 
    padding: 5px;
    min-width: 200px;
}

.account-dropdown.show .dropdown-content {
    display: block;
}

.dropdown-content a {
    display: block;
    border-radius: 4px; padding: 10px 15px;
    color: var(--text-main); 
    border: none;
    text-decoration: none;
}
.dropdown-content a:hover { background-color: var(--hover-bg); color: var(--primary-color); }

.dropdown-header {
    display: block;
    padding: 10px 15px;
    font-weight: bold;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85em;
    margin-bottom: 5px;
}

/* Messages */
.message { padding: 15px; border-radius: 8px; margin-bottom: 25px; font-weight: 500; border-left: 5px solid transparent; }
.message.info { background-color: #eff6ff; color: #1e40af; border-left-color: #3b82f6; }
.message.success { background-color: #f0fdf4; color: #166534; border-left-color: #22c55e; }
.message.error { background-color: #fef2f2; color: #991b1b; border-left-color: #ef4444; }

/* ========================================================= */
/* --- 9. UTILITIES --- */
/* ========================================================= */
.hidden { display: none !important; }

/* ========================================================= */
/* --- 10. PLACEHOLDER / TEMPLATE FOLDERS --- */
/* ========================================================= */
.placeholder-folder {
    background-color: var(--input-bg); /* Matches input boxes */
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    margin-bottom: 15px;
    transition: background-color 0.2s;
}

/* Override the standard header look for these nested headers */
.placeholder-folder .tree-node-header {
    background-color: transparent !important; /* Force transparency */
    border: none;
    border-bottom: 1px dashed var(--border-color) !important;
    padding: 5px 0;
    margin-bottom: 10px;
}

.placeholder-folder .tree-toggle {
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1em;
    width: auto;
}

.placeholder-folder h5 {
    color: var(--text-muted) !important;
    font-style: italic;
    font-weight: 500;
}

/* ========================================================= */
/* --- 11. TABLES (For Template Management) --- */
/* ========================================================= */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden; /* Rounds corners */
    box-shadow: var(--shadow-sm);
}

th, td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

th {
    background-color: var(--input-bg);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: var(--hover-bg);
}

/* Specific button size for tables */
td .btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    margin: 0;
}

/* ========================================================= */
/* --- 12. PENDING INVITATIONS ALERT --- */
/* ========================================================= */
.pending-invitations {
    background-color: #fffbe6;   /* Light Yellow */
    border: 1px solid #ffe58f;   /* Darker Yellow Border */
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 25px;
    color: #92400e;              /* Dark Brownish-Orange text */
}

.pending-invitations h4 {
    color: #92400e;              /* Match text color */
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.share-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 10px 0;
    border-bottom: 1px dashed rgba(0,0,0,0.1);
}

.share-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.share-actions {
    display: flex;
    gap: 10px;
}

/* --- Dark Mode Override for Invitations --- */
[data-theme="dark"] .pending-invitations {
    background-color: rgba(234, 179, 8, 0.1); /* Transparent Gold */
    border-color: rgba(234, 179, 8, 0.4);     /* Gold Border */
    color: #fef08a;                           /* Pale Yellow Text */
}

[data-theme="dark"] .pending-invitations h4 {
    color: #fef08a;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .share-item {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

/* ========================================================= */
/* --- 11. SETTINGS PAGE & 2FA --- */
/* ========================================================= */
.settings-container {
    max-width: 800px;
    margin: 0 auto;
}

.qr-box {
    background: #fff;
    padding: 15px;
    display: inline-block;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin: 15px 0;
}

.secret-code {
    font-family: monospace;
    font-size: 1.2em;
    background: #eee;
    padding: 5px 10px;
    border-radius: 3px;
    letter-spacing: 1px;
    color: #333;
}

.status-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    font-weight: bold;
}

.status-enabled {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-disabled {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Dark Mode Overrides for Settings */
body.dark-mode .secret-code {
    background: #333;
    color: #eee;
    border: 1px solid #555;
}
/* Note: .qr-box stays white even in dark mode so the QR code remains scannable */