"""
NOMAZRA — Branded HTML email templates.
Design: "Judicial Glass" — Navy #0A1628, Royal Blue #1B4DFF, Gold #C9A84C.
"""

BASE_STYLE = """
<style>
  body { margin: 0; padding: 0; background-color: #F0F2F5; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
  .wrapper { background-color: #F0F2F5; padding: 40px 20px; }
  .container { max-width: 600px; margin: 0 auto; background: #FFFFFF; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 12px rgba(10,22,40,0.08); }
  .header { background: linear-gradient(135deg, #0A1628 0%, #12233D 100%); padding: 32px 40px; text-align: center; }
  .header h1 { color: #C9A84C; font-size: 28px; font-weight: 700; margin: 0; letter-spacing: 3px; }
  .header p { color: rgba(255,255,255,0.7); font-size: 13px; margin: 8px 0 0; letter-spacing: 1px; }
  .body-content { padding: 40px; color: #1A2332; line-height: 1.7; font-size: 15px; }
  .body-content h2 { color: #0A1628; font-size: 20px; margin: 0 0 16px; }
  .body-content p { margin: 0 0 16px; }
  .code-box { background: #F0F2F5; border: 2px solid #C9A84C; border-radius: 8px; padding: 20px; text-align: center; margin: 24px 0; }
  .code-box .code { font-size: 32px; font-weight: 700; color: #0A1628; letter-spacing: 6px; font-family: 'Courier New', monospace; }
  .code-box .label { font-size: 12px; color: #6B7280; margin-top: 8px; }
  .btn { display: inline-block; background: #1B4DFF; color: #FFFFFF; text-decoration: none; padding: 14px 40px; border-radius: 8px; font-weight: 600; font-size: 15px; margin: 8px 0; }
  .btn:hover { background: #1540D4; }
  .info-box { background: #F8F9FB; border-left: 4px solid #1B4DFF; padding: 16px 20px; margin: 20px 0; border-radius: 0 8px 8px 0; font-size: 14px; color: #374151; }
  .divider { height: 1px; background: #E5E7EB; margin: 24px 0; }
  .footer { background: #F8F9FB; padding: 24px 40px; text-align: center; border-top: 1px solid #E5E7EB; }
  .footer p { color: #9CA3AF; font-size: 12px; margin: 4px 0; }
  .footer a { color: #1B4DFF; text-decoration: none; }
  .gold { color: #C9A84C; }
  .muted { color: #6B7280; font-size: 13px; }
</style>
"""


def _base_template(title, body_html):
    """Wrap body content in the branded email frame."""
    return f"""<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{title}</title>
  {BASE_STYLE}
</head>
<body>
  <div class="wrapper">
    <div class="container">
      <div class="header">
        <h1>NOMAZRA</h1>
        <p>AI LEGAL ASSISTANT</p>
      </div>
      <div class="body-content">
        {body_html}
      </div>
      <div class="footer">
        <p>&copy; 2025 Kelthos Technologies. All rights reserved.</p>
        <p>NOMAZRA &mdash; AI-Powered Legal Intelligence for 140+ Countries</p>
        <p class="muted" style="margin-top: 12px;">
          This email was sent by NOMAZRA. If you did not request this, please ignore it.
        </p>
      </div>
    </div>
  </div>
</body>
</html>"""


def welcome_email(user_name):
    """Welcome email for new account registration."""
    body = f"""
    <h2>Welcome to NOMAZRA, {user_name}!</h2>
    <p>Thank you for creating your account. You now have access to AI-powered legal intelligence covering <strong>140+ countries</strong>.</p>

    <div class="info-box">
      <strong>What you can do with NOMAZRA:</strong><br>
      &bull; Ask legal questions about any country's laws<br>
      &bull; Analyze legal documents with AI<br>
      &bull; Get emergency legal guidance<br>
      &bull; Search laws and statutes<br>
      &bull; Generate contracts and legal drafts<br>
      &bull; Voice consultations with AI legal experts
    </div>

    <p>Your free plan includes <strong>10 queries per day</strong>. Upgrade to unlock unlimited queries, voice features, document analysis, and multi-country access.</p>

    <div class="divider"></div>

    <p style="text-align: center;">
      <a href="https://nomazra.kelthos.com" class="btn">Open NOMAZRA</a>
    </p>

    <p class="muted" style="text-align: center; margin-top: 20px;">
      Need help? Contact us at support@kelthos.com
    </p>
    """
    return _base_template("Welcome to NOMAZRA", body)


def password_reset_email(user_name, reset_code, expiry_minutes=15):
    """Password reset email with verification code."""
    body = f"""
    <h2>Password Reset Request</h2>
    <p>Hi {user_name},</p>
    <p>We received a request to reset your NOMAZRA account password. Use the code below to complete your password reset:</p>

    <div class="code-box">
      <div class="code">{reset_code}</div>
      <div class="label">Password Reset Code &mdash; Expires in {expiry_minutes} minutes</div>
    </div>

    <div class="info-box">
      <strong>Security Notice:</strong> If you did not request a password reset, please ignore this email. Your account remains secure and no changes have been made.
    </div>

    <p class="muted">This code can only be used once and will expire in {expiry_minutes} minutes for your security.</p>

    <div class="divider"></div>

    <p class="muted" style="text-align: center;">
      If you continue to have issues, contact us at support@kelthos.com
    </p>
    """
    return _base_template("Password Reset — NOMAZRA", body)


def reminder_email(user_name, reminder_title, reminder_description, reminder_date):
    """Legal reminder notification email."""
    body = f"""
    <h2>Legal Reminder</h2>
    <p>Hi {user_name},</p>
    <p>This is a reminder you set in NOMAZRA:</p>

    <div class="info-box">
      <strong>{reminder_title}</strong><br>
      {reminder_description if reminder_description else 'No additional details.'}
      <br><br>
      <span class="muted">Scheduled for: {reminder_date}</span>
    </div>

    <p>Don't miss this important date. Open NOMAZRA for related legal information and guidance.</p>

    <div class="divider"></div>

    <p style="text-align: center;">
      <a href="https://nomazra.kelthos.com" class="btn">Open NOMAZRA</a>
    </p>
    """
    return _base_template("Legal Reminder — NOMAZRA", body)


def subscription_confirmation_email(user_name, plan_name, amount, period):
    """Subscription confirmation email."""
    body = f"""
    <h2>Subscription Confirmed <span class="gold">&check;</span></h2>
    <p>Hi {user_name},</p>
    <p>Your NOMAZRA subscription has been activated successfully.</p>

    <div class="info-box">
      <strong>Plan:</strong> NOMAZRA {plan_name}<br>
      <strong>Amount:</strong> ${amount}/{period}<br>
      <strong>Status:</strong> <span style="color: #10B981;">Active</span>
    </div>

    <p>You now have access to all {plan_name} features. Enjoy the full power of AI legal intelligence.</p>

    <div class="divider"></div>

    <p style="text-align: center;">
      <a href="https://nomazra.kelthos.com" class="btn">Start Using NOMAZRA</a>
    </p>

    <p class="muted" style="text-align: center; margin-top: 16px;">
      Manage your subscription in the app under Settings &gt; Subscription.
    </p>
    """
    return _base_template("Subscription Confirmed — NOMAZRA", body)
