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

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warning: #ca8a04;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
}

.navbar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 1.5rem;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 2rem;
}

.nav-brand a {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.account-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    background: var(--gray-100);
    border-radius: 0.25rem;
    color: var(--gray-700);
}

.switch-account {
    font-size: 0.8125rem;
    color: var(--gray-500) !important;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 0.5rem;
}

.nav-links a {
    padding: 0.5rem 1rem;
    color: var(--gray-700);
    text-decoration: none;
    border-radius: 0.375rem;
    transition: background 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--gray-100);
    color: var(--primary);
}

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

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.breadcrumb {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--gray-500);
}

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

.breadcrumb a:hover {
    text-decoration: underline;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

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

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

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-50);
}

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

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

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

.card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

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

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-50);
}

.table tr:hover {
    background: var(--gray-50);
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

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

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--gray-500);
}

.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

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

.badge-warning {
    background: #fef9c3;
    color: var(--warning);
}

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

.badge-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    padding: 1rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.plot-grid {
    display: grid;
    gap: 0.25rem;
    margin-top: 1rem;
}

.plot-grid-header {
    display: contents;
}

.plot-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: transform 0.1s;
    min-height: 50px;
}

.plot-cell:hover {
    transform: scale(1.05);
    z-index: 1;
}

.plot-cell.available {
    background: #dcfce7;
    border: 1px solid #86efac;
}

.plot-cell.occupied {
    background: #fee2e2;
    border: 1px solid #fca5a5;
}

.plot-cell.reserved {
    background: #fef9c3;
    border: 1px solid #fde047;
}

.plot-cell.header {
    background: var(--gray-100);
    font-weight: 600;
    cursor: default;
}

.plot-cell.header:hover {
    transform: none;
}

.plot-cell.row-header {
    background: var(--gray-200);
    font-weight: 600;
    cursor: default;
}

.plot-cell.row-header:hover {
    transform: none;
}

.grid-controls {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.grid-control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.grid-control-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-500);
}

.grid-toggle {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.grid-toggle:hover {
    background: var(--gray-50);
}

.grid-toggle.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.plot-grid.grid-cols-ltr {
    direction: ltr;
}

.plot-grid.grid-cols-rtl {
    direction: rtl;
}

.plot-grid.grid-cols-rtl .plot-cell {
    direction: ltr;
}

.plot-cell.blocked {
    cursor: not-allowed;
    opacity: 0.85;
    position: relative;
}

.plot-cell.blocked::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        rgba(0, 0, 0, 0.05) 3px,
        rgba(0, 0, 0, 0.05) 6px
    );
    pointer-events: none;
    border-radius: 0.25rem;
}

.plot-cell.blocked:hover {
    transform: none;
}

.plot-cell.header.clickable,
.plot-cell.row-header.clickable {
    cursor: pointer;
    transition: background 0.15s;
}

.plot-cell.header.clickable:hover,
.plot-cell.row-header.clickable:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.05);
}

.label-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.label-chip .color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.label-chip.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.label-manager {
    background: var(--gray-50);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.label-manager-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.label-manager-title {
    font-weight: 600;
    font-size: 0.875rem;
}

.labels-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.add-label-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.add-label-form input[type="text"] {
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.25rem;
    width: 120px;
}

.add-label-form input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--gray-300);
    border-radius: 0.25rem;
    cursor: pointer;
}

.block-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.block-mode-toggle label {
    font-size: 0.875rem;
    font-weight: 500;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--gray-300);
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.label-select-dropdown {
    position: absolute;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    z-index: 50;
    min-width: 150px;
}

.label-select-dropdown .label-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.8125rem;
}

.label-select-dropdown .label-option:hover {
    background: var(--gray-100);
}

.label-select-dropdown .label-option .color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.label-select-dropdown .clear-option {
    color: var(--danger);
    border-top: 1px solid var(--gray-200);
    margin-top: 0.25rem;
    padding-top: 0.5rem;
}

.label-select-dropdown .dropdown-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 0.5rem 0;
}

.label-select-dropdown .delete-option {
    color: var(--danger);
    font-weight: 500;
}

.label-select-dropdown .delete-option:hover {
    background: rgba(220, 38, 38, 0.1);
}

.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    background: var(--gray-900);
    color: white;
    font-size: 0.875rem;
    animation: slideIn 0.3s ease;
}

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

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

@keyframes slideIn {
    from {
        transform: translateY(1rem);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: white;
    border-radius: 0.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
}

.modal-body {
    padding: 1.5rem;
}

.htmx-request .btn {
    opacity: 0.7;
    pointer-events: none;
}

.lang-switch {
    padding: 0.5rem 1rem;
    color: var(--gray-500);
    font-size: 0.875rem;
    border-radius: 0.375rem;
    transition: background 0.15s;
}

.lang-switch:hover {
    background: var(--gray-100);
    color: var(--primary);
}

[dir="rtl"] body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
}

[dir="rtl"] .table th,
[dir="rtl"] .table td {
    text-align: right;
}

[dir="rtl"] .breadcrumb {
    flex-direction: row-reverse;
}

[dir="rtl"] .page-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .nav-links {
    flex-direction: row-reverse;
}

[dir="rtl"] .form-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] .table-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] .stats-grid {
    direction: rtl;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    /* Navbar */
    .navbar {
        height: auto;
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 1rem;
    }

    .nav-brand {
        justify-content: space-between;
        width: 100%;
    }

    .nav-links {
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
        text-align: center;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links a {
        display: block;
        width: 100%;
        padding: 0.75rem;
        background-color: var(--gray-50);
        border-radius: 0.375rem;
    }
    
    .nav-links a:hover,
    .nav-links a.active {
        background-color: var(--gray-100);
    }
    
    /* Layout */
    .main-content {
        padding: 1.5rem 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .page-header h1 {
        text-align: center;
        font-size: 1.5rem;
    }

    .page-header > div,
    .page-header form,
    .page-header .btn {
        width: 100%;
        justify-content: center;
        margin-left: 0 !important;
    }
    
    /* Cards */
    .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }
    
    .card-header > div {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Grid Controls in Card Header */
    .grid-controls {
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
    }
    
    .grid-control-group {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Tables */
    .card {
        overflow-x: auto;
    }
    
    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    /* Plot Grid - Horizontal Scroll */
    .plot-cell {
        min-width: 50px;
        min-height: 50px;
    }
    
    /* Modals */
    .modal {
        max-width: 95%;
        margin: 1rem;
        max-height: 90vh;
    }
    
    .modal-header {
        flex-direction: row; 
        align-items: center;
    }
    
    /* RTL Specific Mobile Overrides */
    [dir="rtl"] .page-header {
        flex-direction: column;
    }
    
    [dir="rtl"] .nav-links {
        flex-direction: column;
    }
    
    [dir="rtl"] .form-actions {
        flex-direction: column;
    }
    
    [dir="rtl"] .table-actions {
        flex-direction: column;
    }
    
    .table-actions {
         flex-wrap: wrap;
    }
}
