* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: Tahoma, 'Segoe UI', sans-serif;
    background: #f4f6f9;
    color: #1f2937;
    overflow-x: hidden;
}

body.rtl {
    direction: rtl;
}

body.ltr {
    direction: ltr;
}

body.sidebar-open {
    overflow: hidden;
}

a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Auth layout */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
}

.auth-card {
    background: #fff;
    padding: 32px;
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.auth-card h1 {
    margin-top: 0;
    text-align: center;
    color: #1e3a8a;
    font-size: 22px;
}

/* Admin shell */
.layout {
    min-height: 100vh;
    position: relative;
}

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 260px;
    background: #111827;
    color: #fff;
    z-index: 1100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.25s ease;
}

body.ltr .sidebar {
    left: 0;
    border-right: 1px solid #1f2937;
}

body.rtl .sidebar {
    right: 0;
    left: auto;
    border-left: 1px solid #1f2937;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid #374151;
}

.sidebar .brand {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.4;
    word-break: break-word;
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.sidebar nav a {
    display: block;
    padding: 13px 20px;
    color: #d1d5db;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: #1f2937;
    color: #fff;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1050;
}

.sidebar-backdrop.show {
    display: block;
}

.main {
    min-height: 100vh;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

body.ltr .main {
    margin-left: 260px;
}

body.rtl .main {
    margin-right: 260px;
    margin-left: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.topbar-start {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-title {
    font-weight: 600;
    word-break: break-word;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}

.lang-switch {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 13px;
}

.lang-switch a {
    white-space: nowrap;
}

.content {
    flex: 1;
    padding: 20px;
    width: 100%;
    max-width: 1400px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-header h2 {
    margin: 0;
    font-size: 24px;
}

.card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 20px;
    overflow: hidden;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-box {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.stat-box h3 {
    margin: 0 0 8px;
    font-size: 14px;
    color: #6b7280;
}

.stat-box .value {
    font-size: 24px;
    font-weight: bold;
    color: #111827;
    word-break: break-word;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.table-responsive table {
    min-width: 720px;
}

table th,
table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    text-align: inherit;
    vertical-align: top;
}

table th {
    background: #f9fafb;
    font-weight: 600;
    white-space: nowrap;
}

table td code,
table td pre {
    word-break: break-all;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    max-width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font: inherit;
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.btn {
    display: inline-block;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
}

.btn:hover {
    text-decoration: none;
    opacity: 0.92;
}

.btn-primary { background: #2563eb; color: #fff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-paid { background: #dcfce7; color: #166534; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #e5e7eb; color: #374151; }
.badge-redirecting { background: #dbeafe; color: #1e40af; }
.badge-verified_duplicate { background: #ede9fe; color: #5b21b6; }

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}

.filter-bar input,
.filter-bar select {
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    min-width: 140px;
}

.code-block {
    background: #111827;
    color: #f9fafb;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
}

.text-muted {
    color: #6b7280;
    font-size: 14px;
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    cursor: pointer;
}

.checkbox-inline input {
    width: auto;
    margin: 0;
}

@media (max-width: 992px) {
    body.ltr .main,
    body.rtl .main {
        margin-left: 0;
        margin-right: 0;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    body.rtl .sidebar {
        transform: translateX(100%);
    }

    body.ltr .sidebar.open,
    body.rtl .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close,
    .sidebar-toggle {
        display: inline-flex;
    }

    .content {
        padding: 16px;
    }
}

@media (max-width: 576px) {
    .topbar,
    .page-header,
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .lang-switch {
        width: 100%;
    }

    .filter-bar input,
    .filter-bar select,
    .filter-bar .btn {
        width: 100%;
    }
}
