import { css } from '@design.estate/dees-element';

/**
 * Shared component styles for geo components
 */
export const geoComponentStyles = css`
  :host {
    display: block;
    box-sizing: border-box;
  }

  :host([hidden]) {
    display: none;
  }

  *,
  *::before,
  *::after {
    box-sizing: inherit;
  }
`;

/**
 * Map container styles
 */
export const mapContainerStyles = css`
  .map-container {
    --geo-overlay-inset: 12px;
    --geo-overlay-gap: 8px;

    position: relative;
    width: 100%;
    height: 100%;
    min-height: 300px;
    overflow: hidden;
    border-radius: 8px;
  }

  .map-wrapper {
    position: absolute;
    inset: 0;
  }

  /* Overlay grid for UI elements */
  .map-overlay {
    position: absolute;
    inset: var(--geo-overlay-inset);
    pointer-events: none;
    z-index: 5;

    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "top-left    .      top-right"
      ".           .      ."
      "bottom-left .      bottom-right";
    gap: var(--geo-overlay-gap);
  }

  .map-overlay > * {
    pointer-events: auto;
  }

  .overlay-top-left {
    grid-area: top-left;
    display: flex;
    align-items: flex-start;
    gap: var(--geo-overlay-gap);
  }

  .overlay-top-right {
    grid-area: top-right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--geo-overlay-gap);
  }

  .overlay-bottom-left {
    grid-area: bottom-left;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--geo-overlay-gap);
  }

  .overlay-bottom-right {
    grid-area: bottom-right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--geo-overlay-gap);
  }
`;

/**
 * Toolbar styles
 */
export const toolbarStyles = css`
  .toolbar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.9));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-self: flex-start;
  }

  .toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .toolbar-divider {
    height: 1px;
    margin: 4px 0;
    background: var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
  }

  .tool-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--geo-text, #fff);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .tool-button:hover {
    background: var(--geo-tool-hover, rgba(255, 255, 255, 0.1));
  }

  .tool-button.active {
    background: var(--geo-tool-active, #0084ff);
    color: #fff;
  }

  .tool-button svg {
    width: 20px;
    height: 20px;
  }

  .tool-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
`;

/**
 * Search styles for address search functionality
 */
export const searchStyles = css`
  .search-container {
    width: 280px;
    position: relative;
  }

  .search-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.9));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .search-input-wrapper:focus-within {
    border-color: var(--geo-tool-active, #0084ff);
  }

  .search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
  }

  .search-icon svg {
    width: 16px;
    height: 16px;
  }

  .search-input {
    flex: 1;
    height: 36px;
    padding: 0 12px 0 0;
    border: none;
    background: transparent;
    color: var(--geo-text, #fff);
    font-size: 13px;
    font-family: inherit;
    outline: none;
  }

  .search-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
  }

  .search-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }

  .search-spinner svg {
    width: 16px;
    height: 16px;
    color: rgba(255, 255, 255, 0.5);
    animation: spin 1s linear infinite;
  }

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

  .search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-right: 4px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .search-clear:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
  }

  .search-clear svg {
    width: 14px;
    height: 14px;
  }

  .search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.95));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 20;
  }

  .search-results:empty {
    display: none;
  }

  .search-result {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.1s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }

  .search-result:last-child {
    border-bottom: none;
  }

  .search-result:hover,
  .search-result.highlighted {
    background: rgba(255, 255, 255, 0.1);
  }

  .search-result-name {
    font-size: 13px;
    color: var(--geo-text, #fff);
    line-height: 1.3;
  }

  .search-result-type {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: capitalize;
  }

  .search-no-results {
    padding: 12px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
  }
`;

/**
 * Navigation panel styles for A-to-B routing
 */
export const navigationStyles = css`
  .navigation-panel {
    width: 300px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.95));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
    align-self: flex-start;
  }

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

  .nav-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    color: var(--geo-tool-active, #0084ff);
  }

  .nav-header-icon svg {
    width: 18px;
    height: 18px;
  }

  .nav-header-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--geo-text, #fff);
  }

  .nav-mode-selector {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .nav-mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .nav-mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
  }

  .nav-mode-btn.active {
    background: var(--geo-tool-active, #0084ff);
    color: #fff;
  }

  .nav-mode-btn svg {
    width: 16px;
    height: 16px;
  }

  .nav-inputs {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .nav-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .nav-input-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .nav-input-marker.start {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3);
  }

  .nav-input-marker.end {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
  }

  .nav-input-wrapper {
    flex: 1;
    position: relative;
  }

  .nav-input {
    width: 100%;
    height: 36px;
    padding: 0 36px 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.2);
    color: var(--geo-text, #fff);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
  }

  .nav-input:focus {
    border-color: var(--geo-tool-active, #0084ff);
  }

  .nav-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
  }

  .nav-input.has-value {
    padding-right: 60px;
  }

  .nav-set-map-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .nav-set-map-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
  }

  .nav-set-map-btn.active {
    background: var(--geo-tool-active, #0084ff);
    color: #fff;
  }

  .nav-set-map-btn svg {
    width: 14px;
    height: 14px;
  }

  .nav-input-clear {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: color 0.15s ease;
  }

  .nav-input-clear:hover {
    color: rgba(255, 255, 255, 0.8);
  }

  .nav-input-clear svg {
    width: 12px;
    height: 12px;
  }

  .nav-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.98));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 6px;
    z-index: 20;
  }

  .nav-search-result {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.1s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }

  .nav-search-result:last-child {
    border-bottom: none;
  }

  .nav-search-result:hover,
  .nav-search-result.highlighted {
    background: rgba(255, 255, 255, 0.1);
  }

  .nav-search-result-name {
    font-size: 12px;
    color: var(--geo-text, #fff);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-search-result-type {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: capitalize;
  }

  .nav-actions {
    display: flex;
    gap: 8px;
    padding: 0 12px 12px;
  }

  .nav-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, opacity 0.15s ease;
  }

  .nav-action-btn.primary {
    background: var(--geo-tool-active, #0084ff);
    color: #fff;
  }

  .nav-action-btn.primary:hover:not(:disabled) {
    background: #0073e6;
  }

  .nav-action-btn.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .nav-action-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
  }

  .nav-action-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
  }

  .nav-action-btn svg {
    width: 16px;
    height: 16px;
  }

  .nav-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px;
    background: rgba(0, 132, 255, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .nav-summary-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--geo-text, #fff);
  }

  .nav-summary-item svg {
    width: 16px;
    height: 16px;
    color: var(--geo-tool-active, #0084ff);
  }

  .nav-steps {
    max-height: 250px;
    overflow-y: auto;
  }

  .nav-step {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background-color 0.15s ease;
  }

  .nav-step:last-child {
    border-bottom: none;
  }

  .nav-step:hover {
    background: rgba(255, 255, 255, 0.05);
  }

  .nav-step-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    flex-shrink: 0;
  }

  .nav-step-content {
    flex: 1;
    min-width: 0;
  }

  .nav-step-instruction {
    font-size: 13px;
    color: var(--geo-text, #fff);
    line-height: 1.4;
    margin-bottom: 2px;
  }

  .nav-step-distance {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
  }

  .nav-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(239, 68, 68, 0.15);
    border-top: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    font-size: 12px;
  }

  .nav-error svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .nav-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
  }

  .nav-loading svg {
    width: 18px;
    height: 18px;
    animation: spin 1s linear infinite;
  }

  .nav-empty-steps {
    padding: 16px 12px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
  }

  /* Traffic-aware route info */
  .nav-traffic-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 152, 0, 0.1);
    border-radius: 6px;
    margin: 8px 12px;
  }

  .nav-traffic-info.low {
    background: rgba(0, 200, 83, 0.1);
  }

  .nav-traffic-info.moderate {
    background: rgba(255, 235, 59, 0.15);
  }

  .nav-traffic-info.heavy {
    background: rgba(255, 152, 0, 0.15);
  }

  .nav-traffic-info.severe {
    background: rgba(244, 67, 54, 0.15);
  }

  .nav-traffic-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .nav-traffic-indicator.low {
    background: #00c853;
  }

  .nav-traffic-indicator.moderate {
    background: #ffeb3b;
  }

  .nav-traffic-indicator.heavy {
    background: #ff9800;
  }

  .nav-traffic-indicator.severe {
    background: #f44336;
  }

  .nav-traffic-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
  }

  .nav-traffic-delay {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-left: auto;
  }
`;

/**
 * Traffic control styles
 */
/**
 * Header toolbar styles for toolbar above map
 */
export const headerToolbarStyles = css`
  .geo-component {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
  }

  .header-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.95));
    border-bottom: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    flex-shrink: 0;
    min-height: 52px;
    position: relative;
    z-index: 10;
  }

  .toolbar-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }

  .toolbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 200px;
  }

  .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .header-toolbar .toolbar-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
  }

  /* Header toolbar button styles */
  .header-toolbar .tool-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--geo-text, #fff);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .header-toolbar .tool-button:hover {
    background: var(--geo-tool-hover, rgba(255, 255, 255, 0.1));
  }

  .header-toolbar .tool-button.active {
    background: var(--geo-tool-active, #0084ff);
    color: #fff;
  }

  .header-toolbar .tool-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .header-toolbar .tool-button svg {
    width: 18px;
    height: 18px;
  }

  /* Search container in header */
  .header-toolbar .search-container {
    width: 100%;
    max-width: 300px;
  }

  /* Map container takes remaining space */
  .geo-component .map-container {
    flex: 1;
    position: relative;
    min-height: 0;
  }
`;

/**
 * Traffic control styles
 */
export const trafficStyles = css`
  .traffic-control {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .traffic-toggle-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.9));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    color: var(--geo-text, #fff);
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  }

  .traffic-toggle-btn:hover:not(:disabled) {
    background: var(--geo-tool-hover, rgba(255, 255, 255, 0.15));
  }

  .traffic-toggle-btn.active {
    background: var(--geo-tool-active, #0084ff);
    border-color: var(--geo-tool-active, #0084ff);
    color: #fff;
  }

  .traffic-toggle-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .traffic-toggle-btn svg {
    width: 20px;
    height: 20px;
  }

  .traffic-loading-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.9));
    border-radius: 50%;
  }

  .traffic-loading-indicator svg {
    width: 10px;
    height: 10px;
    animation: spin 1s linear infinite;
  }

  .traffic-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.9));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 6px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .traffic-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #00c853;
    animation: pulse 2s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }

  .traffic-status-text {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
  }

  .traffic-error {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: #f44336;
    cursor: help;
  }

  .traffic-error svg {
    width: 16px;
    height: 16px;
  }

  /* Traffic Legend */
  .traffic-legend {
    padding: 10px 12px;
    background: var(--geo-toolbar-bg, rgba(30, 30, 30, 0.9));
    border: 1px solid var(--geo-toolbar-border, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .traffic-legend-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
  }

  .traffic-legend-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .traffic-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
  }

  .traffic-legend-color {
    width: 16px;
    height: 4px;
    border-radius: 2px;
  }

  .traffic-legend-updated {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
  }
`;
