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

:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --sidebar: #ffffff;
    --topbar: #ffffff;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;

    --text: #111827;
    --text-soft: #6b7280;
    --border: #e5e7eb;

    --input-bg: #ffffff;
    --input-border: #d1d5db;

    --success: #16a34a;
    --success-bg: #dcfce7;

    --danger: #dc2626;
    --danger-bg: #fee2e2;

    --warning: #f59e0b;
    --warning-bg: #fef3c7;

    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 16px;
}

body.dark,
body[data-theme="dark"] {
    --bg: #0f172a;
    --card: #111827;
    --sidebar: #111827;
    --topbar: #111827;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.16);

    --text: #f9fafb;
    --text-soft: #9ca3af;
    --border: #263244;

    --input-bg: #0f172a;
    --input-border: #334155;

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.15);

    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);

    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.15);

    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.25s ease, color 0.25s ease;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

button {
    cursor: pointer;
}

.hidden {
    display: none !important;
}

.mobile-only {
    display: none !important;
}

/* ================================
   Login Page
================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.18), transparent 35%),
        radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.14), transparent 35%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 34px;
    box-shadow: var(--shadow);
}

.login-logo {
    width: 68px;
    height: 68px;
    margin: 0 auto 18px;
    border-radius: 22px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
}

.login-card h1 {
    text-align: center;
    font-size: 28px;
    margin-bottom: 8px;
}

.login-card p {
    text-align: center;
    color: var(--text-soft);
    margin-bottom: 28px;
}

.password-box {
    display: flex;
    align-items: center;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    border-radius: 12px;
    overflow: hidden;
}

.password-box input {
    border: 0 !important;
    border-radius: 0 !important;
}

.password-box input:focus {
    box-shadow: none !important;
}

.password-box button {
    width: 46px;
    height: 46px;
    border: none;
    background: transparent;
    color: var(--text-soft);
}

/* ================================
   Layout
================================ */

.admin-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    min-width: 280px;
    height: 100vh;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    z-index: 20;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 46px;
    height: 46px;
    border-radius: 15px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.brand h2 {
    font-size: 20px;
    line-height: 1.1;
}

.brand span {
    font-size: 13px;
    color: var(--text-soft);
}

.sidebar-menu {
    flex: 1;
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-item {
    width: 100%;
    height: 48px;
    border: none;
    background: transparent;
    color: var(--text-soft);
    border-radius: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    font-size: 15px;
    font-weight: 600;
    transition: 0.2s ease;
}

.menu-item i {
    width: 22px;
    text-align: center;
}

.menu-item:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.menu-item.active {
    background: var(--primary);
    color: #ffffff;
}

.sidebar-footer {
    padding: 16px 14px;
    border-top: 1px solid var(--border);
}

.logout-btn {
    width: 100%;
    height: 46px;
    border: none;
    border-radius: 14px;
    background: var(--danger-bg);
    color: var(--danger);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.main-content {
    flex: 1;
    min-width: 0;
}

.topbar {
    height: 84px;
    background: var(--topbar);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 15;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar h1 {
    font-size: 24px;
    margin-bottom: 3px;
}

.topbar p {
    color: var(--text-soft);
    font-size: 14px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.theme-toggle {
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--text);
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.admin-profile {
    height: 46px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.admin-profile strong {
    display: block;
    font-size: 14px;
}

.admin-profile small {
    display: block;
    color: var(--text-soft);
    font-size: 12px;
}

.page-wrapper {
    padding: 24px;
}

.page {
    display: none;
}

.page.active-page {
    display: block;
}

/* ================================
   Common Components
================================ */

.content-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.small-card {
    max-width: 760px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.card-header h3 {
    font-size: 20px;
    margin-bottom: 4px;
}

.card-header p {
    color: var(--text-soft);
    font-size: 14px;
}

.btn {
    min-height: 42px;
    border: none;
    border-radius: 12px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s ease;
}

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

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

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

.btn-light:hover {
    filter: brightness(0.96);
}

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

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

.full-btn {
    width: 100%;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 7px;
}

.form-group small {
    display: block;
    margin-top: 7px;
    color: var(--text-soft);
    font-size: 12px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--input-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text);
    padding: 0 13px;
    outline: none;
    font-size: 14px;
    transition: 0.2s ease;
}

textarea {
    min-height: 90px;
    resize: vertical;
    padding-top: 12px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

select {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-soft) 50%),
        linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 20px,
        calc(100% - 12px) 20px;
    background-size: 6px 6px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

/* ================================
   Dashboard
================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 18px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    gap: 14px;
}

.stat-card p {
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 8px;
}

.stat-card h2 {
    font-size: 30px;
}

.stat-card i {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

/* ================================
   Table
================================ */

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

thead {
    background: var(--primary-light);
}

th {
    text-align: left;
    padding: 14px 12px;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
}

td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(37, 99, 235, 0.04);
}

.empty-table {
    text-align: center;
    color: var(--text-soft);
    padding: 28px 12px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.status-active {
    background: var(--success-bg);
    color: var(--success);
}

.status-inactive {
    background: var(--danger-bg);
    color: var(--danger);
}

.status-offer {
    background: var(--warning-bg);
    color: var(--warning);
}

.action-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

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

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

/* ================================
   Package Filter
================================ */

.package-header {
    align-items: flex-start;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

/* ================================
   Modal
================================ */

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.62);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.modal-content {
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.large-modal {
    max-width: 980px;
}

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

.modal-header h3 {
    font-size: 22px;
}

.modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

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

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

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    margin: 6px 0 18px;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    color: var(--text);
}

.checkbox-row input {
    width: 18px;
    min-height: 18px;
}

.offer-fields {
    padding: 16px;
    border: 1px dashed var(--primary);
    border-radius: 16px;
    background: var(--primary-light);
    margin-bottom: 18px;
}

/* ================================
   Features
================================ */

.features-section {
    margin-top: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-title h4 {
    font-size: 17px;
    margin-bottom: 4px;
}

.section-title p {
    font-size: 13px;
    color: var(--text-soft);
}

.features-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feature-item {
    display: grid;
    grid-template-columns: 1fr 1fr 100px 42px;
    gap: 10px;
    align-items: center;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.feature-item input {
    min-height: 42px;
}

.remove-feature-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 12px;
    background: var(--danger-bg);
    color: var(--danger);
}

/* ================================
   Settings Repeat Input
================================ */

.repeat-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

.repeat-item {
    display: flex;
    gap: 10px;
}

.repeat-item input {
    flex: 1;
}

.remove-repeat-btn {
    width: 46px;
    min-width: 46px;
    border: none;
    border-radius: 12px;
    background: var(--danger-bg);
    color: var(--danger);
}

/* ================================
   Loader / Message / Toast
================================ */

.loader {
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.message {
    margin-top: 16px;
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}

.message.success {
    background: var(--success-bg);
    color: var(--success);
}

.message.error {
    background: var(--danger-bg);
    color: var(--danger);
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 200;
    min-width: 280px;
    max-width: 420px;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-weight: 700;
}

.toast.success {
    border-left: 5px solid var(--success);
}

.toast.error {
    border-left: 5px solid var(--danger);
}

.toast.warning {
    border-left: 5px solid var(--warning);
}

/* ================================
   Scrollbar
================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 999px;
}

/* ================================
   Responsive
================================ */

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .filter-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .mobile-only {
        display: flex !important;
    }

    .sidebar {
        position: fixed;
        left: -290px;
        top: 0;
        transition: left 0.25s ease;
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        width: 100%;
    }

    .topbar {
        padding: 0 16px;
    }

    .admin-profile {
        display: none;
    }

    .page-wrapper {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filter-row {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .feature-item {
        grid-template-columns: 1fr;
    }

    .remove-feature-btn {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .login-card {
        padding: 24px;
        border-radius: 20px;
    }

    .topbar {
        height: auto;
        min-height: 78px;
        align-items: flex-start;
        padding-top: 14px;
        padding-bottom: 14px;
        gap: 12px;
    }

    .topbar-left {
        align-items: flex-start;
    }

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

    .topbar p {
        font-size: 12px;
    }

    .topbar-right {
        align-self: center;
    }

    .theme-toggle span {
        display: none;
    }

    .theme-toggle {
        width: 42px;
        padding: 0;
        justify-content: center;
    }

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

    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .card-header .btn {
        width: 100%;
    }

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

    .modal {
        padding: 10px;
    }

    .modal-content {
        padding: 18px;
        border-radius: 18px;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

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

    .checkbox-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-title {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-title .btn {
        width: 100%;
    }

    .repeat-item {
        flex-direction: column;
    }

    .remove-repeat-btn {
        width: 100%;
    }

    .toast {
        left: 14px;
        right: 14px;
        bottom: 14px;
        min-width: auto;
    }
}

/* Prevent login/dashboard flicker before JS auth check */
body.auth-loading #loginPage,
body.auth-loading #adminLayout {
  display: none !important;
}