/* =========================================================
   Student Expense Advisor System - Responsive UI Foundation
   ========================================================= */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #0f766e;
  --success: #16a34a;
  --success-dark: #15803d;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
  --text: #1f2937;
  --muted: #64748b;
  --border: #dbe3ec;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --page: #eef7f7;
  --shadow: 0 12px 35px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --brand-navy: #17324d;
  --brand-blue: #2563a6;
  --brand-green: #1d8062;
  --brand-gold: #d7a72b;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    linear-gradient(rgba(247, 251, 253, 0.84), rgba(247, 251, 253, 0.84)),
    url("assets/seas-background.svg") center top / cover fixed,
    linear-gradient(135deg, #f2f9fb 0%, #edf4fb 48%, #f6faf8 100%);
  line-height: 1.55;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
}

body::before {
  width: 280px;
  height: 280px;
  top: -150px;
  right: -110px;
  border-radius: 50%;
  background: rgba(37, 99, 166, 0.045);
}

body::after {
  width: 220px;
  height: 220px;
  bottom: -120px;
  left: -90px;
  border-radius: 50%;
  background: rgba(29, 128, 98, 0.04);
}

a {
  color: inherit;
}

.container {
  width: calc(100% - 48px);
  max-width: 1000px;
  margin: 28px auto;
  padding: 30px 34px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(219, 227, 236, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

/* V3.2: no decorative strip at the top of the main container. */

.container.narrow,
.auth-container {
  width: calc(100% - 48px);
  max-width: 1000px;
}

.page-header {
  text-align: center;
  margin-bottom: 24px;
}

.page-header h1 {
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

.brand-mark {
  width: 72px;
  height: 72px;
  display: block;
  margin: 0 auto 0.5px;
  filter: drop-shadow(0 7px 14px rgba(23, 50, 77, 0.10));
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

h1,
h2,
h3 {
  margin-top: 0;
  line-height: 1.2;
}

h1 {
  margin-bottom: 10px;
  color: var(--brand-navy);
  font-size: clamp(1.75rem, 2.8vw, 2.25rem);
  line-height: 0.8;
  letter-spacing: -0.015em;
}

h2 {
  color: #24435d;
  font-size: clamp(1.12rem, 1.8vw, 1.35rem);
}

h3 {
  font-size: 1.05rem;
}

.page-header p,
.subtitle {
  max-width: 680px;
  margin: 0 auto;
  color: var(--muted);
}

.card {
  margin-top: 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: 15px;
  box-shadow: 0 7px 22px rgba(15, 23, 42, 0.05);
}

.card:hover {
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.card p:last-child {
  margin-bottom: 0;
}

.summary-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.metric {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.metric-value {
  display: block;
  color: #17324d;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.metric.danger-metric {
  border-left: 4px solid var(--danger);
}

.metric.success-metric {
  border-left: 4px solid var(--success);
}

.metric.info-metric {
  border-left: 4px solid var(--info);
}

label {
  display: block;
  margin: 17px 0 7px;
  color: #334155;
  font-weight: 700;
  font-size: 0.94rem;
}

input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  margin: 0;
  border: 1px solid #cbd5e1;
  border-radius: 11px;
  outline: none;
  background: #fff;
  color: var(--text);
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input::placeholder {
  color: #94a3b8;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10);
}

button,
.button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 11px 20px;
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button {
  width: 100%;
  margin-top: 22px;
  background: linear-gradient(135deg, var(--success), #22c55e);
  color: #fff;
  box-shadow: 0 7px 18px rgba(22, 163, 74, 0.18);
}

button:hover,
.button:hover,
.btn:hover {
  transform: translateY(-1px);
}

button:hover {
  background: linear-gradient(135deg, var(--success-dark), var(--success));
}

.button {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.14);
}

.button:hover {
  background: var(--primary-dark);
}

.btn {
  width: 100%;
  margin-top: 20px;
  background: #0f766e;
  color: #fff;
}

.btn:hover {
  background: #0b625b;
}

.logout-btn {
  background: #dc2626;
}

.logout-btn:hover {
  background: #b91c1c;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.actions .button {
  margin: 0;
}

.auth-container {
  margin-top: clamp(28px, 8vh, 70px);
}

.auth-container .page-header {
  margin-bottom: 20px;
}

.auth-container form,
.auth-container .auth-link {
  width: min(100%, 720px);
  margin-left: auto;
  margin-right: auto;
}

.auth-link {
  margin: 20px 0 0;
  text-align: center;
  color: var(--muted);
}

.auth-link a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.auth-link a:hover {
  text-decoration: underline;
}

.flash {
  padding: 12px 14px;
  margin: 0 0 16px;
  border-radius: 10px;
  font-weight: 700;
  border: 1px solid transparent;
}

.flash.success {
  background: #ecfdf3;
  color: #166534;
  border-color: #bbf7d0;
}

.flash.error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.flash.warning {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.danger { color: #b91c1c; }
.warning { color: #b45309; }
.info { color: #1d4ed8; }
.success { color: #15803d; }

.advice-block {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 13px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.advice-block.danger-block { border-left: 5px solid var(--danger); }
.advice-block.warning-block { border-left: 5px solid var(--warning); }
.advice-block.info-block { border-left: 5px solid var(--info); }
.advice-block.success-block { border-left: 5px solid var(--success); }

ul {
  padding-left: 22px;
}

li {
  margin-bottom: 8px;
}

.history-advice {
  margin: 0;
  padding-left: 18px;
}

.history-advice li {
  margin-bottom: 6px;
}

.trend-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}

.trend-list li {
  padding: 12px 14px;
  margin-bottom: 9px;
  border-radius: 11px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.table-container {
  width: 100%;
  margin-top: 20px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  background: #eff6ff;
  color: #1e3a5f;
  font-size: 0.95rem;
  white-space: nowrap;
}

td {
  font-size: 0.79rem;
}

tr:last-child td {
  border-bottom: 0;
}

tr:hover td {
  background: #f8fbff;
}

.history-cards {
  display: none;
}

.empty-state {
  text-align: center;
}

.footer {
  width: calc(100% - 48px);
  max-width: 1000px;
  margin: 0 auto 26px;
  text-align: center;
  color: #64748b;
  font-size: 0.85rem;
}

.footer p {
  margin: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* Dashboard */
.dashboard-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.dashboard-actions .button {
  margin: 0;
  width: 100%;
}

/* Analysis page */
.analysis-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 18px;
}

.analysis-form .full-width,
.analysis-form button {
  grid-column: 1 / -1;
}

/* =========================================================
   UI V2 Responsive System
   Phone: fluid single-column layout.
   Laptop/Desktop: common 1000px maximum container.
   ========================================================= */

@media (max-width: 760px) {
  .container,
  .container.narrow,
  .auth-container {
    width: calc(100% - 28px);
    max-width: none;
    margin: 16px auto;
    padding: 21px 17px;
    border-radius: 15px;
  }

  .auth-container {
    margin-top: 18px;
  }

  .page-header {
    margin-bottom: 20px;
  }

  .brand-mark {
    width: 60px;
    height: 60px;
    margin-bottom: 0.5px;
  }

  h1 {
    font-size: clamp(1.42rem, 6.2vw, 1.78rem);
    line-height: 1.15;
  }

  h2 {
    font-size: 1.18rem;
  }

  .page-header p,
  .subtitle {
    font-size: 0.94rem;
    line-height: 1.5;
  }

  .summary-grid,
  .metric-grid,
  .analysis-form {
    grid-template-columns: 1fr;
  }

  .analysis-form .full-width,
  .analysis-form button {
    grid-column: auto;
  }

  .dashboard-actions {
    grid-template-columns: 1fr;
  }

  .dashboard-actions .button,
  .actions .button {
    width: 100%;
  }

  .card {
    padding: 18px;
    margin-top: 16px;
  }

  .metric {
    padding: 15px;
  }

  .metric-value {
    font-size: 1.12rem;
  }

  label {
    margin-top: 15px;
  }

  input {
    min-height: 47px;
  }

  button,
  .button,
  .btn {
    min-height: 48px;
  }

  .actions {
    flex-direction: column;
    gap: 10px;
  }

  .auth-container form,
  .auth-container .auth-link {
    width: 100%;
  }

  /* Replace the wide history table with readable record cards. */
  .table-container {
    display: none;
  }

  .history-cards {
    display: grid;
    gap: 14px;
    margin-top: 18px;
  }

  .history-card {
    padding: 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  }

  .history-card-date {
    margin: 0 0 12px;
    color: #1e3a5f;
    font-weight: 800;
    font-size: 0.92rem;
  }

  .history-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .history-metric {
    padding: 10px;
    border-radius: 10px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
  }

  .history-metric small {
    display: block;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 3px;
  }

  .history-metric strong {
    overflow-wrap: anywhere;
    font-size: 0.94rem;
  }

  .history-card-advice {
    margin-top: 13px;
    padding-top: 13px;
    border-top: 1px solid var(--border);
  }

  .history-card-advice h3 {
    margin-bottom: 8px;
  }

  .footer {
    width: calc(100% - 28px);
    margin-bottom: 18px;
    font-size: 0.8rem;
  }
}

@media (max-width: 390px) {
  .container,
  .container.narrow,
  .auth-container {
    width: calc(100% - 22px);
    padding: 18px 14px;
  }

  h1 {
    font-size: 1.52rem;
  }

  .brand-mark {
    width: 54px;
    height: 54px;
  }

  .metric-value {
    font-size: 1.05rem;
  }

  .history-metrics {
    grid-template-columns: 1fr;
  }
}

/* Landscape phones: keep the page upright and use the available width. */
@media (max-height: 520px) and (orientation: landscape) {
  .container,
  .container.narrow,
  .auth-container {
    width: calc(100% - 28px);
    max-width: 900px;
    margin: 12px auto;
    padding: 18px 24px;
  }

  .page-header {
    margin-bottom: 12px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
    margin-bottom: 0.5px;
    font-size: 24px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .auth-container .page-header {
    margin-bottom: 10px;
  }

  .auth-container form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 18px;
  }

  .auth-container form button {
    grid-column: 1 / -1;
  }

  .auth-container form label {
    margin-top: 10px;
  }
}
