<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Iniciar sesión — ContaApp</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
  <style>
    body {
      background: #0f1623;
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      font-family: 'Segoe UI', system-ui, sans-serif;
    }
    .auth-wrap { width: 100%; max-width: 420px; padding: 16px; }

    .brand-icon {
      width: 56px; height: 56px; border-radius: 16px;
      background: linear-gradient(135deg,#4f86f7,#3a6fd8);
      display: flex; align-items: center; justify-content: center;
      font-size: 1.5rem; color: #fff;
      margin: 0 auto 16px;
    }

    .auth-card {
      background: #162038;
      border: 1px solid rgba(255,255,255,.08);
      border-radius: 18px;
      padding: 36px 36px 28px;
      box-shadow: 0 20px 60px rgba(0,0,0,.5);
    }
    .auth-card h2 {
      font-size: 1.25rem; font-weight: 700; color: #e2e8f0; margin-bottom: 4px;
    }
    .auth-card .sub {
      font-size: .83rem; color: #64748b; margin-bottom: 28px;
    }

    .form-label { font-size: .82rem; font-weight: 600; color: #94a3b8; }
    .form-control {
      background: #1e2d45; border-color: #2d4a6e; color: #e2e8f0;
      border-radius: 10px; font-size: .9rem; padding: 10px 14px;
    }
    .form-control::placeholder { color: #4a6582; }
    .form-control:focus {
      background: #1e2d45; border-color: #4f86f7; color: #e2e8f0;
      box-shadow: 0 0 0 3px rgba(79,134,247,.2);
    }
    .btn-primary {
      background: #4f86f7; border-color: #4f86f7;
      border-radius: 10px; font-weight: 600;
      padding: 10px; font-size: .9rem;
    }
    .btn-primary:hover { background: #3a6fd8; border-color: #3a6fd8; }

    .divider {
      border-top: 1px solid rgba(255,255,255,.08); margin: 20px 0;
    }
    .link-muted { color: #64748b; font-size: .83rem; text-decoration: none; }
    .link-muted:hover { color: #4f86f7; }
    .link-primary { color: #4f86f7; font-size: .83rem; font-weight: 600; text-decoration: none; }
    .link-primary:hover { text-decoration: underline; }

    .alert {
      border-radius: 10px; border: none;
      background: #3a1515; color: #f87171;
      font-size: .85rem; padding: 10px 14px;
    }
  </style>
</head>
<body>
<div class="auth-wrap">

  <div class="text-center mb-4">
    <div class="brand-icon"><i class="bi bi-building"></i></div>
    <h1 class="text-white fw-bold mb-0" style="font-size:1.6rem">ContaApp</h1>
    <p class="text-muted small mt-1">Gestión Contable Multi-empresa</p>
  </div>

  <div class="auth-card">
    <h2>Bienvenido de nuevo</h2>
    <p class="sub">Introduce tus credenciales para acceder</p>

    {% with msgs = get_flashed_messages(with_categories=true) %}
      {% for cat, msg in msgs %}
        {% if cat == 'success' %}
        <div style="background:#d1fae5;color:#065f46;border-radius:10px;padding:11px 14px;font-size:.88rem;margin-bottom:1rem;font-weight:500;">
          <i class="bi bi-check-circle-fill me-1"></i>{{ msg }}
        </div>
        {% elif cat == 'danger' %}
        <div style="background:#fee2e2;color:#991b1b;border-radius:10px;padding:11px 14px;font-size:.88rem;margin-bottom:1rem;">
          <i class="bi bi-exclamation-circle me-1"></i>{{ msg }}
        </div>
        {% else %}
        <div style="background:#e0f2fe;color:#0c4a6e;border-radius:10px;padding:11px 14px;font-size:.88rem;margin-bottom:1rem;">
          <i class="bi bi-info-circle me-1"></i>{{ msg }}
        </div>
        {% endif %}
      {% endfor %}
    {% endwith %}

    {% if error %}
    <div class="alert mb-3">
      <i class="bi bi-exclamation-circle me-1"></i>{{ error }}
    </div>
    {% endif %}

    <form method="post">
      <div class="mb-3">
        <label class="form-label">Usuario</label>
        <input type="text" name="username" class="form-control"
               placeholder="tu_usuario" required autofocus
               value="{{ request.form.get('username', '') }}">
      </div>
      <div class="mb-4">
        <label class="form-label">Contraseña</label>
        <input type="password" name="password" class="form-control"
               placeholder="••••••••" required>
      </div>
      <button type="submit" class="btn btn-primary w-100">
        <i class="bi bi-box-arrow-in-right me-1"></i>Entrar
      </button>
    </form>

    <div class="divider"></div>
    <div class="text-center">
      <span class="link-muted">¿Aún no tienes cuenta?</span>
      <a href="{{ url_for('auth.registro') }}" class="link-primary ms-1">Regístrate</a>
    </div>
  </div>

</div>
</body>
</html>
