/* ===== CSS Variables ===== */
:root {
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --bg-card-hover: #fafbfc;
    --text: #1a1a2e;
    --text-secondary: #64748b;
    --primary: #6C63FF;
    --primary-light: #8b83ff;
    --primary-hover: #5a52d5;
    --primary-glow: rgba(108, 99, 255, 0.15);
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.08), 0 8px 32px rgba(0, 0, 0, 0.06);
    --radius: 16px;
    --radius-sm: 10px;
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.1);
    --success: #22c55e;
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.1);
    --gradient: linear-gradient(135deg, #6C63FF 0%, #a78bfa 100%);
    --gradient-dark: linear-gradient(135deg, #4338ca 0%, #6C63FF 100%);
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #253349;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --primary: #818cf8;
    --primary-light: #a5b4fc;
    --primary-hover: #6C63FF;
    --primary-glow: rgba(129, 140, 248, 0.15);
    --border: #334155;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.3), 0 8px 32px rgba(0, 0, 0, 0.2);
    --danger-light: rgba(239, 68, 68, 0.15);
    --warning-light: rgba(245, 158, 11, 0.15);
    --gradient: linear-gradient(135deg, #818cf8 0%, #c4b5fd 100%);
    --gradient-dark: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.4s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

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

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .header {
    background: rgba(30, 41, 59, 0.85);
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    gap: 8px;
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    letter-spacing: 0.01em;
}

.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
}

.btn-icon:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
    transform: translateY(-1px);
}

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

/* ===== Main ===== */
.main {
    max-width: 720px;
    margin: 0 auto;
    padding: 28px 16px 80px;
}

/* ===== Summary Cards ===== */
.summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 28px;
}

.summary-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid var(--border);
    color: var(--text);
}

.summary-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-glow);
}

.summary-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.summary-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== Search Bar ===== */
.search-bar {
    margin-bottom: 20px;
}

.search-bar input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--bg-card);
    color: var(--text);
    transition: all 0.25s ease;
    box-shadow: var(--shadow);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 1rem;
    pointer-events: none;
}

/* ===== Next Renewal ===== */
.next-renewal {
    background: var(--warning-light);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 24px;
    border: 1px solid rgba(245, 158, 11, 0.2);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.next-renewal-icon {
    font-size: 1.3rem;
}

/* ===== Subscription List ===== */
.sub-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.sub-list-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.subscriptions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sub-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
    border: 1px solid var(--border);
    cursor: default;
    color: var(--text);
}

.sub-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border);
    background: var(--bg-card-hover);
}

.sub-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sub-item:hover .sub-icon {
    transform: scale(1.08);
}

.sub-info {
    flex: 1;
    min-width: 0;
}

.sub-name {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text) !important;
}

.sub-meta {
    font-size: 0.78rem;
    color: var(--text-secondary) !important;
    margin-top: 3px;
}

.sub-price-wrapper {
    text-align: right;
    flex-shrink: 0;
}

.sub-price {
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--text) !important;
}

.sub-cycle-label {
    font-size: 0.7rem;
    color: var(--text-secondary) !important;
    display: block;
    text-align: right;
    margin-top: 2px;
}

.sub-actions {
    display: flex;
    gap: 6px;
    margin-left: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sub-item:hover .sub-actions {
    opacity: 1;
}

.sub-actions button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sub-actions .edit-btn:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.sub-actions .delete-btn:hover {
    border-color: var(--danger);
    background: var(--danger-light);
}

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

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

.empty-state p {
    margin-bottom: 8px;
    font-size: 0.95rem;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: scaleIn 0.25s ease;
}

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

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

/* ===== Templates ===== */
.templates-section {
    margin-bottom: 24px;
}

.templates-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.templates {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
    padding-right: 4px;
}

.template-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.template-btn:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
    transform: translateY(-1px);
}

/* ===== Template Search ===== */
.template-search {
    margin-bottom: 10px;
}

.template-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

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

/* ===== Form ===== */
.sub-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input,
.form-group select {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
    transition: all 0.25s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 8px;
}

/* ===== Settings ===== */
.settings-body {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-group h3 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.setting-row span,
.setting-row label {
    font-size: 0.9rem;
}

.import-label {
    text-align: center;
    cursor: pointer;
}

/* ===== Language Picker ===== */
.lang-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.lang-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.lang-btn:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.lang-btn.active {
    border-color: var(--primary);
    background: var(--primary-glow);
    font-weight: 700;
}

/* ===== Onboarding ===== */
.onboarding {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.onboarding-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 48px 36px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: scaleIn 0.3s ease;
}

.onboarding-card h1 {
    font-size: 1.6rem;
    margin-bottom: 10px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.onboarding-card > p {
    color: var(--text-secondary);
    margin-bottom: 28px;
    line-height: 1.5;
}

.onboarding-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
    text-align: left;
    padding-left: 20px;
}

.step {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 1rem;
    font-weight: 500;
}

.step-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    background: var(--primary-glow);
    flex-shrink: 0;
}

.privacy-note {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 20px;
    line-height: 1.4;
}

/* ===== Category Colors ===== */
.cat-streaming { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.cat-music { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.cat-software { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.cat-gaming { background: rgba(168, 85, 247, 0.12); color: #a855f7; }
.cat-fitness { background: rgba(249, 115, 22, 0.12); color: #f97316; }
.cat-news { background: rgba(99, 102, 241, 0.12); color: #6366f1; }
.cat-cloud { background: rgba(34, 211, 238, 0.12); color: #06b6d4; }
.cat-education { background: rgba(236, 72, 153, 0.12); color: #ec4899; }
.cat-food { background: rgba(234, 179, 8, 0.12); color: #ca8a04; }
.cat-other { background: rgba(148, 163, 184, 0.12); color: #94a3b8; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 20px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 500px) {
    .summary {
        grid-template-columns: 1fr;
    }

    .summary-card {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 14px 18px;
    }

    .summary-card .summary-label {
        margin-bottom: 0;
    }

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

    .header {
        padding: 12px 16px;
    }

    .sub-actions {
        opacity: 1;
        flex-direction: column;
    }

    .main {
        padding: 20px 12px 80px;
    }

    .onboarding-card {
        padding: 32px 24px;
    }

    .modal-content {
        padding: 20px;
    }
}

@media (min-width: 501px) and (max-width: 768px) {
    .main {
        padding: 24px 16px 80px;
    }
}
