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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
}

/* Navigation Header */
.nav-header {
    background: #1e293b;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
    height: 57px;
    flex-shrink: 0;
}

.nav-header .nav-brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #f8fafc;
}

.nav-header .nav-links {
    display: flex;
    gap: 8px;
}

.nav-header .nav-links a {
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.nav-header .nav-links a:hover,
.nav-header .nav-links a.active {
    color: #f8fafc;
    background: #334155;
}

.nav-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: #f8fafc;
    overflow: hidden;
}

.nav-user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.nav-user-name {
    font-size: 0.875rem;
    color: #e2e8f0;
}

.nav-logout-btn {
    background: #334155;
    border: none;
    color: #94a3b8;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.nav-logout-btn:hover {
    background: #475569;
    color: #e2e8f0;
}

#app {
    display: flex;
    height: calc(100vh - 57px);
}

/* Sidebar */
#sidebar {
    width: 320px;
    background: #1e293b;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    border-right: 1px solid #334155;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f8fafc;
}

.sidebar-header .subtitle {
    color: #94a3b8;
    font-size: 0.875rem;
    margin-top: 4px;
}

.section {
    background: #0f172a;
    border-radius: 12px;
    padding: 16px;
}

.section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin-bottom: 12px;
}

/* Layer Controls */
.layer-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #1e293b;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.layer-toggle:hover {
    background: #334155;
}

.layer-toggle input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.layer-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.layer-name {
    flex: 1;
    font-size: 0.875rem;
}

.layer-count {
    font-size: 0.75rem;
    color: #64748b;
    background: #0f172a;
    padding: 2px 8px;
    border-radius: 12px;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: #334155;
}

.btn-secondary.satellite-active {
    background: #0ea5e9;
    color: white;
}

.btn-secondary.satellite-active:hover {
    background: #0284c7;
}

.btn-secondary-base {
    background: #334155;
    color: #e2e8f0;
    margin-top: 8px;
}

.btn-secondary:hover {
    background: #475569;
}

/* Location Info */
#location-details {
    font-size: 0.875rem;
}

#location-details .address {
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 4px;
}

#location-details .city {
    color: #94a3b8;
    margin-bottom: 8px;
}

#location-details .type-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

#location-details .type-fiber {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

#location-details .type-wireless {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

#location-details .type-customer {
    background: rgba(168, 85, 247, 0.2);
    color: #a855f7;
}

#location-details .customer-name {
    font-weight: 600;
    color: #a855f7;
    margin-bottom: 8px;
}

#location-details .name-drop-hint {
    font-size: 0.75rem;
    color: #64748b;
    font-style: italic;
    margin-top: 8px;
    padding: 8px;
    background: #1e293b;
    border-radius: 6px;
    border-left: 3px solid #a855f7;
}

/* Stats */
.stats-section {
    display: flex;
    gap: 16px;
}

.stat-item {
    flex: 1;
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f8fafc;
    display: block;
}

.stat-label {
    font-size: 0.75rem;
    color: #64748b;
}

/* Map */
#map {
    flex: 1;
    height: 100%;
}

/* Map Popup */
.maplibregl-popup-content {
    background: #1e293b !important;
    color: #e2e8f0;
    border-radius: 12px !important;
    padding: 16px !important;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5) !important;
    min-width: 200px;
}

.maplibregl-popup-tip {
    border-top-color: #1e293b !important;
}

.popup-content .popup-address {
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 4px;
}

.popup-content .popup-city {
    color: #94a3b8;
    font-size: 0.875rem;
    margin-bottom: 8px;
}

.popup-content .popup-type {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.popup-content .popup-type.fiber {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.popup-content .popup-type.wireless {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

.popup-content .popup-type.customer {
    background: rgba(168, 85, 247, 0.2);
    color: #a855f7;
}

.popup-content .popup-type.unreachable {
    background: rgba(107, 114, 128, 0.2);
    color: #6b7280;
}

.popup-content .popup-type.tower {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.popup-content .customer-name {
    color: #a855f7;
    font-weight: 600;
    margin-bottom: 8px;
}

.popup-content .name-drop-hint {
    font-size: 0.75rem;
    color: #64748b;
    font-style: italic;
    margin-top: 8px;
    padding: 8px;
    background: #0f172a;
    border-radius: 6px;
    border-left: 3px solid #a855f7;
}

/* Close button */
.maplibregl-popup-close-button {
    color: #94a3b8 !important;
    font-size: 20px !important;
    padding: 4px 8px !important;
}

.maplibregl-popup-close-button:hover {
    color: #f8fafc !important;
    background: transparent !important;
}

/* Loading overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #334155;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Drawing mode */
.drawing-mode #map {
    cursor: crosshair;
}

/* Territory Selection Styles */
.tool-hint {
    font-size: 0.75rem;
    color: #64748b;
    margin-bottom: 12px;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-success {
    background: #22c55e;
    color: white;
}

.btn-success:hover {
    background: #16a34a;
}

.btn.drawing-active {
    background: #ef4444;
}

.btn.drawing-active:hover {
    background: #dc2626;
}

/* Territory Info in Sidebar */
.territory-info {
    text-align: center;
}

.territory-count {
    font-size: 2.5rem;
    font-weight: 700;
    color: #f59e0b;
    line-height: 1;
}

.territory-label {
    font-size: 0.875rem;
    color: #94a3b8;
    margin-bottom: 12px;
}

.territory-breakdown {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
}

.territory-breakdown .fiber-count {
    color: #22c55e;
    font-size: 0.875rem;
}

.territory-breakdown .wireless-count {
    color: #3b82f6;
    font-size: 0.875rem;
}

.territory-actions {
    display: flex;
    gap: 8px;
}

.territory-actions .btn-assign {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    background: #f59e0b;
    color: #0f172a;
}

.territory-actions .btn-assign:hover {
    background: #d97706;
}

.territory-actions .btn-export {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    background: #334155;
    color: #e2e8f0;
}

.territory-actions .btn-export:hover {
    background: #475569;
}

/* User Info */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 10px 12px;
    background: #0f172a;
    border-radius: 8px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    flex: 1;
    font-size: 0.875rem;
    color: #e2e8f0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    background: #334155;
    color: #94a3b8;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #475569;
    color: #e2e8f0;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    background: #1e293b;
    border-radius: 16px;
    width: 100%;
    /* 480px crammed two side-by-side datetime-local inputs into ~208px each;
       Chrome truncates the date+time string at that width and the modal also
       clipped the title text on tighter viewports. 640px gives ~272px per
       input which fits "MM/DD/YYYY, HH:MM AM" plus the calendar glyph. */
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Stack the side-by-side date inputs on narrower viewports so neither one
   gets clipped to a single character. */
@media (max-width: 700px) {
    .modal-content .form-row {
        grid-template-columns: 1fr;
    }
}

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #f8fafc;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #334155;
    color: #94a3b8;
    font-size: 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #475569;
    color: #f8fafc;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid #334155;
}

/* Assignment Summary */
.assign-summary {
    background: #0f172a;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    margin-bottom: 24px;
}

.summary-stat {
    margin-bottom: 8px;
}

.summary-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #f59e0b;
}

.summary-label {
    font-size: 0.875rem;
    color: #94a3b8;
    display: block;
    margin-top: 4px;
}

.summary-breakdown {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
}

.fiber-badge {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.wireless-badge {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Form Styles */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #e2e8f0;
    margin-bottom: 8px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    color: #f8fafc;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3b82f6;
}

.form-group input::placeholder {
    color: #64748b;
}

.form-group select {
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid #ef4444;
    color: #ef4444;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-top: 16px;
}

.form-hint {
    color: #94a3b8;
    font-size: 0.75rem;
    margin-top: 8px;
    line-height: 1.4;
}

/* Modal button adjustments */
.modal-footer .btn {
    width: auto;
    min-width: 100px;
}

.modal-footer .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
