/* ==================== CSS Variables (Theme Support) ==================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #efefef;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --border-primary: #dddddd;
    --border-secondary: #e2e8f0;
    --accent-primary: #667eea;
    --accent-secondary: #764ba2;
    --accent-hover: #5568d3;
    --success: #38a169;
    --warning: #d69e2e;
    --danger: #e53e3e;
    --info: #3182ce;
    --header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --header-text: #ffffff;
    --button-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --button-text: #ffffff;
    --card-bg: #ffffff;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --input-bg: #ffffff;
    --input-border: #ddd;
    --input-focus-border: #667eea;
    --input-focus-shadow: rgba(102, 126, 234, 0.1);
    --nav-text: #999999;
    --nav-active: #667eea;
    --nav-bg: #ffffff;
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --modal-bg: #ffffff;
    --vip-banner-bg: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    --vip-banner-text: #333333;
    --quota-border-primary: #667eea;
    --quota-border-warning: #f6ad55;
    --quota-border-danger: #fc8181;
    --spinner-bg: #f0f0f0;
    --spinner-border: #667eea;
}

/* ==================== Base Styles ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

/* ==================== Common Utilities ==================== */
.container {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

.full-height {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== Header ==================== */
.header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px var(--card-shadow);
}

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

.header-title {
    font-size: 1.2em;
    font-weight: bold;
    flex: 1;
}

.header-subtitle {
    font-size: 0.8em;
    opacity: 0.8;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--header-text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* ==================== Main Content ==================== */
main {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
    animation: fadeIn 0.3s;
}

.page.active {
    display: block;
}

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

/* ==================== Cards ==================== */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px var(--card-shadow);
    transition: background-color 0.3s;
}

.card-header {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.card-content {
    font-size: 0.9em;
    color: var(--text-secondary);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    font-size: 0.8em;
    color: var(--text-tertiary);
}

/* ==================== Lists ==================== */
.list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.list-item {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid transparent;
}

.list-item:active {
    background: var(--bg-tertiary);
    border-left-color: var(--accent-primary);
    transform: scale(0.98);
}

.list-item-title {
    font-weight: bold;
    margin-bottom: 4px;
}

.list-item-meta {
    font-size: 0.8em;
    color: var(--text-tertiary);
}

/* ==================== Forms ==================== */
.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.form-label {
    font-weight: 500;
    font-size: 0.9em;
}

.form-input,
.form-select,
.form-textarea {
    padding: 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font-size: 1em;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.3s;
}

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

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.form-error {
    color: var(--danger);
    font-size: 0.8em;
    margin-top: 4px;
}

/* ==================== Buttons ==================== */
.btn {
    padding: 12px 16px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    display: inline-block;
    text-decoration: none;
}

.btn-primary {
    background: var(--button-bg);
    color: var(--button-text);
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

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

.btn-secondary:active {
    background: var(--bg-secondary);
}

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

.btn-danger:active {
    background: #d63031;
}

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

.btn-success:active {
    background: #27ae60;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ==================== Badges & Tags ==================== */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 500;
}

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

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

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

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

/* ==================== Quota Info ==================== */
.quota-display {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    border-left: 4px solid var(--quota-border-primary);
}

.quota-display.low {
    border-left-color: var(--quota-border-warning);
}

.quota-display.empty {
    border-left-color: var(--quota-border-danger);
}

.quota-progress {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.quota-progress-bar {
    height: 100%;
    background: var(--accent-primary);
    width: 100%;
    transition: width 0.3s;
}

/* ==================== Loading State ==================== */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--spinner-bg);
    border-top-color: var(--spinner-border);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ==================== Alert Messages ==================== */
.alert {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 0.9em;
    transition: all 0.3s;
}

.alert-info {
    background: var(--info);
    color: white;
    border-left: 4px solid var(--info);
}

.alert-success {
    background: var(--success);
    color: white;
    border-left: 4px solid var(--success);
}

.alert-warning {
    background: var(--warning);
    color: white;
    border-left: 4px solid var(--warning);
}

.alert-error {
    background: var(--danger);
    color: white;
    border-left: 4px solid var(--danger);
}

/* ==================== Modals ==================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-overlay);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.modal {
    background: var(--modal-bg);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 25px var(--card-shadow);
    animation: slideUp 0.3s;
}

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

.modal-header {
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 16px;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-tertiary);
}

/* ==================== Bottom Navigation ==================== */
.bottom-nav {
    background: var(--nav-bg);
    border-top: 1px solid var(--border-secondary);
    padding: 8px 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    position: sticky;
    bottom: 0;
    z-index: 100;
    transition: background-color 0.3s;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    cursor: pointer;
    color: var(--nav-text);
    font-size: 0.75em;
    transition: all 0.2s;
    border-top: 3px solid transparent;
    text-decoration: none;
}

.nav-item.active {
    color: var(--nav-active);
    border-top-color: var(--nav-active);
}

.nav-icon {
    font-size: 1.5em;
}

/* ==================== VIP Banner ==================== */
.vip-banner {
    background: var(--vip-banner-bg);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    text-align: center;
    color: var(--vip-banner-text);
}

.vip-banner-title {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 8px;
}

.vip-banner-desc {
    font-size: 0.9em;
    margin-bottom: 12px;
}

/* ==================== Subscription Plans ==================== */
.plan-card {
    border: 2px solid var(--border-primary);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    transition: all 0.3s;
    background: var(--card-bg);
}

.plan-card.highlighted {
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.plan-name {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 8px;
}

.plan-price {
    font-size: 2em;
    font-weight: bold;
    color: var(--accent-primary);
    margin-bottom: 8px;
}

.plan-period {
    font-size: 0.8em;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.plan-features {
    list-style: none;
    margin-bottom: 16px;
    text-align: left;
    font-size: 0.9em;
}

.plan-features li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-secondary);
}

.plan-features li:last-child {
    border-bottom: none;
}

.plan-features li:before {
    content: "✓ ";
    color: var(--success);
    font-weight: bold;
    margin-right: 8px;
}

/* ==================== Article Content ==================== */
.article-header {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.article-title {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 12px;
    line-height: 1.4;
}

.article-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    color: var(--text-tertiary);
}

.article-body {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 8px;
    line-height: 1.8;
}

.article-body p {
    margin-bottom: 12px;
}

.article-body img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 12px 0;
}

/* ==================== Payment Status ==================== */
.payment-status {
    text-align: center;
    padding: 40px 20px;
}

.payment-status-icon {
    font-size: 4em;
    margin-bottom: 16px;
}

.payment-status-title {
    font-weight: bold;
    font-size: 1.3em;
    margin-bottom: 8px;
}

.payment-status-message {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ==================== Theme Toggle Switch ==================== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    color: var(--text-primary);
}

.theme-toggle:hover {
    background: var(--border-primary);
}

.theme-icon {
    font-size: 1.2em;
}

/* ==================== Responsive ==================== */
@media (max-width: 480px) {
    .header-title {
        font-size: 1em;
    }

    .btn {
        padding: 12px 12px;
        font-size: 0.95em;
    }

    .modal {
        border-radius: 12px 12px 0 0;
    }

    .plan-card.highlighted {
        transform: scale(1.02);
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    main {
        padding: 8px;
    }

    .card {
        padding: 12px;
        margin-bottom: 8px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 0.9em;
    }
}

/* ==================== Admin Dashboard ==================== */
.admin-container {
    display: flex;
    min-height: 100vh;
    background: var(--bg-primary);
}

.admin-sidebar {
    width: 250px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    overflow-y: auto;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}

.admin-brand {
    padding: 0 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
}

.admin-brand h2 {
    font-size: 1.3em;
    margin: 0;
    color: var(--text-primary);
}

.admin-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.admin-menu .menu-item {
    display: block;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.admin-menu .menu-item:hover {
    background: var(--bg-secondary);
    color: var(--accent-primary);
}

.admin-menu .menu-item.active {
    background: var(--bg-secondary);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 600;
}

.admin-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

#admin-body {
    width: 100%;
}

.admin-section {
    margin-bottom: 30px;
}

.admin-section h1 {
    font-size: 1.8em;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.admin-section h2 {
    font-size: 1.3em;
    margin-top: 30px;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.admin-section-divider {
    height: 1px;
    background: var(--border-color);
    margin: 30px 0;
}

.admin-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95em;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.filter-select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95em;
    cursor: pointer;
}

.btn-primary,
.btn-secondary {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

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

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

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

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

/* Admin Tables */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.admin-table thead {
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
}

.admin-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.admin-table tbody tr:hover {
    background: var(--bg-secondary);
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

/* Stat Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.stat-card {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--card-bg);
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.stat-icon {
    font-size: 2em;
    margin-right: 16px;
}

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 0.85em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--text-primary);
}

/* Monitoring Cards */
.monitoring-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.monitoring-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.monitoring-card h3 {
    margin: 0 0 15px 0;
    font-size: 1.1em;
    color: var(--text-primary);
}

.chart-placeholder {
    height: 150px;
    background: var(--bg-secondary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.9em;
    text-align: center;
}

/* Pagination */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 20px 0;
}

#page-info,
#audit-page-info {
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 60px;
    text-align: center;
}

/* Responsive Admin */
@media (max-width: 768px) {
    .admin-container {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        overflow-x: auto;
    }

    .admin-brand {
        display: none;
    }

    .admin-menu {
        display: flex;
        width: 100%;
    }

    .admin-menu .menu-item {
        padding: 12px 16px;
        border-left: none;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
    }

    .admin-menu .menu-item.active {
        border-left: none;
        border-bottom-color: var(--accent-primary);
    }

    .admin-content {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .admin-controls {
        flex-direction: column;
    }

    .search-input {
        flex: 1;
        width: 100%;
    }

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

    .admin-table {
        font-size: 0.85em;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px 12px;
    }
}
