/*
 * Blitz Panel - Premium UI Stylesheet
 * Inspired by DashStack & Modern Design Systems
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #4a6cf7;
    --primary-hover: #3b5bdb;
    --primary-light: rgba(74, 108, 247, 0.1);
    --dark: #0f172a;
    --sidebar-bg: #1e293b;
    --sidebar-active: #334155;
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #334155;
    --text-muted: #64748b;
    --text-white: #ffffff;
    --border-color: #e2e8f0;
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.1);
    --gray-light: #f1f5f9;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body[data-theme="dark"] {
    --primary: #7c6cff;
    --primary-hover: #6958f0;
    --primary-light: rgba(124, 108, 255, 0.16);
    --dark: #f8fafc;
    --sidebar-bg: #0f172a;
    --sidebar-active: #1e293b;
    --bg-main: #111827;
    --card-bg: #182235;
    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --text-white: #ffffff;
    --border-color: #334155;
    --gray-light: #223049;
    --success-light: rgba(16, 185, 129, 0.14);
    --danger-light: rgba(239, 68, 68, 0.14);
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.25);
    --shadow-md: 0 8px 18px -8px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 20px 35px -18px rgb(0 0 0 / 0.7);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    display: flex;
    min-height: 100vh;
}

/* Layout */
.app-container {
    display: flex;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: transparent;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 18px;
}

.logo-icon img {
    width: 40px;
    height: 40px;
    display: block;
    border-radius: 0;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-menu {
    list-style: none;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.menu-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition);
}

.menu-item a:hover {
    color: var(--text-white);
    background-color: rgba(255, 255, 255, 0.02);
}

.menu-item.active a {
    color: var(--text-white);
    background-color: var(--primary);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.25);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
}

.user-role {
    font-size: 12px;
    color: #64748b;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header */
.main-header {
    height: 70px;
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Content Area */
.content-body {
    padding: 32px;
    overflow-y: auto;
    flex-grow: 1;
}

/* Alerts */
.alert {
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    font-size: 14px;
    animation: fadeIn 0.3s ease;
}

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

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

.alert-danger {
    background-color: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.alert-btn {
    background: none;
    border: none;
    color: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    font-size: 13px;
}

/* Cards & Widgets */
.widgets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.widget-card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.widget-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.widget-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.widget-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.widget-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.5px;
}

.widget-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

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

.icon-success {
    background-color: var(--success-light);
    color: var(--success);
}

.icon-danger {
    background-color: var(--danger-light);
    color: var(--danger);
}

.icon-warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

/* Content Card */
.content-card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 32px;
}

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

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
}

.card-body {
    padding: 32px;
}

/* Info Lists */
.info-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-light);
}

.info-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.info-key {
    font-weight: 500;
    color: var(--text-muted);
}

.info-val {
    font-weight: 600;
    color: var(--dark);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

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

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

.badge-action {
    gap: 6px;
    border: 0;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.badge-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(239, 68, 68, 0.16);
    text-decoration: none;
}

.badge-warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge-gray {
    background-color: var(--gray-light);
    color: var(--text-muted);
}

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

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

.form-control {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-main);
    background-color: var(--bg-main);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--card-bg);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.15);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.2);
}

.btn-secondary {
    background-color: var(--gray-light);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

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

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-icon-only {
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 6px !important;
    flex-shrink: 0;
}

.theme-toggle {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-main);
}

.theme-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

.theme-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.theme-option.active,
.theme-option:has(input:checked) {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Search bar and actions layout */
.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    max-width: 320px;
    width: 100%;
}

.search-box input {
    padding-left: 40px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

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

.table-custom {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table-custom th {
    padding: 12px 18px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-main);
}

.table-custom td {
    padding: 12px 18px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

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

.table-custom tr:hover td {
    background-color: var(--gray-light);
}

.client-name-cell {
    display: flex;
    flex-direction: column;
}

.client-subtext {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    max-width: 760px;
    width: 100%;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

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

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--dark);
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--dark);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
}

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

.config-preview-box {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    word-wrap: break-word;
    max-height: 200px;
    overflow-y: auto;
    color: var(--text-main);
}

.qr-box {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    align-self: center;
}

.qr-box img {
    width: min(220px, 32vw);
    max-width: 100%;
    height: auto;
}

.qr-series {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    width: 100%;
    max-width: 240px;
    justify-self: center;
}

.qr-part-label,
.qr-loading {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.qr-show-btn {
    width: 100%;
    max-width: 180px;
    justify-content: center;
    white-space: nowrap;
}


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

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

/* Login Page Layout */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-main);
}

.login-card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.login-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.login-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.5px;
}

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

@media (max-width: 760px) {
    body {
        display: block;
        min-width: 0;
        overflow-x: hidden;
    }

    .app-container {
        display: block;
        min-width: 0;
    }

    .sidebar {
        width: 100%;
        min-height: auto;
        position: sticky;
        top: 0;
        z-index: 50;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .sidebar-header {
        padding: 12px 14px;
        min-height: 58px;
    }

    .logo-icon,
    .logo-icon img {
        width: 34px;
        height: 34px;
    }

    .logo-text {
        font-size: 16px;
    }

    .sidebar-menu {
        flex-direction: row;
        gap: 6px;
        padding: 8px 10px 12px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }

    .sidebar-menu::-webkit-scrollbar {
        display: none;
    }

    .menu-item {
        flex: 0 0 auto;
    }

    .menu-item a {
        min-height: 40px;
        padding: 9px 12px;
        gap: 8px;
        white-space: nowrap;
        font-size: 13px;
    }

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

    .sidebar-footer {
        display: none;
    }

    .main-content {
        width: 100%;
    }

    .main-header {
        height: auto;
        min-height: 62px;
        padding: 14px 16px;
        align-items: flex-start;
        gap: 12px;
        flex-direction: column;
    }

    .page-title {
        font-size: 18px;
        line-height: 1.25;
    }

    .header-actions {
        width: 100%;
        gap: 8px;
        flex-wrap: wrap;
    }

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

    .content-body {
        padding: 14px;
        overflow: visible;
    }

    .content-card {
        border-radius: 10px;
        margin-bottom: 16px;
    }

    .card-header {
        padding: 16px;
        gap: 12px;
        align-items: flex-start;
        flex-direction: column;
    }

    .card-title {
        font-size: 15px;
        line-height: 1.35;
    }

    .card-body {
        padding: 16px;
    }

    .alert {
        padding: 12px 14px;
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .table-toolbar {
        padding: 14px !important;
        align-items: stretch;
    }

    .search-box {
        max-width: none;
    }

    .table-toolbar > div {
        width: 100%;
    }

    .table-toolbar .btn {
        flex: 1 1 120px;
    }

    .table-responsive {
        margin: 0;
        border-top: 1px solid var(--border-color);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-custom {
        min-width: 760px;
    }

    .table-custom th,
    .table-custom td {
        padding: 12px 14px;
        font-size: 13px;
    }

    .btn {
        min-height: 42px;
        padding: 10px 14px;
        text-align: center;
        white-space: normal;
    }

    .btn-sm {
        min-height: 36px;
    }

    .form-control {
        min-height: 42px;
        font-size: 16px;
    }

    .theme-toggle {
        width: 100%;
        grid-template-columns: 1fr 1fr;
    }

    .info-item {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .modal {
        align-items: stretch;
        justify-content: stretch;
        padding: 8px;
    }

    .modal-content {
        width: 100%;
        max-width: none;
        height: calc(100vh - 16px);
        max-height: calc(100vh - 16px);
        border-radius: 10px;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        padding: 14px 16px;
        flex-shrink: 0;
    }

    .modal-title {
        font-size: 16px;
        line-height: 1.3;
        min-width: 0;
        word-break: break-word;
    }

    .modal-body {
        padding: 16px;
        max-height: none;
        flex: 1 1 auto;
        gap: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-shrink: 0;
    }

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

    .modal-body-layout {
        grid-template-columns: 1fr !important;
        gap: 18px !important;
    }

    .config-preview-box {
        max-height: 220px;
        font-size: 12px;
    }

    .qr-version-grid {
        grid-template-columns: 1fr !important;
        max-width: 280px !important;
        margin: 0 auto;
    }

    .qr-series {
        max-width: 100%;
        min-height: 230px;
    }

    .qr-box img {
        width: min(260px, 78vw);
        max-width: 100%;
    }

    .qr-show-btn {
        max-width: 180px;
    }

    .login-container {
        min-height: 100vh;
        height: auto;
        padding: 18px;
    }

    .login-card {
        padding: 28px 20px;
    }
}

@media (max-width: 420px) {
    .content-body {
        padding: 10px;
    }

    .main-header {
        padding: 12px;
    }

    .card-header,
    .card-body {
        padding: 14px;
    }

    .menu-item a {
        font-size: 12px;
        padding: 8px 10px;
    }

    .table-custom {
        min-width: 720px;
    }
}
