:root {
    --bg-dark: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --success-dim: rgba(5, 150, 105, 0.1);
    --danger: #dc2626;
    --danger-dim: rgba(220, 38, 38, 0.1);
    --border: #e2e8f0;
    
    --sidebar-width: 260px;
    --header-height: 80px;
    --font: 'Inter', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
a { text-decoration: none; }

body {
    font-family: var(--font);
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 98;
}

.logo {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
}

.nav-menu {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-menu a {
    text-decoration: none;
    color: var(--text-muted);
    padding: 1rem 1.25rem;
    border-radius: 0.75rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
}

.nav-menu a i { font-size: 1.25rem; }
.nav-menu a:hover, .nav-menu a.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

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

.top-header {
    height: var(--header-height);
    padding: 0 3rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.search-wrapper .search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.25rem;
}

.search-wrapper input {
    width: 100%;
    padding: 1rem 1rem 1rem 3.5rem;
    border-radius: 9999px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-family: var(--font);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.search-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.search-dropdown {
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 0.5rem;
    display: none;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    max-height: 400px;
    overflow-y: auto;
}

.search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--text-main);
    transition: background 0.2s;
}

.search-item:hover { background: var(--bg-card-hover); }

.search-item .item-info { display: flex; flex-direction: column; gap: 0.25rem; }
.search-item .device-name { font-weight: 600; }
.search-item .owner-info { font-size: 0.85rem; color: var(--text-muted); }

/* Layout & Typography */
.content-wrapper { padding: 3rem; }

.page-header { margin-bottom: 2.5rem; }
.page-header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 1rem;}
.page-header p { color: var(--text-muted); font-size: 1.1rem; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.mt-4 { margin-top: 1.5rem; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}
.full-width { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-group label { font-size: 0.9rem; font-weight: 500; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea, .simulated-input {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-family: var(--font);
    font-size: 1rem;
    transition: all 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-family: var(--font);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn i {
    font-size: 0.9rem;
    line-height: 1;
}

.btn-sm {
    padding: 0.45rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 0.4rem;
}

.btn-sm i {
    font-size: 0.85rem;
}

/* Action icon colors */
.btn-icon-view {
    border-color: rgba(15, 23, 42, 0.25);
    color: #0f172a;
}
.btn-icon-print {
    border-color: rgba(14, 116, 144, 0.35);
    color: #0e7490;
}
.btn-icon-edit {
    border-color: rgba(37, 99, 235, 0.35);
    color: #2563eb;
}
.btn-icon-delete {
    border-color: rgba(220, 38, 38, 0.35);
    color: #dc2626;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
.disabled { opacity: 0.5; cursor: not-allowed; }

/* Alerts & Badges */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    margin-bottom: 2rem;
    font-weight: 500;
}
.alert-success { background: var(--success-dim); color: var(--success); border: 1px solid rgba(5, 150, 105, 0.2); }

.badge { padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; }
.badge-pending { background: rgba(217, 119, 6, 0.1); color: #d97706; border: 1px solid rgba(217, 119, 6, 0.2); }
.badge-fixed { background: var(--success-dim); color: var(--success); border: 1px solid rgba(5, 150, 105, 0.2); }
.badge-returned_fixed { background: var(--success-dim); color: var(--success); border: 1px solid rgba(5, 150, 105, 0.2); }
.badge-returned_unfixed { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(220, 38, 38, 0.2); }

.status-badge { font-size: 0.75rem; padding: 0.25rem 0.6rem; border-radius: 0.25rem; font-weight: 600; }
.status-badge.pending { background: rgba(217, 119, 6, 0.1); color: #d97706; }
.status-badge.fixed { background: var(--success-dim); color: var(--success); }

/* Device Details Grid */
.device-details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.detail-card h3 { 
    display: flex; align-items: center; gap: 0.5rem; 
    color: var(--text-muted); font-size: 1.1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.75rem;
}
.detail-card ul { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }
.detail-card li { display: flex; justify-content: space-between; align-items: center; }
.detail-card li span { color: var(--text-muted); font-size: 0.9rem; }
.description-text { color: var(--text-main); line-height: 1.7; font-size: 1.05rem; white-space: pre-wrap; }

.bg-success-dim { background: var(--success-dim); border-color: rgba(5, 150, 105, 0.2); }

.action-bar { display: flex; gap: 1rem; }

/* Tables and Grid */
.grid-2-cols { display: grid; grid-template-columns: 1fr 1.5fr; gap: 2rem; }

.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { padding: 1rem; border-bottom: 1px solid var(--border); color: var(--text-muted); font-weight: 600; font-size: 0.9rem; }
.data-table td { padding: 1rem; border-bottom: 1px solid var(--border); }
.text-danger { color: #f87171; font-weight: 600; }
.text-center { text-align: center; }

/* Profit Loss */
.financial-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2rem; }
.stat-card { display: flex; align-items: center; gap: 1.5rem; }
.stat-icon { width: 60px; height: 60px; border-radius: 1rem; display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.income-card .stat-icon { background: var(--success-dim); color: var(--success); }
.expense-card .stat-icon { background: var(--danger-dim); color: var(--danger); }
.stat-details { display: flex; flex-direction: column; }
.stat-label { color: var(--text-muted); font-size: 0.9rem; font-weight: 500; }
.stat-value { font-size: 2rem; font-weight: 700; }

.profit-card { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4rem 2rem; text-align: center; }
.profit-amount { font-size: 4rem; font-weight: 800; margin: 1rem 0; }
.net-positive .profit-amount { color: var(--success); }
.net-negative .profit-amount { color: var(--danger); }

/* Menu Badges */
.menu-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.35rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: auto;
}
.menu-badge.pending { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.menu-badge.total { background: rgba(59, 130, 246, 0.2); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.4); }

/* ── Customer Autocomplete ── */
.customer-suggestions {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: 0.625rem;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.15);
    z-index: 200;
    overflow: hidden;
    max-height: 240px;
    overflow-y: auto;
}
.cust-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    gap: 0.5rem;
}
.cust-item:not(:last-child) { border-bottom: 1px solid var(--border); }
.cust-item:hover { background: rgba(37, 99, 235, 0.07); }
.cust-name { font-weight: 600; font-size: 0.95rem; color: var(--text-main); }
.cust-phone {
    font-size: 0.82rem;
    color: var(--text-muted);
    background: rgba(37, 99, 235, 0.08);
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    white-space: nowrap;
}

/* Multi-device registration */
.form-section {
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}
.device-entry {
    animation: slideDown 0.3s ease-out;
    position: relative;
    transition: all 0.2s ease;
}
.device-entry:hover {
    border-color: var(--primary) !important;
    background: rgba(37, 99, 235, 0.05) !important;
}
.btn-remove-device {
    padding: 0.4rem 0.8rem !important;
    border-radius: 0.4rem !important;
    font-size: 0.85rem !important;
    transition: all 0.2s;
}
.btn-remove-device:hover {
    background: var(--danger-dim) !important;
    transform: scale(1.05);
}

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

/* Responsive */
@media (max-width: 1024px) {
    .content-wrapper { padding: 2rem; }
    .grid-2-cols { grid-template-columns: 1fr; }
    .financial-grid { grid-template-columns: 1fr; }
    .device-details-grid { grid-template-columns: 1fr; }
    .action-bar { flex-wrap: wrap; }
}

@media (max-width: 768px) {
    .menu-toggle { display: inline-flex; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 99;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }

    .top-header { padding: 0 1rem; }
    .search-wrapper { max-width: 100%; }
    .content-wrapper { padding: 1.25rem; }

    .page-header { margin-bottom: 1.5rem; }
    .page-header h1 { font-size: 1.5rem; }
    .page-header p { font-size: 1rem; }

    .card { padding: 1.25rem; }
    .form-grid { grid-template-columns: 1fr; }
    .form-actions { justify-content: flex-start; flex-wrap: wrap; gap: 0.5rem; }

    .data-table th, .data-table td { padding: 0.75rem; font-size: 0.9rem; }
    .btn { padding: 0.65rem 1.1rem; font-size: 0.95rem; }
    .btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
}

@media (max-width: 480px) {
    .top-header { height: 64px; }
    .logo { height: 64px; }
    .search-wrapper input { padding: 0.8rem 0.9rem 0.8rem 3rem; }
    .search-wrapper .search-icon { left: 1rem; }
    .stat-value { font-size: 1.5rem; }
    .profit-amount { font-size: 2.5rem; }
}
