:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #3b82f6;
    --info-light: #dbeafe;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.view {
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;
}

.btn:hover {
    background-color: #f8fafc;
    border-color: var(--text-muted);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

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

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

.btn.sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn.text {
    border: none;
    background: transparent;
    color: var(--text-muted);
    box-shadow: none;
}

.btn.text:hover {
    color: var(--text-main);
    background-color: var(--bg-body);
    box-shadow: none;
}

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

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

/* Login */
#login-view {
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.login-card h2 {
    margin-bottom: 2rem;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: var(--transition);
    background: white;
}

.form-group input:hover,
.form-group select:hover {
    border-color: var(--text-muted);
}

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

.full-width {
    width: 100%;
}

.error-msg {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 1rem;
    text-align: center;
}

/* Dashboard */
.top-bar {
    background: var(--bg-card);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.logo {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--primary);
    letter-spacing: -0.025em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info #user-display {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.content {
    padding: 2rem;
    max-width: 1280px;
    margin: 0 auto;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    gap: 0.5rem;
    flex: 1;
    max-width: 400px;
}

.search-box input {
    flex: 1;
    min-width: 200px;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: var(--transition);
    background: white;
}

.search-box input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.search-box input:hover {
    border-color: var(--text-muted);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.tab-btn {
    border: none;
    background: transparent;
    padding: 0.75rem 1.25rem;
    border-radius: 0;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
    font-weight: 500;
    position: relative;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn:hover {
    color: var(--text-main);
    background-color: var(--bg-body);
}

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

.tab-content {
    display: none;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    background: var(--bg-body);
    text-align: left;
    padding: 0.875rem 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    border-bottom: 2px solid var(--border);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background-color: var(--bg-body);
}

.pagination {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

#page-info,
#app-page-info {
    font-size: 0.875rem;
    color: var(--text-muted);
    min-width: 120px;
    text-align: center;
}

/* Badges */
.badge {
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge.active {
    background: var(--success-light);
    color: #065f46;
}

.badge.inactive {
    background: #e2e8f0;
    color: #475569;
}

.badge.expired {
    background: var(--danger-light);
    color: #991b1b;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease;
}

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

.modal-content.lg {
    max-width: 900px;
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

.modal-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
}

.checkbox-group input {
    width: auto;
}

small {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.375rem;
    line-height: 1.4;
}

.checkbox-list {
    display: grid;
    gap: 0.625rem;
    max-height: 240px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-body);
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.875rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    cursor: pointer;
}

.checkbox-list label:hover {
    background: white;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    resize: vertical;
    font-family: inherit;
    font-size: 0.875rem;
    transition: var(--transition);
    line-height: 1.5;
}

textarea:hover {
    border-color: var(--text-muted);
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.card h3 {
    margin-bottom: 1.5rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.test-result {
    margin-top: 1.5rem;
    background: #0f172a;
    color: #e2e8f0;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid #1e293b;
}

.test-meta {
    font-size: 0.8125rem;
    color: #94a3b8;
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.test-result pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8125rem;
    line-height: 1.6;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    min-width: 320px;
    max-width: 400px;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    background: white;
    color: var(--text-main);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 200;
    animation: toastSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 4px solid var(--info);
    font-size: 0.875rem;
    font-weight: 500;
}

.toast::before {
    content: '';
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.success::before {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--success);
    color: white;
    font-weight: bold;
    font-size: 14px;
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.error::before {
    content: '✕';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    font-weight: bold;
    font-size: 14px;
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast.warning::before {
    content: '!';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--warning);
    color: white;
    font-weight: bold;
    font-size: 14px;
}

.toast.info {
    border-left-color: var(--info);
}

.toast.info::before {
    content: 'i';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--info);
    color: white;
    font-weight: bold;
    font-size: 14px;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast.hiding {
    animation: toastSlideOut 0.2s cubic-bezier(0.4, 0, 1, 1) forwards;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.empty-state-text {
    font-size: 0.875rem;
}

/* Loading state */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
}

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

/* Responsive design */
@media (max-width: 768px) {
    .content {
        padding: 1rem;
    }

    .top-bar {
        padding: 0.75rem 1rem;
    }

    .logo {
        font-size: 1rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: 100%;
    }

    .table-container {
        border-radius: var(--radius-md);
    }

    th,
    td {
        padding: 0.75rem 0.875rem;
        font-size: 0.8125rem;
    }

    .modal-content {
        padding: 1.5rem;
        max-width: 95%;
    }

    .toast {
        left: 1rem;
        right: 1rem;
        min-width: auto;
        max-width: none;
    }

    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .tab-btn {
        white-space: nowrap;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-body);
}

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

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

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}
