import { css } from "lit";

/**
 * Shared UI Theme and Common Styles
 *
 * This module provides CSS custom properties (variables) and common style patterns
 * for all UI components to ensure visual consistency across the application.
 *
 * Usage in LitElement components:
 * ```js
 * import { theme } from '../styles/theme.js';
 *
 * static get styles() {
 *   return [
 *     theme,  // Include theme variables
 *     css`...` // Your component-specific styles
 *   ];
 * }
 * ```
 */

/**
 * Theme CSS with custom properties (CSS variables)
 * These can be overridden per-component if needed
 */
export const theme = css`
  :host {
    /* === COLOR PALETTE === */
    /* Primary Colors */
    --color-bg-primary: rgba(0, 0, 0, 0.8);
    --color-bg-secondary: rgba(20, 20, 30, 0.9);
    --color-bg-tertiary: rgba(10, 10, 20, 0.95);
    --color-bg-panel: rgba(20, 20, 30, 0.9);
    --color-bg-card: rgba(0, 0, 0, 0.5);
    --color-bg-overlay: rgba(0, 0, 0, 0.7);
    --color-bg-backdrop: rgba(0, 0, 0, 0.8);

    /* Border Colors */
    --color-border-default: #555;
    --color-border-light: #666;
    --color-border-dark: #333;
    --color-border-dashed: #444;

    /* Accent Colors */
    --color-accent-cyan: #00ffff;
    --color-accent-cyan-dark: #00aaff;
    --color-accent-gold: #ffd700;
    --color-accent-green: #00ff00;
    --color-accent-green-dark: #00cc00;
    --color-accent-red: #ff6666;
    --color-accent-orange: #ffaa00;

    /* Text Colors */
    --color-text-primary: white;
    --color-text-secondary: #aaa;
    --color-text-tertiary: #888;
    --color-text-muted: #666;
    --color-text-accent: #00ffff;
    --color-text-warning: #ffd700;
    --color-text-success: #00ff00;
    --color-text-error: #ff6666;

    /* Status Colors */
    --color-status-buff: #00ff00;
    --color-status-debuff: #ff6666;
    --color-status-active: #ffd700;
    --color-status-available: #00aaff;
    --color-status-locked: #333;

    /* === TYPOGRAPHY === */
    --font-family: "Courier New", monospace;
    --font-size-xs: 0.7rem;
    --font-size-sm: 0.8rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.1rem;
    --font-size-xl: 1.2rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.8rem;
    --font-size-4xl: 2rem;
    --font-size-5xl: 2.4rem;

    --font-weight-normal: normal;
    --font-weight-bold: bold;

    /* === SPACING === */
    --spacing-xs: 5px;
    --spacing-sm: 10px;
    --spacing-md: 15px;
    --spacing-lg: 20px;
    --spacing-xl: 30px;
    --spacing-2xl: 40px;

    /* === BORDERS === */
    --border-width-thin: 1px;
    --border-width-medium: 2px;
    --border-width-thick: 3px;
    --border-radius-sm: 3px;
    --border-radius-md: 4px;
    --border-radius-lg: 10px;

    /* === SHADOWS === */
    --shadow-sm: 0 0 10px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 0 15px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 0 20px rgba(0, 0, 0, 0.8);
    --shadow-glow-cyan: 0 0 15px rgba(0, 255, 255, 0.6);
    --shadow-glow-gold: 0 0 15px rgba(255, 215, 0, 0.6);
    --shadow-glow-green: 0 0 15px rgba(0, 255, 0, 0.5);
    --shadow-glow-red: 0 0 15px rgba(255, 102, 102, 0.5);

    /* === TRANSITIONS === */
    --transition-fast: 0.1s;
    --transition-normal: 0.2s;
    --transition-slow: 0.3s;

    /* === Z-INDEX LAYERS === */
    --z-base: 0;
    --z-overlay: 10;
    --z-modal: 20;
    --z-tooltip: 1000;
  }

  * {
    box-sizing: border-box;
  }
`;

/**
 * Common button styles
 */
export const buttonStyles = css`
  .btn {
    background: var(--color-bg-card);
    border: var(--border-width-medium) solid var(--color-border-default);
    color: var(--color-text-primary);
    padding: var(--spacing-sm) var(--spacing-lg);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    transition: all var(--transition-normal);
    text-transform: uppercase;
    border-radius: var(--border-radius-md);
  }

  .btn:hover:not(:disabled) {
    background: rgba(70, 70, 90, 0.9);
    border-color: var(--color-accent-cyan);
    box-shadow: var(--shadow-glow-cyan);
    transform: translateY(-2px);
  }

  .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--color-bg-card);
    border-color: var(--color-border-dark);
    color: var(--color-text-muted);
  }

  .btn:active:not(:disabled) {
    transform: translateY(0);
  }

  /* Button Variants */
  .btn-primary {
    background: #008800;
    border-color: var(--color-accent-green);
    color: white;
  }

  .btn-primary:hover:not(:disabled) {
    background: #00aa00;
    box-shadow: var(--shadow-glow-green);
  }

  .btn-danger {
    background: transparent;
    border-color: var(--color-accent-red);
    color: var(--color-accent-red);
  }

  .btn-danger:hover:not(:disabled) {
    background: var(--color-accent-red);
    color: white;
  }

  .btn-close {
    background: transparent;
    border: var(--border-width-medium) solid var(--color-accent-red);
    color: var(--color-accent-red);
    width: 40px;
    height: 40px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .btn-close:hover:not(:disabled) {
    background: var(--color-accent-red);
    color: white;
  }
`;

/**
 * Common card/panel styles
 */
export const cardStyles = css`
  .card {
    background: var(--color-bg-card);
    border: var(--border-width-medium) solid var(--color-border-default);
    padding: var(--spacing-lg);
    transition: all var(--transition-normal);
  }

  .card:hover {
    border-color: var(--color-accent-cyan);
    background: rgba(0, 255, 255, 0.1);
  }

  .panel {
    background: var(--color-bg-panel);
    border: var(--border-width-medium) solid var(--color-border-default);
    padding: var(--spacing-lg);
    overflow-y: auto;
  }

  .panel-header {
    background: rgba(0, 0, 0, 0.5);
    border-bottom: var(--border-width-medium) solid var(--color-border-default);
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
`;

/**
 * Common progress bar styles
 */
export const progressBarStyles = css`
  .progress-bar-container {
    width: 100%;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: var(--border-width-thin) solid var(--color-border-default);
    position: relative;
    overflow: hidden;
  }

  .progress-bar-fill {
    height: 100%;
    transition: width var(--transition-slow);
  }

  .progress-bar-fill.hp {
    background: linear-gradient(90deg, #ff0000, #ff6666);
  }

  .progress-bar-fill.ap {
    background: linear-gradient(90deg, #ffaa00, #ffd700);
  }

  .progress-bar-fill.xp {
    background: linear-gradient(90deg, #ffd700, #ffaa00);
  }

  .progress-bar-fill.charge {
    background: linear-gradient(90deg, #0066ff, #00aaff);
  }

  .progress-bar-fill.cyan {
    background: linear-gradient(
      90deg,
      var(--color-accent-cyan),
      var(--color-accent-cyan-dark)
    );
  }

  .progress-bar-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--font-size-xs);
    color: var(--color-text-primary);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    z-index: 1;
  }
`;

/**
 * Common tab styles
 */
export const tabStyles = css`
  .tabs {
    display: flex;
    border-bottom: var(--border-width-medium) solid var(--color-border-default);
  }

  .tab-button {
    flex: 1;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-right: var(--border-width-thin) solid var(--color-border-default);
    color: var(--color-text-secondary);
    padding: var(--spacing-md);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    transition: all var(--transition-normal);
  }

  .tab-button:last-child {
    border-right: none;
  }

  .tab-button:hover {
    background: rgba(0, 255, 255, 0.1);
    color: var(--color-text-primary);
  }

  .tab-button.active {
    background: rgba(0, 255, 255, 0.2);
    color: var(--color-accent-cyan);
    border-bottom: var(--border-width-medium) solid var(--color-accent-cyan);
    margin-bottom: calc(-1 * var(--border-width-medium));
  }

  .tab-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-lg);
    min-height: 0;
  }
`;

/**
 * Common tooltip styles
 */
export const tooltipStyles = css`
  .tooltip {
    background: rgba(0, 0, 0, 0.95);
    border: var(--border-width-medium) solid var(--color-accent-cyan);
    padding: var(--spacing-sm);
    min-width: 200px;
    z-index: var(--z-tooltip);
    color: var(--color-text-primary);
    position: fixed;
    margin: 0;
  }

  .tooltip-title {
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-sm);
    margin-top: 0;
    color: var(--color-accent-cyan);
    font-size: var(--font-size-sm);
  }

  .tooltip-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    font-size: var(--font-size-xs);
    color: var(--color-text-primary);
  }
`;

/**
 * Common modal/dialog styles
 */
export const modalStyles = css`
  dialog {
    background: var(--color-bg-tertiary);
    border: var(--border-width-thick) solid var(--color-border-default);
    box-shadow: var(--shadow-lg);
    padding: 0;
    margin: auto;
    font-family: var(--font-family);
    color: var(--color-text-primary);
  }

  dialog::backdrop {
    background: var(--color-bg-overlay);
    backdrop-filter: blur(4px);
  }
`;

/**
 * Common grid/list styles
 */
export const gridStyles = css`
  .grid {
    display: grid;
    gap: var(--spacing-md);
  }

  .grid-auto-fill {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }

  .grid-auto-fit {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }

  .flex {
    display: flex;
  }

  .flex-column {
    flex-direction: column;
  }

  .flex-center {
    align-items: center;
    justify-content: center;
  }

  .flex-between {
    justify-content: space-between;
  }

  .gap-sm {
    gap: var(--spacing-sm);
  }

  .gap-md {
    gap: var(--spacing-md);
  }

  .gap-lg {
    gap: var(--spacing-lg);
  }
`;

/**
 * Common portrait/icon styles
 */
export const portraitStyles = css`
  .portrait {
    border: var(--border-width-medium) solid var(--color-accent-cyan);
    border-radius: var(--border-radius-md);
    background: rgba(0, 0, 0, 0.8);
    overflow: hidden;
  }

  .portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .icon-button {
    width: 70px;
    height: 70px;
    background: rgba(0, 0, 0, 0.8);
    border: var(--border-width-medium) solid var(--color-border-light);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    position: relative;
    transition: all var(--transition-normal);
    color: var(--color-text-primary);
  }

  .icon-button:hover:not(:disabled) {
    border-color: var(--color-accent-gold);
    box-shadow: var(--shadow-glow-gold);
    transform: translateY(-2px);
  }

  .icon-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: var(--color-border-dark);
  }

  .icon-button.active {
    background: rgba(255, 215, 0, 0.2);
    border-color: var(--color-accent-gold);
    box-shadow: var(--shadow-glow-gold);
  }
`;

/**
 * Common status badge styles
 */
export const badgeStyles = css`
  .badge {
    display: inline-block;
    padding: 2px var(--spacing-sm);
    border-radius: 10px;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
  }

  .badge-success {
    background: var(--color-accent-green);
    color: #000;
  }

  .badge-warning {
    background: var(--color-accent-orange);
    color: #000;
  }

  .badge-info {
    background: var(--color-accent-cyan);
    color: #000;
  }

  .badge-error {
    background: var(--color-accent-red);
    color: white;
  }
`;

/**
 * Common overlay/backdrop styles
 */
export const overlayStyles = css`
  .overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
  }

  .overlay-container.active {
    pointer-events: auto;
  }

  .overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg-backdrop);
    backdrop-filter: blur(4px);
  }

  .overlay-content {
    position: relative;
    z-index: calc(var(--z-modal) + 1);
    width: 90%;
    max-width: 1200px;
    max-height: 90%;
    overflow: auto;
  }
`;

/**
 * Combined common styles - use this for quick inclusion
 */
export const commonStyles = css`
  ${theme}
  ${buttonStyles}
  ${cardStyles}
  ${progressBarStyles}
  ${tabStyles}
  ${tooltipStyles}
  ${modalStyles}
  ${gridStyles}
  ${portraitStyles}
  ${badgeStyles}
  ${overlayStyles}
`;
