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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.page {
    display: block;
}

.page.hidden {
    display: none;
}

/* ===== AUTH PAGE ===== */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 20px;
}

.auth-card {
    background: var(--card);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}

.auth-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 40px 20px;
    text-align: center;
}

.auth-header h1 {
    font-size: 32px;
    margin: 0 0 10px 0;
}

.auth-subtitle {
    font-size: 14px;
    margin: 0;
    opacity: 0.9;
    font-weight: 500;
}

.auth-form {
    display: none;
    padding: 30px;
}

.auth-form.active {
    display: block;
}

.auth-form h2 {
    margin-bottom: 20px;
    font-size: 20px;
    color: var(--text);
}

.security-info {
    background: #d1fae5;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 20px;
    font-size: 13px;
    color: #065f46;
}

.security-info p {
    margin: 4px 0;
}

.auth-form form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form input {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.auth-toggle {
    text-align: center;
    margin-top: 15px;
    font-size: 14px;
    color: var(--text-light);
}

.auth-toggle a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.auth-toggle a:hover {
    text-decoration: underline;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    width: 100%;
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--text-light);
    color: white;
    padding: 8px 16px;
}

.btn-secondary:hover {
    background: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: white;
    padding: 8px 12px;
    font-size: 12px;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--warning);
    color: white;
    padding: 8px 12px;
    font-size: 12px;
}

.btn-warning:hover {
    background: #d97706;
}

/* ===== MESSAGES ===== */
.message {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    display: none;
}

.message.success {
    display: block;
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.message.error {
    display: block;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ===== DASHBOARD PAGE ===== */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 20px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 24px;
    margin: 0;
}

.search-bar {
    flex: 1;
    min-width: 200px;
}

.search-bar input {
    width: 100%;
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
}

.search-bar input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.search-bar input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.3);
}

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

.user-display {
    font-weight: 500;
}

.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ===== ADD APP SECTION ===== */
.add-app-section {
    background: linear-gradient(135deg, var(--card) 0%, rgba(99, 102, 241, 0.02) 100%);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 40px;
    box-shadow: var(--shadow);
    border: 2px solid var(--border);
    transition: all 0.3s;
}

.add-app-section:hover {
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.1);
}

.add-app-section h2 {
    margin-bottom: 24px;
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.add-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.add-form input {
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--card);
    color: var(--text);
    transition: all 0.3s;
    font-weight: 500;
}

.add-form input::placeholder {
    color: var(--text-light);
    opacity: 0.7;
}

.add-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    background: linear-gradient(135deg, var(--card) 0%, rgba(99, 102, 241, 0.02) 100%);
}

.form-row .btn {
    padding: 12px;
}

/* ===== APPS GRID ===== */
.apps-section {
    margin-top: 40px;
}

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 28px;
    animation: fadeIn 0.5s ease-in;
}

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

.app-card {
    background: var(--card);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
}

.app-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    opacity: 0;
    transition: opacity 0.3s;
}

.app-card:hover {
    transform: translateY(-12px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    border-color: var(--primary);
}

.app-card:hover::before {
    opacity: 1;
}

.app-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.app-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

.app-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s;
}

.app-card:hover .app-image img {
    transform: scale(1.08);
}

.app-content {
    padding: 24px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--card) 0%, rgba(0,0,0,0.02) 100%);
}

.app-name {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
    word-break: break-word;
    letter-spacing: -0.3px;
}

.app-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 12px;
    margin-bottom: 16px;
    word-break: break-all;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
    transition: opacity 0.3s;
}

.app-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.app-actions {
    display: flex;
    gap: 10px;
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.app-actions .btn {
    flex: 1;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.3s;
}

.app-actions .btn:hover {
    transform: translateY(-2px);
}

.no-apps {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.no-apps p {
    font-size: 16px;
}

/* ===== MODAL ===== */
.modal {
    display: flex;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-light);
}

.modal-close:hover {
    color: var(--text);
}

#editForm {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#editForm input {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}

#editForm input:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border);
}

.modal-footer .btn {
    flex: 1;
    padding: 10px;
}

/* ===== DARK MODE ===== */
body.dark-mode {
    --bg: #1a1a2e;
    --card: #16213e;
    --text: #eaeaea;
    --text-light: #b0b0b0;
    --border: #2d3561;
}

body.dark-mode .header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

body.dark-mode .app-card {
    background: var(--card);
    border: 1px solid var(--border);
}

body.dark-mode .add-app-section,
body.dark-mode .auth-card,
body.dark-mode .modal-content {
    background: var(--card);
    border: 1px solid var(--border);
}

body.dark-mode .app-card-title,
body.dark-mode .auth-form h2,
body.dark-mode .modal-header h2 {
    color: var(--text);
}

/* ===== MODAL TABS ===== */
.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.tab-btn {
    flex: 1;
    padding: 15px;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-light);
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover {
    background: var(--bg);
}

.tab-content {
    display: none;
}

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

.tab-content input {
    width: 100%;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
}

.tab-content input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== FAVORITE STAR ===== */
.favorite-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s;
}

.favorite-btn:hover {
    transform: scale(1.2);
}

.favorite-btn.active {
    color: var(--warning);
}

/* ===== STATS ===== */
.app-stats {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 12px;
    padding: 12px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
    display: none !important;
}

.stat-item {
    display: block;
    margin: 6px 0;
    padding: 4px 0;
    font-weight: 500;
}

/* ===== COLOR PICKER ===== */
.color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.color-option {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: var(--text);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .header h1 {
        font-size: 20px;
    }

    .search-bar {
        min-width: 100%;
    }

    .header-right {
        width: 100%;
        justify-content: center;
    }

    .main {
        padding: 20px 15px;
    }

    .add-app-section {
        padding: 20px;
    }

    .add-app-section h2 {
        font-size: 18px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .apps-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 20px;
    }

    .app-image {
        height: 160px;
    }

    .app-content {
        padding: 16px;
    }

    .app-name {
        font-size: 16px;
    }

    .modal-content {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 18px;
    }

    .apps-grid {
        grid-template-columns: 1fr;
    }

    .app-actions {
        flex-direction: column;
    }

    .app-actions .btn {
        width: 100%;
    }

    .modal-footer {
        flex-direction: column;
    }
}
