{% extends "base.html" %}
{% block title %}Stock Manager{% endblock %}

{% block content %}
<style>
  :root {
    --primary-color: #10b981;
    --primary-light: #6ee7b7;
    --primary-dark: #059669;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;
    --bg-light: #f0fdf4;
    --bg-card: #ffffff;
    --border-color: #d1fae5;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --shadow-sm: 0 1px 3px rgba(16, 185, 129, 0.12);
    --shadow-md: 0 4px 6px rgba(16, 185, 129, 0.15);
    --shadow-lg: 0 10px 15px rgba(16, 185, 129, 0.2);
  }

  body {
    background: var(--bg-light);
  }

  /* Modern Container */
  .stock-container {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
  }

  /* Section Headers */
  .section-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--primary-color);
  }

  .section-header h2, .section-header h3 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .section-icon {
    font-size: 2rem;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.1));
  }

  /* Filter Section Styling */
  .filter-section {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
  }
  
  .filter-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
  }
  
  .filter-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
  }
  
  .filter-icon {
    font-size: 1.5rem;
  }
  
  .filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
  }
  
  .filter-group {
    flex: 1;
    min-width: 200px;
  }
  
  .filter-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
  }

  /* Beautiful Stock Table */
  .stock-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    font-size: 0.9rem;
  }

  .stock-table thead {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  }

  .stock-table thead th {
    padding: 1rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: white;
    border: none;
    white-space: nowrap;
  }

  .stock-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: all 0.3s ease;
  }

  .stock-table tbody tr:hover {
    background: linear-gradient(90deg, #f0fdf4 0%, #ffffff 100%);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
  }

  .stock-table tbody tr:last-child {
    border-bottom: none;
  }

  .stock-table tbody td {
    padding: 1rem 0.75rem;
    color: var(--text-dark);
    font-size: 0.85rem;
    vertical-align: middle;
  }

  /* ID Badge */
  .id-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 45px;
    padding: 0.4rem 0.7rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
  }

  /* Stock ID Badge */
  .stock-id-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.9rem;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #1e40af;
    border: 1px solid #93c5fd;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.85rem;
  }

  /* Quantity Badges */
  .qty-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border-radius: 16px;
    font-weight: 700;
    font-size: 0.85rem;
  }

  .qty-high {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #065f46;
    border: 1px solid #6ee7b7;
  }

  .qty-medium {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    border: 1px solid #fcd34d;
  }

  .qty-low {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
    border: 1px solid #fca5a5;
  }

  /* Category Badge */
  .category-badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.75rem;
    background: linear-gradient(135deg, #e9d5ff 0%, #d8b4fe 100%);
    color: #6b21a8;
    border: 1px solid #c084fc;
  }

  /* Price Display */
  .price-cell {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary-color);
  }

  /* Item Name Highlight */
  .item-name-cell {
    font-weight: 600;
    color: var(--text-dark);
  }

  /* Action Buttons */
  .action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .btn-action {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
  }

  .btn-action:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }

  .btn-edit {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
  }

  .btn-delete {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
  }

  /* Form Styling */
  .form-control, .form-select {
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
    font-size: 0.95rem;
  }

  .form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
    outline: none;
  }

  .form-label {
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  /* Primary Button */
  .btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    padding: 0.85rem 2rem;
    border-radius: 10px;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .btn-primary:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }

  .btn-secondary {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    border: none;
    padding: 0.85rem 2rem;
    border-radius: 10px;
    font-weight: 700;
    color: white;
  }

  /* Mobile Card Styling */
  @media (max-width: 768px) {
    .stock-container {
      padding: 1.5rem;
      border-radius: 12px;
    }

    .filter-section {
      padding: 1rem;
      margin-bottom: 1.5rem;
    }
    
    .filter-controls {
      flex-direction: column;
      gap: 0.75rem;
    }
    
    .filter-group {
      min-width: 100%;
    }
    
    .mobile-card {
      background: white;
      border-radius: 12px;
      padding: 1.5rem;
      margin-bottom: 1.5rem;
      box-shadow: var(--shadow-md);
      border: 2px solid var(--border-color);
    }
    
    .mobile-card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 1.25rem;
      padding-bottom: 1rem;
      border-bottom: 3px solid var(--primary-color);
    }

    .mobile-stock-id {
      font-size: 1rem;
      font-weight: 800;
      color: var(--text-dark);
    }
    
    .mobile-qty-badge {
      padding: 0.5rem 0.9rem;
      border-radius: 10px;
      font-weight: 800;
      font-size: 0.9rem;
    }
    
    .mobile-card-row {
      display: flex;
      justify-content: space-between;
      align-items: start;
      padding: 0.75rem 0;
      border-bottom: 1px solid #f3f4f6;
      gap: 1rem;
    }

    .mobile-card-row:last-child {
      border-bottom: none;
    }
    
    .mobile-card-label {
      font-weight: 700;
      color: var(--text-light);
      font-size: 0.85rem;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      flex-shrink: 0;
    }
    
    .mobile-card-value {
      color: var(--text-dark);
      text-align: right;
      font-size: 0.9rem;
      font-weight: 600;
      word-break: break-word;
    }
    
    .mobile-card-actions {
      margin-top: 1.25rem;
      padding-top: 1rem;
      border-top: 2px solid var(--border-color);
      display: flex;
      gap: 0.75rem;
      justify-content: flex-end;
    }

    .section-header h2, .section-header h3 {
      font-size: 1.4rem;
    }
    
    .desktop-table {
      display: none;
    }
    
    .mobile-view {
      display: block;
    }

    .btn-mobile-full {
      width: 100%;
      margin-bottom: 0.75rem;
    }
  }
  
  @media (min-width: 769px) {
    .mobile-view {
      display: none;
    }
    
    .desktop-table {
      display: block;
    }
  }

  /* Pagination */
  .pagination {
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .page-item .page-link {
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-dark);
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    transition: all 0.3s ease;
  }

  .page-item.active .page-link {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-color: var(--primary-color);
    color: white;
  }

  .page-item .page-link:hover {
    background: var(--bg-light);
    border-color: var(--primary-color);
    transform: translateY(-2px);
  }

  /* Empty State */
  .empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-light);
  }

  .empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
  }

  /* Scrollable Table */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
</style>

{% if session.get('role') == 'admin' %}
<div class="stock-container">
  <div class="section-header">
    <span class="section-icon">{{ "✏️" if edit_row else "➕" }}</span>
    <h2>{{ "Edit Stock" if edit_row else "Add New Stock" }}</h2>
  </div>

  <form method="POST" class="row g-3">
    <input type="hidden" name="edit_id" value="{{ edit_row.id if edit_row else '' }}">

    <div class="col-md-3">
      <label for="stock_id" class="form-label">📦 Stock ID</label>
      <input type="text" class="form-control" name="stock_id" id="stock_id" value="{{ edit_row.stock_id if edit_row else '' }}" required>
    </div>

    <div class="col-md-3">
      <label for="item_name" class="form-label">📱 Item Name</label>
      <input type="text" class="form-control" name="item_name" id="item_name" value="{{ edit_row.item_name if edit_row else '' }}" required>
    </div>

    <div class="col-md-3">
      <label for="item_category" class="form-label">🏷️ Category</label>
      <input type="text" class="form-control" name="item_category" id="item_category" value="{{ edit_row.item_category if edit_row else '' }}">
    </div>

    <div class="col-md-3">
      <label for="date" class="form-label">📅 Date</label>
      <input type="date" class="form-control" name="date" id="date" value="{{ edit_row.date if edit_row else '' }}">
    </div>

    <div class="col-md-3">
      <label for="order_price" class="form-label">💰 Order Price</label>
      <input type="number" step="0.01" class="form-control" name="order_price" id="order_price" value="{{ edit_row.order_price if edit_row else '' }}">
    </div>

    <div class="col-md-3">
      <label for="logistic_charges" class="form-label">🚚 Logistics</label>
      <input type="number" step="0.01" class="form-control" name="logistic_charges" id="logistic_charges" value="{{ edit_row.logistic_charges if edit_row else '' }}">
    </div>

    <div class="col-md-3">
      <label for="shipping_charges" class="form-label">📦 Shipping</label>
      <input type="number" step="0.01" class="form-control" name="shipping_charges" id="shipping_charges" value="{{ edit_row.shipping_charges if edit_row else '' }}">
    </div>

    <div class="col-md-3">
      <label for="unit_cost" class="form-label">💵 Unit Cost</label>
      <input type="number" step="0.01" class="form-control" name="unit_cost" id="unit_cost" value="{{ edit_row.unit_cost if edit_row else '' }}" required>
    </div>

    <div class="col-md-3">
      <label for="qty" class="form-label">📊 Available Qty</label>
      <input type="number" class="form-control" name="qty" id="qty" value="{{ edit_row.qty if edit_row else '' }}">
    </div>

    <div class="col-md-3">
      <label for="ordered_qty" class="form-label">🛒 Ordered Qty</label>
      <input type="number" class="form-control" name="ordered_qty" id="ordered_qty" value="{{ edit_row.ordered_qty if edit_row else '' }}">
    </div>

    <div class="col-12">
      <button type="submit" class="btn btn-primary btn-mobile-full">
        {{ "💾 Update Stock" if edit_row else "💾 Save Stock" }}
      </button>
      {% if edit_row %}
      <a href="{{ url_for('stock_manage') }}" class="btn btn-secondary ms-2 btn-mobile-full">❌ Cancel</a>
      {% endif %}
    </div>
  </form>
</div>
{% endif %}

<div class="stock-container">
  <div class="section-header">
    <span class="section-icon">📦</span>
    <h3>Stock List</h3>
  </div>

  <!-- Filter Section -->
  <div class="filter-section">
    <div class="filter-header">
      <span class="filter-icon">🔍</span>
      <h3>Search & Filter</h3>
    </div>
    
    <form method="GET" action="{{ url_for('stock_manage') }}" class="filter-controls">
      <div class="filter-group">
        <label for="search" class="form-label">🔍 Search</label>
        <input type="text" class="form-control" name="q" id="search" value="{{ search_query }}" placeholder="Search by ID or name...">
      </div>
      
      <div class="filter-group">
        <label for="category" class="form-label">🏷️ Category</label>
        <select class="form-select" name="category" id="category">
          <option value="All" {% if filter_category == "All" %}selected{% endif %}>All Categories</option>
          {% for cat in categories %}
          <option value="{{ cat.item_category }}" {% if filter_category == cat.item_category %}selected{% endif %}>{{ cat.item_category }}</option>
          {% endfor %}
        </select>
      </div>
      
      <div class="filter-group">
        <label for="stock_level" class="form-label">📊 Stock Level</label>
        <select class="form-select" name="stock_level" id="stock_level">
          <option value="All" {% if filter_stock_level == "All" %}selected{% endif %}>All Levels</option>
          <option value="High" {% if filter_stock_level == "High" %}selected{% endif %}>High (>10)</option>
          <option value="Medium" {% if filter_stock_level == "Medium" %}selected{% endif %}>Medium (1-10)</option>
          <option value="Low" {% if filter_stock_level == "Low" %}selected{% endif %}>Low (1-5)</option>
          <option value="Out" {% if filter_stock_level == "Out" %}selected{% endif %}>Out of Stock</option>
        </select>
      </div>
      
      <div class="filter-group">
        <div class="form-check mt-4">
          <input class="form-check-input" type="checkbox" name="available_only" id="available_only" {% if filter_available_only %}checked{% endif %}>
          <label class="form-check-label" for="available_only">
            ✅ Available Only
          </label>
        </div>
      </div>
      
      <div class="filter-actions">
        <button type="submit" class="btn btn-primary">🔍 Apply Filters</button>
        <a href="{{ url_for('stock_manage') }}" class="btn btn-secondary">🔄 Reset</a>
      </div>
    </form>
  </div>

  <!-- Desktop Table View -->
  <div class="desktop-table">
    <div class="table-responsive">
      <table class="stock-table">
        <thead>
          <tr>
            <th>ID</th>
            <th>Stock ID</th>
            <th>Item Name</th>
            <th>Category</th>
            <th>Date</th>
            <th>Order Price</th>
            <th>Logistics</th>
            <th>Shipping</th>
            <th>Unit Cost</th>
            <th>Qty</th>
            <th>Ordered</th>
            {% if session.get('role') == 'admin' %}
            <th>Actions</th>
            {% endif %}
          </tr>
        </thead>
        <tbody>
          {% for row in stocks %}
          <tr>
            <td><span class="id-badge">#{{ row.id }}</span></td>
            <td><span class="stock-id-badge">{{ row.stock_id }}</span></td>
            <td class="item-name-cell">{{ row.item_name }}</td>
            <td>
              {% if row.item_category %}
              <span class="category-badge">{{ row.item_category }}</span>
              {% else %}
              —
              {% endif %}
            </td>
            <td>{{ row.date or '—' }}</td>
            <td class="price-cell">{{ "Rs. {:,.2f}".format(row.order_price) if row.order_price else '—' }}</td>
            <td class="price-cell">{{ "Rs. {:,.2f}".format(row.logistic_charges) if row.logistic_charges else '—' }}</td>
            <td class="price-cell">{{ "Rs. {:,.2f}".format(row.shipping_charges) if row.shipping_charges else '—' }}</td>
            <td class="price-cell"><strong>{{ "Rs. {:,.2f}".format(row.unit_cost) if row.unit_cost else '—' }}</strong></td>
            <td>
              <span class="qty-badge {% if row.qty > 10 %}qty-high{% elif row.qty > 0 %}qty-medium{% else %}qty-low{% endif %}">
                {% if row.qty > 10 %}✅{% elif row.qty > 0 %}⚠️{% else %}❌{% endif %} {{ row.qty }}
              </span>
            </td>
            <td>{{ row.ordered_qty }}</td>
            {% if session.get('role') == 'admin' %}
            <td>
              <div class="action-buttons">
                <a href="{{ url_for('stock_manage', edit=row.id, page=current_page) }}" class="btn-action btn-edit" title="Edit">✏️</a>
                <a href="{{ url_for('stock_manage', delete=row.id, page=current_page) }}" onclick="return confirmDeleteStock()" class="btn-action btn-delete" title="Delete">🗑️</a>
              </div>
            </td>
            {% endif %}
          </tr>
          {% else %}
          <tr>
            <td colspan="12">
              <div class="empty-state">
                <div class="empty-state-icon">📭</div>
                <p>No stock items found matching your filters</p>
                <a href="{{ url_for('stock_manage') }}" class="btn btn-primary mt-3">🔄 Reset Filters</a>
              </div>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>

  <!-- Mobile Card View -->
  <div class="mobile-view">
    {% for row in stocks %}
    <div class="mobile-card">
      <div class="mobile-card-header">
        <span class="mobile-stock-id">{{ row.stock_id }}</span>
        <span class="mobile-qty-badge qty-badge {% if row.qty > 10 %}qty-high{% elif row.qty > 0 %}qty-medium{% else %}qty-low{% endif %}">
          {% if row.qty > 10 %}✅{% elif row.qty > 0 %}⚠️{% else %}❌{% endif %} Qty: {{ row.qty }}
        </span>
      </div>
      
      <div class="mobile-card-row">
        <span class="mobile-card-label">📱 Item</span>
        <span class="mobile-card-value"><strong>{{ row.item_name }}</strong></span>
      </div>
      
      {% if row.item_category %}
      <div class="mobile-card-row">
        <span class="mobile-card-label">🏷️ Category</span>
        <span class="mobile-card-value">
          <span class="category-badge">{{ row.item_category }}</span>
        </span>
      </div>
      {% endif %}
      
      {% if row.date %}
      <div class="mobile-card-row">
        <span class="mobile-card-label">📅 Date</span>
        <span class="mobile-card-value">{{ row.date }}</span>
      </div>
      {% endif %}
      
      {% if row.order_price %}
      <div class="mobile-card-row">
        <span class="mobile-card-label">💰 Order Price</span>
        <span class="mobile-card-value price-cell">Rs. {{ "{:,.2f}".format(row.order_price) }}</span>
      </div>
      {% endif %}
      
      {% if row.logistic_charges %}
      <div class="mobile-card-row">
        <span class="mobile-card-label">🚚 Logistics</span>
        <span class="mobile-card-value price-cell">Rs. {{ "{:,.2f}".format(row.logistic_charges) }}</span>
      </div>
      {% endif %}
      
      {% if row.shipping_charges %}
      <div class="mobile-card-row">
        <span class="mobile-card-label">📦 Shipping</span>
        <span class="mobile-card-value price-cell">Rs. {{ "{:,.2f}".format(row.shipping_charges) }}</span>
      </div>
      {% endif %}
      
      <div class="mobile-card-row">
        <span class="mobile-card-label">💵 Unit Cost</span>
        <span class="mobile-card-value price-cell"><strong>Rs. {{ "{:,.2f}".format(row.unit_cost) }}</strong></span>
      </div>
      
      <div class="mobile-card-row">
        <span class="mobile-card-label">🛒 Ordered Qty</span>
        <span class="mobile-card-value">{{ row.ordered_qty }}</span>
      </div>
      
      {% if session.get('role') == 'admin' %}
      <div class="mobile-card-actions">
        <a href="{{ url_for('stock_manage', edit=row.id, page=current_page) }}" class="btn-action btn-edit">✏️ Edit</a>
        <a href="{{ url_for('stock_manage', delete=row.id, page=current_page) }}" 
           onclick="return confirmDeleteStock()" 
           class="btn-action btn-delete">🗑️ Delete</a>
      </div>
      {% endif %}
    </div>
    {% else %}
    <div class="empty-state">
      <div class="empty-state-icon">📭</div>
      <p>No stock items found matching your filters</p>
      <a href="{{ url_for('stock_manage') }}" class="btn btn-primary mt-3">🔄 Reset Filters</a>
    </div>
    {% endfor %}
  </div>
</div>

<!-- Pagination -->
<nav>
  <ul class="pagination justify-content-center mt-4">
    {% if current_page > 1 %}
    <li class="page-item">
      <a class="page-link" href="?page={{ current_page - 1 }}{% if search_query %}&q={{ search_query }}{% endif %}{% if filter_category != 'All' %}&category={{ filter_category }}{% endif %}{% if filter_available_only %}&available_only=on{% endif %}{% if filter_stock_level != 'All' %}&stock_level={{ filter_stock_level }}{% endif %}">« Prev</a>
    </li>
    {% endif %}
    
    {% for page_num in range(1, total_pages + 1) %}
    <li class="page-item {% if page_num == current_page %}active{% endif %}">
      <a class="page-link" href="?page={{ page_num }}{% if search_query %}&q={{ search_query }}{% endif %}{% if filter_category != 'All' %}&category={{ filter_category }}{% endif %}{% if filter_available_only %}&available_only=on{% endif %}{% if filter_stock_level != 'All' %}&stock_level={{ filter_stock_level }}{% endif %}">{{ page_num }}</a>
    </li>
    {% endfor %}
    
    {% if current_page < total_pages %}
    <li class="page-item">
      <a class="page-link" href="?page={{ current_page + 1 }}{% if search_query %}&q={{ search_query }}{% endif %}{% if filter_category != 'All' %}&category={{ filter_category }}{% endif %}{% if filter_available_only %}&available_only=on{% endif %}{% if filter_stock_level != 'All' %}&stock_level={{ filter_stock_level }}{% endif %}">Next »</a>
    </li>
    {% endif %}
  </ul>
</nav>

<script>
  function confirmDeleteStock() {
    if (!confirm("Are you sure you want to delete this stock?")) return false;
    const password = prompt("Enter password to confirm deletion:");
    if (password === "12345") return true;
    alert("❌ Incorrect password. Deletion canceled.");
    return false;
  }
</script>
{% endblock %}