/* Tyres CRM — shared theme: soft green gradient, layered depth, mobile-first */

:root {
  --primary: #2f9e44;
  --primary-dark: #1f7a34;
  --primary-light: #eafbf0;
  --accent: #66d98a;
  --accent-2: #9be8ac;
  --bg-1: #eafcf1;
  --bg-2: #d3f4dd;
  --bg-3: #bcedd0;
  --card-bg: #ffffff;
  --text: #12291a;
  --text-muted: #5c7a68;
  --border: #d7f0e0;
  --danger: #e0554f;
  --warn: #d99a2b;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 2px 10px rgba(31, 122, 52, 0.08);
  --shadow-md: 0 10px 28px rgba(31, 122, 52, 0.14);
  --shadow-lg: 0 20px 48px rgba(31, 122, 52, 0.2);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: 'Noto Sans Thai', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-2) 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--bg-3) 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1) 0%, #f4fdf7 55%, var(--bg-1) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 0 88px 0;
  position: relative;
}
.app-shell.wide { max-width: 1180px; padding-bottom: 24px; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--primary-dark);
}
.brand .logo-dot {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  color: white; font-size: 18px;
}
.topbar .icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: 16px;
}

/* ---- membership card ---- */
.member-card {
  margin: 4px 20px 20px;
  border-radius: var(--radius-lg);
  padding: 22px;
  color: white;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--accent) 130%);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.member-card::after {
  content: "";
  position: absolute;
  right: -40px; top: -60px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: rgba(255,255,255,0.10);
}
.member-card::before {
  content: "";
  position: absolute;
  left: -30px; bottom: -50px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.member-card .row-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  position: relative; z-index: 1;
}
.member-card .tier-badge {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
  backdrop-filter: blur(4px);
}
.member-card .name { font-size: 19px; font-weight: 700; margin-top: 14px; position: relative; z-index: 1; }
.member-card .sub { font-size: 13px; opacity: .85; margin-top: 2px; position: relative; z-index: 1; }
.member-card .points-row {
  margin-top: 20px;
  display: flex; align-items: baseline; gap: 8px;
  position: relative; z-index: 1;
}
.member-card .points-num { font-size: 34px; font-weight: 800; }
.member-card .points-label { font-size: 13px; opacity: .85; }
.member-card .progress-wrap { margin-top: 16px; position: relative; z-index: 1; }
.member-card .progress-track {
  height: 8px; border-radius: 999px; background: rgba(255,255,255,0.25); overflow: hidden;
}
.member-card .progress-fill {
  height: 100%; border-radius: 999px; background: white;
}
.member-card .progress-caption { font-size: 12px; opacity: .85; margin-top: 8px; }

/* ---- generic card / section ---- */
.section { padding: 0 20px 18px; }
.section-title {
  font-size: 15px; font-weight: 700; color: var(--text);
  margin: 4px 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.stat-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-tile .stat-value { font-size: 22px; font-weight: 800; color: var(--primary-dark); }
.stat-tile .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-tile .stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.reward-item, .history-item, .coupon-item, .list-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.reward-item:last-child, .history-item:last-child, .coupon-item:last-child, .list-row:last-child { border-bottom: none; }
.item-title { font-weight: 600; font-size: 14px; }
.item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pill {
  font-size: 12px; font-weight: 700;
  padding: 5px 12px; border-radius: 999px;
  background: var(--primary-light); color: var(--primary-dark);
  white-space: nowrap;
}
.pill.muted { background: #f1f3f1; color: var(--text-muted); }
.pill.danger { background: #fdeceb; color: var(--danger); }
.pill.warn { background: #fbf1de; color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  padding: 12px 18px;
  transition: transform .06s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  box-shadow: var(--shadow-md);
}
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-outline {
  background: white; color: var(--primary-dark);
  border: 1.5px solid var(--primary);
}
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 12.5px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fbfffc;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: white;
}

.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); font-size: 13.5px; }
.empty-state .emoji { font-size: 30px; margin-bottom: 8px; }

.alert {
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px;
}
.alert-error { background: #fdeceb; color: #b5342d; border: 1px solid #f6c9c6; }
.alert-success { background: var(--primary-light); color: var(--primary-dark); border: 1px solid var(--border); }

/* ---- bottom nav (mobile) ---- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 480px; margin: 0 auto;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 20px rgba(31,122,52,0.08);
}
.bottom-nav a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0;
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}
.bottom-nav a.active { color: var(--primary-dark); background: var(--primary-light); }
.bottom-nav .nav-icon { font-size: 19px; }

/* ---- auth pages ---- */
.auth-wrap {
  max-width: 420px; margin: 0 auto;
  min-height: 100vh;
  display: flex; flex-direction: column; justify-content: center;
  padding: 32px 24px;
}
.auth-hero { text-align: center; margin-bottom: 26px; }
.auth-hero .logo-big {
  width: 64px; height: 64px; margin: 0 auto 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--accent) 130%);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: white;
  box-shadow: var(--shadow-lg);
}
.auth-hero h1 { font-size: 20px; margin: 0 0 4px; color: var(--text); }
.auth-hero p { font-size: 13px; color: var(--text-muted); margin: 0; }
.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  padding: 24px 22px;
}
.auth-switch { text-align: center; margin-top: 16px; font-size: 13.5px; color: var(--text-muted); }
.auth-switch b { color: var(--primary-dark); cursor: pointer; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; background: var(--primary-light); padding: 4px; border-radius: 999px; }
.auth-tabs button {
  flex: 1; border: none; background: transparent; padding: 9px 0; border-radius: 999px;
  font-weight: 700; font-size: 13.5px; color: var(--text-muted); cursor: pointer;
}
.auth-tabs button.active { background: white; color: var(--primary-dark); box-shadow: var(--shadow-sm); }

/* ---- admin layout ---- */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.admin-sidebar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; margin-bottom: 26px; padding: 0 6px;}
.admin-sidebar .logo-dot { width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,0.18); display:flex; align-items:center; justify-content:center; font-size:18px; }
.admin-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; color: rgba(255,255,255,0.85);
  margin-bottom: 4px;
}
.admin-nav a.active, .admin-nav a:hover { background: rgba(255,255,255,0.16); color: white; }
.admin-main { flex: 1; padding: 26px 30px 60px; max-width: 1180px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px;}
.admin-header h1 { font-size: 21px; margin: 0; }
.admin-header .desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 700; font-size: 12px;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
table.data-table td { padding: 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data-table tr:last-child td { border-bottom: none; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18,41,26,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-width: 420px; width: 100%; padding: 22px; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; font-size: 17px; }

.tabs-row { display: flex; gap: 8px; margin-bottom: 18px; overflow-x: auto; }
.tabs-row button {
  border: 1.5px solid var(--border); background: white; color: var(--text-muted);
  padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.tabs-row button.active { background: var(--primary); border-color: var(--primary); color: white; }

.loading { text-align: center; padding: 40px; color: var(--text-muted); font-size: 13.5px; }

.admin-mobile-nav { display: none; }

@media (max-width: 860px) {
  .admin-sidebar { display: none; }
  .admin-main { padding: 16px 16px 90px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .admin-mobile-nav {
    display: flex; gap: 8px; overflow-x: auto; margin-bottom: 18px; padding-bottom: 4px;
  }
  .admin-mobile-nav button {
    border: 1.5px solid var(--border); background: white; color: var(--text-muted);
    padding: 9px 14px; border-radius: 999px; font-weight: 700; font-size: 12.5px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
  }
  .admin-mobile-nav button.active { background: var(--primary); border-color: var(--primary); color: white; }
}
@media (max-width: 480px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
}
