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

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: var(--gray-900);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: bold;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--gray-300);
    text-decoration: none;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: white;
}

.btn-logout {
    color: var(--danger) !important;
}

.nav-user {
    color: var(--gray-300);
}

/* Container */
.container {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}

.login-box {
    background: white;
    padding: 3rem;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

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

.login-header h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.login-header h2 {
    color: var(--gray-700);
}

.login-header p {
    color: var(--gray-500);
}

/* Forgot password link */
.forgot-password-link {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.forgot-password-link a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.forgot-password-link a:hover {
    text-decoration: underline;
}

/* Resend 2FA code */
.resend-code {
    text-align: center;
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 8px;
}

.resend-code p {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

/* Rate limit warning */
.rate-limit-warning {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--gray-700);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group small {
    color: var(--gray-500);
    font-size: 0.85rem;
}

.form-group.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-group.checkbox label {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    padding: 1.5rem;
    background: var(--gray-50);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.form-row .form-group {
    flex: 1;
    min-width: 150px;
    margin: 0;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    background: var(--gray-200);
    color: var(--gray-700);
    transition: all 0.2s;
}

.btn:hover {
    background: var(--gray-300);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

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

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

.btn-block {
    display: block;
    width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Dashboard */
.dashboard h1 {
    margin-bottom: 2rem;
}

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.app-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative;
}

.app-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.app-icon {
    font-size: 2.5rem;
}

.app-info h3 {
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.app-info p {
    color: var(--gray-500);
    font-size: 0.9rem;
}

.badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
}

.badge-public {
    background: #dbeafe;
    color: #1e40af;
}

.empty-state {
    text-align: center;
    padding: 4rem;
    color: var(--gray-500);
}

.empty-state h2 {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Admin */
.admin-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--gray-200);
    padding-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--gray-500);
    border-radius: 8px 8px 0 0;
}

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

.tab-content {
    display: none;
}

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

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

.hidden-form {
    display: none;
}

/* Tables */
.data-table {
    width: 100%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--gray-200);
}

.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
}

.data-table tr:hover {
    background: var(--gray-50);
}

.data-table tr.inactive {
    opacity: 0.6;
}

.actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
}

.status.active {
    background: #d1fae5;
    color: #065f46;
}

.status.inactive {
    background: #fee2e2;
    color: #991b1b;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    min-width: 350px;
}

.modal-content h3 {
    margin-bottom: 1.5rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Permissions */
.apps-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.app-checkbox {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.app-checkbox:hover {
    background: var(--gray-50);
}

.app-checkbox input {
    width: 1.25rem;
    height: 1.25rem;
}

.app-checkbox-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-checkbox .icon {
    font-size: 1.5rem;
}

/* Profile */
.profile-page {
    max-width: 600px;
}

.profile-form {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 2rem;
}

.profile-form hr {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 1.5rem 0;
}

.profile-info {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
}

.profile-info h3 {
    margin-bottom: 1rem;
}

.profile-info p {
    margin-bottom: 0.5rem;
    color: var(--gray-700);
}

/* URL Tags */
.url-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.url-tag {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: help;
}

.url-tag.localhost { background: #fef3c7; color: #92400e; }
.url-tag.internal { background: #dbeafe; color: #1e40af; }
.url-tag.external { background: #dcfce7; color: #166534; }
.url-tag.domain { background: #f3e8ff; color: #7c3aed; }

/* URL Grid for forms */
.url-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 1.5rem;
    background: var(--gray-50);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.url-grid .form-group {
    margin: 0;
}

/* Dashboard header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.client-info {
    color: var(--gray-500);
    font-size: 0.9rem;
    background: var(--gray-200);
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

/* App card with URLs */
.app-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.app-main {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.app-main:hover {
    background: var(--gray-50);
}

.app-urls {
    border-top: 1px solid var(--gray-200);
    position: relative;
}

.url-toggle {
    width: 100%;
    padding: 0.75rem;
    background: var(--gray-50);
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-600);
    transition: background 0.2s;
}

.url-toggle:hover {
    background: var(--gray-100);
}

.url-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
    margin-bottom: 0.5rem;
}

.url-dropdown.show {
    display: block;
}

.url-option {
    display: block;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.2s;
}

.url-option:last-child {
    border-bottom: none;
}

.url-option:hover {
    background: var(--gray-50);
}

.url-option small {
    display: block;
    color: var(--gray-500);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    word-break: break-all;
}

/* Edit app page */
.edit-app-page {
    max-width: 800px;
}

.edit-form {
    background: white;
    padding: 2rem;
    border-radius: 12px;
}

.form-section {
    margin-bottom: 2rem;
}

.form-section h2 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

.url-group {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: 8px;
}

.help-text {
    color: var(--gray-500);
    margin-bottom: 1rem;
}

.legacy-url-notice {
    background: #fef3c7;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    color: #92400e;
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem;
    color: var(--gray-500);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }

    .form-row {
        flex-direction: column;
    }

    .data-table {
        font-size: 0.85rem;
    }

    .actions {
        flex-direction: column;
    }
}

/* Security Stats */
.security-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-box {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.stat-box h3 {
    margin-bottom: 1rem;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 0.5rem;
}

.stat-box p {
    margin-bottom: 0.5rem;
    color: var(--gray-600);
}

.stat-box strong {
    color: var(--primary);
}
