/* ============================================
   CSS Variables
   ============================================ */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --sidebar-bg: #1f2937;
    --sidebar-text: #9ca3af;
    --sidebar-active: #ffffff;

    --text-color: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;

    --sidebar-width: 250px;
    --header-height: 60px;
    --border-radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

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

html {
    font-size: 14px;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    min-height: 100vh;
}

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

a:hover {
    text-decoration: underline;
}

/* ============================================
   Layout - App Container
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--sidebar-active);
    margin: 0;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 15px 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--sidebar-text);
    transition: all 0.2s;
    text-decoration: none;
}

.sidebar-nav li a:hover,
.sidebar-nav li.active a {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--sidebar-active);
}

.sidebar-nav .icon {
    margin-right: 12px;
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    margin-bottom: 10px;
}

.user-name {
    display: block;
    font-weight: 600;
    color: var(--sidebar-active);
}

.user-email {
    display: block;
    font-size: 0.85rem;
    color: var(--sidebar-text);
}

.logout-btn {
    display: inline-block;
    padding: 8px 16px;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--sidebar-text);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.logout-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--sidebar-active);
    text-decoration: none;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.content-header {
    background-color: var(--card-bg);
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumb {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.breadcrumb a {
    color: var(--text-muted);
}

.breadcrumb .separator {
    margin: 0 8px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.content-body {
    padding: 30px;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

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

.card-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ============================================
   Tables
   ============================================ */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.truncate {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

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

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

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

.btn-secondary:hover {
    background-color: #5a6373;
}

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

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

.btn-danger:hover {
    background-color: #dc2626;
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-block {
    display: block;
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.page-actions {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group input[readonly],
.form-control-plaintext {
    background-color: var(--bg-color);
    cursor: default;
}

.form-hint {
    display: block;
    margin-top: 5px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.required {
    color: var(--danger-color);
}

.error-message {
    display: block;
    color: var(--danger-color);
    font-size: 0.85rem;
    margin-top: 5px;
}

.form-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 200px;
}

.col-md-2 { flex: 0 0 16.666%; max-width: 16.666%; }
.col-md-4 { flex: 0 0 33.333%; max-width: 33.333%; }
.col-md-6 { flex: 0 0 50%; max-width: 50%; }
.col-md-8 { flex: 0 0 66.666%; max-width: 66.666%; }

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.checkbox-label input {
    width: auto;
    margin-right: 8px;
}

.checkbox-list {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
}

.checkbox-item:hover {
    background-color: var(--bg-color);
}

.checkbox-item input {
    margin-right: 10px;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.filter-form .form-group {
    margin-bottom: 0;
}

.filter-buttons {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding-bottom: 0;
}

/* ============================================
   Alerts
   ============================================ */
.alert {
    padding: 15px 20px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* ============================================
   Badges & Status
   ============================================ */
.badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
    text-transform: capitalize;
}

.badge-email {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-telegram {
    background-color: #cffafe;
    color: #0e7490;
}

.badge-pushover {
    background-color: #fce7f3;
    color: #9d174d;
}

.badge-info {
    background-color: #e0e7ff;
    color: #3730a3;
}

.badge-default {
    background-color: var(--bg-color);
    color: var(--text-muted);
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
    text-transform: capitalize;
}

.status-badge.active,
.status-badge.success {
    background-color: #d1fae5;
    color: #065f46;
}

.status-badge.inactive,
.status-badge.failed {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-badge.pending {
    background-color: #fef3c7;
    color: #92400e;
}

/* ============================================
   Modals
   ============================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalFadeIn 0.2s ease;
}

.modal-lg {
    max-width: 700px;
}

.modal-sm {
    max-width: 400px;
}

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

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

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.channel-config {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.channel-config h4 {
    margin-bottom: 15px;
    font-size: 1rem;
    color: var(--text-muted);
}

/* ============================================
   Auth Pages
   ============================================ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 400px;
}

.auth-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.auth-header {
    padding: 30px;
    text-align: center;
    background-color: var(--bg-color);
}

.auth-header h1 {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.auth-header p {
    color: var(--text-muted);
    margin: 0;
}

.auth-form {
    padding: 30px;
}

.auth-footer {
    padding: 20px 30px;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

/* ============================================
   Dashboard
   ============================================ */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.stat-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.bg-primary { background-color: var(--primary-color); }
.bg-success { background-color: var(--success-color); }
.bg-warning { background-color: var(--warning-color); }
.bg-info { background-color: var(--info-color); }

.stat-content h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 5px 0 0;
}

.quick-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 15px 20px;
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.quick-stat {
    display: flex;
    flex-direction: column;
    padding: 0 20px;
    border-right: 1px solid var(--border-color);
}

.quick-stat:last-child {
    border-right: none;
}

.quick-stat .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.quick-stat .value {
    font-size: 1.25rem;
    font-weight: 600;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.activity-list {
    display: flex;
    flex-direction: column;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 6px;
}

.activity-status.status-success { background-color: var(--success-color); }
.activity-status.status-failed { background-color: var(--danger-color); }
.activity-status.status-pending { background-color: var(--warning-color); }

.activity-title {
    font-weight: 500;
    margin-bottom: 4px;
}

.activity-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
}

.activity-meta .time {
    color: var(--text-muted);
}

.channel-distribution,
.api-activity {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.distribution-item,
.api-activity-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
}

.type-icon {
    font-size: 1.25rem;
}

.type-name,
.api-name {
    flex: 1;
    font-weight: 500;
}

.type-count,
.api-count {
    font-weight: 600;
    color: var(--primary-color);
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 35px;
    height: 35px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.2s;
}

.page-link:hover {
    background-color: var(--bg-color);
    text-decoration: none;
}

.page-link.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.page-ellipsis {
    padding: 0 5px;
    color: var(--text-muted);
}

.page-info {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ============================================
   Config Tabs
   ============================================ */
.config-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background-color: var(--card-bg);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-color);
}

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

.tab-content {
    display: none;
}

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

.info-box {
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
    padding: 15px;
    margin-top: 10px;
}

/* ============================================
   Credentials Display
   ============================================ */
.credentials-alert {
    margin-bottom: 20px;
}

.credentials-alert h4 {
    margin-bottom: 10px;
}

.credentials-box {
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
    padding: 15px;
    margin-top: 15px;
}

.credential-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.credential-item:last-child {
    margin-bottom: 0;
}

.credential-item label {
    font-weight: 600;
    min-width: 100px;
}

.credential-item code {
    flex: 1;
    background-color: var(--card-bg);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    word-break: break-all;
}

.api-key-display {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background-color: var(--bg-color);
    padding: 4px 8px;
    border-radius: 4px;
}

/* ============================================
   Log Details
   ============================================ */
.log-details {
    display: grid;
    gap: 15px;
}

.detail-row {
    display: flex;
    gap: 15px;
}

.detail-row label {
    font-weight: 600;
    min-width: 100px;
    color: var(--text-muted);
}

.detail-row.full-width {
    flex-direction: column;
}

.detail-row pre {
    background-color: var(--bg-color);
    padding: 15px;
    border-radius: var(--border-radius);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin: 0;
}

.error-text {
    color: var(--danger-color);
}

/* ============================================
   Toast Notifications
   ============================================ */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 15px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 400px;
    animation: toastSlideIn 0.3s ease;
}

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

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

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

.toast.info {
    background-color: var(--info-color);
    color: white;
}

/* ============================================
   Utility Classes
   ============================================ */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-danger { color: var(--danger-color); }
.text-success { color: var(--success-color); }
.text-warning { color: var(--warning-color); }

/* ============================================
   Error Page
   ============================================ */
.error-page {
    text-align: center;
    padding: 60px 20px;
}

.error-page h1 {
    font-size: 4rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.error-page p {
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .content-body {
        padding: 15px;
    }

    .form-row {
        flex-direction: column;
    }

    .col-md-2, .col-md-4, .col-md-6, .col-md-8 {
        flex: none;
        max-width: none;
    }

    .quick-stats {
        flex-direction: column;
    }

    .quick-stat {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 10px 0;
    }

    .quick-stat:last-child {
        border-bottom: none;
    }

    .btn-group {
        flex-direction: column;
    }

    .pagination {
        justify-content: center;
    }

    .page-info {
        width: 100%;
        text-align: center;
        margin-left: 0;
        margin-top: 10px;
    }
}
