/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

:root {
    --bg-dark: #09070f;
    --panel-bg: rgba(255, 255, 255, 0.03);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    
    --accent-color: #818cf8;
    --accent-gradient: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
    
    --color-new: #818cf8;
    --color-in-work: #fbbf24;
    --color-closed: #34d399;
    --color-rejected: #f87171;
}

body {
    background: radial-gradient(circle at top right, #130f22 0%, var(--bg-dark) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 16px;
    padding-bottom: 90px; /* Safe space for bottom navigation */
    overflow-x: hidden;
}

body.telegram-theme {
    background: var(--tg-theme-bg-color, radial-gradient(circle at top right, #130f22 0%, var(--bg-dark) 100%));
    color: var(--tg-theme-text-color, var(--text-primary));
}

/* App Container (adaptive based on role) */
.app-container {
    max-width: 520px;
    margin: 0 auto;
    position: relative;
    transition: max-width 0.4s ease;
}

.app-container.admin-mode {
    max-width: 1200px;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #09070f;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.4s ease;
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(129, 140, 248, 0.1);
    border-top: 3px solid #818cf8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 20px;
    animation: fadeInDown 0.6s ease;
}

.app-header h1 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, #c084fc 0%, #6366f1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

.app-header .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Section Titles */
.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: #818cf8;
    margin-bottom: 12px;
    padding-left: 4px;
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 20px;
    animation: fadeIn 0.8s ease;
}

.categories-grid .category-card:last-child {
    grid-column: span 3;
}

.category-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.category-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(99, 102, 241, 0.3);
}

.category-card.active {
    background: linear-gradient(135deg, rgba(192, 132, 252, 0.15) 0%, rgba(99, 102, 241, 0.15) 100%);
    border-color: #818cf8;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
    transform: scale(1.02);
}

.category-card .icon {
    font-size: 20px;
    margin-bottom: 6px;
}

.category-card .label {
    font-size: 11px;
    font-weight: 500;
    text-align: center;
    color: #e2e8f0;
}

/* Glass Panel */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Form Fields */
.input-group {
    margin-bottom: 14px;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #cbd5e1;
    margin-bottom: 6px;
    padding-left: 2px;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="file"],
textarea {
    width: 100%;
    background: rgba(15, 12, 32, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px 12px;
    color: #f8fafc;
    font-size: 13px;
    outline: none;
    transition: all 0.2s ease;
    -webkit-user-select: text !important;
    user-select: text !important;
}

input[type="file"] {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    cursor: pointer;
    padding: 14px;
}

input[type="file"]::file-selector-button {
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 12px;
    cursor: pointer;
}

input:focus,
textarea:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    background: rgba(15, 12, 32, 0.7);
}

.margin-top {
    margin-top: 10px;
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: rgba(15, 12, 32, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 3px;
    overflow: hidden;
}

.segmented-control .segment {
    flex: 1;
    cursor: pointer;
    text-align: center;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control span {
    display: block;
    padding: 8px 2px;
    font-size: 11px;
    font-weight: 500;
    color: #94a3b8;
    border-radius: 7px;
    transition: all 0.2s ease;
}

.segmented-control input[type="radio"]:checked + span {
    background: var(--accent-color);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(129, 140, 248, 0.3);
}

/* Submit Button */
.submit-btn {
    width: 100%;
    background: var(--accent-gradient);
    border: none;
    outline: none;
    border-radius: 12px;
    padding: 14px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.25);
}

.submit-btn:hover {
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.submit-btn:active {
    transform: scale(0.99);
}

/* Bottom Navigation Bar */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: rgba(12, 10, 22, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 900;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    outline: none;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
    transition: all 0.25s ease;
    padding: 8px 16px;
    border-radius: 12px;
}

.nav-item .nav-icon {
    font-size: 20px;
    margin-bottom: 4px;
    transition: transform 0.2s ease;
}

.nav-item.active {
    color: #a78bfa;
}

.nav-item.active .nav-icon {
    transform: scale(1.15);
    text-shadow: 0 0 10px rgba(167, 139, 250, 0.5);
}

/* History List & Cards (Buyer & Admin) */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeIn 0.4s ease;
}

.ticket-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-drag: element;
}

.ticket-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.12);
}

.ticket-card.dragging {
    opacity: 0.4;
    border: 1px dashed #818cf8;
}

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

.card-id {
    font-size: 11px;
    font-weight: 700;
    color: #a78bfa;
}

.card-date {
    font-size: 10px;
    color: var(--text-secondary);
}

.card-buyer {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-details-link {
    font-size: 10px;
    color: #818cf8;
}

/* Badges */
.badge {
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-setup { background: rgba(129, 140, 248, 0.12); color: #818cf8; border: 1px solid rgba(129, 140, 248, 0.2); }
.badge-social { background: rgba(244, 63, 94, 0.12); color: #f43f5e; border: 1px solid rgba(244, 63, 94, 0.2); }
.badge-bm { background: rgba(236, 72, 153, 0.12); color: #ec4899; border: 1px solid rgba(236, 72, 153, 0.2); }
.badge-adaccount { background: rgba(168, 85, 247, 0.12); color: #a855f7; border: 1px solid rgba(168, 85, 247, 0.2); }
.badge-proxy { background: rgba(20, 184, 166, 0.12); color: #20b8a6; border: 1px solid rgba(20, 184, 166, 0.2); }
.badge-other { background: rgba(100, 116, 139, 0.12); color: #94a3b8; border: 1px solid rgba(100, 116, 139, 0.2); }
.badge-freeorder { background: rgba(234, 179, 8, 0.12); color: #eab308; border: 1px solid rgba(234, 179, 8, 0.2); }
.badge-rktopup { background: rgba(59, 130, 246, 0.12); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.2); }
.badge-fp { background: rgba(249, 115, 22, 0.12); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.2); }

/* Status Labels & Colors */
.status-badge {
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 9px;
    font-weight: 500;
}

.status-new { background: rgba(129, 140, 248, 0.15); color: var(--color-new); }
.status-in_work { background: rgba(251, 191, 36, 0.15); color: var(--color-in-work); }
.status-closed { background: rgba(52, 211, 153, 0.15); color: var(--color-closed); }
.status-rejected { background: rgba(248, 113, 113, 0.15); color: var(--color-rejected); }

/* Horizontal Tabs (Common) */
.status-tabs-container {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 12px;
    margin-bottom: 12px;
    scrollbar-width: none;
}

.status-tabs-container::-webkit-scrollbar {
    display: none;
}

.buyer-status-tab-btn {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.buyer-status-tab-btn.active {
    background: rgba(255, 255, 255, 0.06);
    border-color: #818cf8;
    color: var(--text-primary);
}

/* KANBAN BOARD WRAPPER (Swipable on mobile, flex on desktop) */
.kanban-wrapper {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

/* Kanban Columns */
.kanban-column {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 14px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    min-height: 480px;
    max-height: calc(100vh - 180px);
    
    /* Mobile-first: Swipable layout */
    flex: 0 0 85vw;
    min-width: 270px;
    max-width: 310px;
    scroll-snap-align: start;
    
    transition: border-color 0.25s, background-color 0.25s;
}

/* Desktop override: Columns side-by-side */
@media (min-width: 768px) {
    .kanban-wrapper {
        justify-content: flex-start;
        scroll-snap-type: none;
    }
    .kanban-column {
        flex: 1;
        min-width: 240px;
        max-width: 280px;
    }
}

.kanban-column.drag-over {
    border-color: #818cf8;
    background: rgba(129, 140, 248, 0.06);
}

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

.column-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 8px;
}

.dot-new { background-color: var(--color-new); box-shadow: 0 0 6px var(--color-new); }
.dot-in_work { background-color: var(--color-in-work); box-shadow: 0 0 6px var(--color-in-work); }
.dot-closed { background-color: var(--color-closed); box-shadow: 0 0 6px var(--color-closed); }
.dot-rejected { background-color: var(--color-rejected); box-shadow: 0 0 6px var(--color-rejected); }

.column-header h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    flex-grow: 1;
}

.column-count {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
}

.column-cards-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding-right: 2px;
    flex-grow: 1;
    min-height: 380px; /* Ensure dropping zone is always big enough */
}

/* Custom Scrollbars */
.column-cards-container::-webkit-scrollbar,
.modal-content::-webkit-scrollbar,
.kanban-wrapper::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

.column-cards-container::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb,
.kanban-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Stats Panel */
.stats-panel {
    padding: 20px 16px;
}

.stat-card-row {
    display: flex;
    gap: 12px;
}

.stat-card {
    flex: 1;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
}

.stat-num {
    font-size: 24px;
    font-weight: 700;
    color: #a78bfa;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 4, 10, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-container {
    background: rgba(20, 18, 30, 0.95);
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 460px;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    animation: zoomIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal-header h3 {
    font-size: 15px;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.modal-content {
    padding: 16px;
    overflow-y: auto;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.meta-value {
    font-size: 12px;
    font-weight: 600;
}

.meta-value.badge {
    align-self: flex-start;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-section h4 {
    font-size: 11px;
    font-weight: 600;
    color: #818cf8;
    margin-bottom: 6px;
}

.details-list {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    padding: 8px 12px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 12px;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-key {
    color: var(--text-secondary);
}

.detail-val {
    font-weight: 500;
    word-break: break-all;
    max-width: 60%;
}

.comment-box {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    min-height: 50px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.15);
}

/* Buttons inside Modal */
.btn {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
    color: #000000;
}

.btn-success {
    background: linear-gradient(135deg, #34d399 0%, #059669 100%);
    color: #ffffff;
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--color-rejected);
    color: var(--color-rejected);
}

/* Utilities */
.hidden {
    display: none !important;
}

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

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

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

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
