<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>{% block title %}Battery Tracker{% endblock %}</title>
  <link rel="manifest" href="/static/manifest.json">
  <meta name="theme-color" content="#1e40af" media="(prefers-color-scheme: light)">
  <meta name="theme-color" content="#0c1a3b" media="(prefers-color-scheme: dark)">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="apple-mobile-web-app-title" content="Batteries">
  <link rel="apple-touch-icon" href="/static/icon-192.png">
  <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
  <nav>
    <a class="brand" href="{{ url_for('home') }}">Battery Tracker</a>
    <a href="{{ url_for('battery_list') }}">Batteries</a>
    <a href="{{ url_for('device_list') }}">Devices</a>
    <a href="{{ url_for('battery_add') }}">+ Battery</a>
    <a href="{{ url_for('device_add') }}">+ Device</a>
  </nav>

  <div class="container">
    {% with messages = get_flashed_messages(with_categories=true) %}
      {% for category, message in messages %}
        <div class="flash {{ category }}">{{ message }}</div>
      {% endfor %}
    {% endwith %}

    {% block content %}{% endblock %}
  </div>

  <footer style="text-align:center;padding:1.25rem 1rem 1.5rem;margin-top:1rem;
                  border-top:1px solid var(--border);font-size:0.8rem;">
    <a href="{{ url_for('export_page') }}"
       style="color:var(--text-muted);text-decoration:none;"
       onmouseover="this.style.textDecoration='underline'"
       onmouseout="this.style.textDecoration='none'">Export data</a>
    <span style="color:var(--text-muted);margin:0 0.5rem;">·</span>
    <a href="{{ url_for('import_page') }}"
       style="color:var(--text-muted);text-decoration:none;"
       onmouseover="this.style.textDecoration='underline'"
       onmouseout="this.style.textDecoration='none'">Import data</a>
  </footer>

  <div id="confirm-modal" role="dialog" aria-modal="true">
    <div id="confirm-modal-box">
      <p id="confirm-modal-msg"></p>
      <div id="confirm-modal-actions">
        <button id="confirm-modal-cancel" class="btn btn-secondary">Cancel</button>
        <button id="confirm-modal-ok" class="btn btn-danger">Confirm</button>
      </div>
    </div>
  </div>

  <script src="{{ url_for('static', filename='app.js') }}" defer></script>

  <nav class="bottom-nav" aria-label="Main navigation">
    {% set ep = request.endpoint or '' %}
    <a href="{{ url_for('home') }}" class="bottom-nav-item{% if ep == 'home' %} active{% endif %}">
      <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/>
      </svg>
      <span>Home</span>
    </a>
    <a href="{{ url_for('battery_list') }}" class="bottom-nav-item{% if ep == 'battery_list' %} active{% endif %}">
      <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <rect x="2" y="7" width="16" height="10" rx="2"/><path d="M22 11v2"/>
      </svg>
      <span>Batteries</span>
    </a>
    <a href="{{ url_for('device_list') }}" class="bottom-nav-item{% if ep.startswith('device') and ep != 'device_add' %} active{% endif %}">
      <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <rect x="5" y="2" width="14" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/>
      </svg>
      <span>Devices</span>
    </a>
    <a href="{{ url_for('battery_add') }}" class="bottom-nav-item{% if ep == 'battery_add' %} active{% endif %}">
      <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <rect x="2" y="7" width="16" height="10" rx="2"/><path d="M22 11v2"/><line x1="10" y1="11" x2="10" y2="15"/><line x1="8" y1="13" x2="12" y2="13"/>
      </svg>
      <span>+ Battery</span>
    </a>
    <a href="{{ url_for('device_add') }}" class="bottom-nav-item{% if ep == 'device_add' %} active{% endif %}">
      <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/>
      </svg>
      <span>+ Device</span>
    </a>
  </nav>
</body>
</html>
