/* ============================================================
   APERSON Design System — aperson-ui.css
   Mobile-first | 375px base
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Urbanist:wght@500;600;700;800&display=swap');

/* --- Design Tokens --- */
:root {
  /* Colors */
  --color-primary:   #0A2D44;
  --color-bg:        #F8FDFF;
  --color-surface:   #F0EFEB;
  --color-accent:    #F07900;
  --color-muted:     #5B7A8A;
  --color-text:      #1A1A1A;
  --color-text-secondary: #6B7280;
  --color-border:    #E2E2DD;
  --color-success:   #22C55E;
  --color-warning:   #F59E0B;
  --color-danger:    #EF4444;
  --color-white:     #FFFFFF;

  /* Typography */
  --font-heading: 'Urbanist', sans-serif;
  --font-body:    'Inter', sans-serif;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(10,45,68,0.06);
  --shadow-md:  0 4px 12px rgba(10,45,68,0.08);
  --shadow-lg:  0 8px 24px rgba(10,45,68,0.12);

  /* Layout */
  --header-height: 64px;
  --tab-bar-height: 56px;
  --content-max-width: 1200px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-primary);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

a {
  color: var(--color-accent);
  text-decoration: none;
}

/* --- App Layout --- */
.ap-app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* --- Header --- */
.ap-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--color-primary);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  box-shadow: var(--shadow-md);
}

.ap-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.ap-header__logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.875rem;
  color: var(--color-white);
}

.ap-header__title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-white);
}

.ap-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* --- Content Area --- */
.ap-content {
  flex: 1;
  margin-top: var(--header-height);
  margin-bottom: var(--tab-bar-height);
  padding: var(--space-md);
  max-width: var(--content-max-width);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* --- Bottom Tab Bar --- */
.ap-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--tab-bar-height);
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0;
  box-shadow: 0 -2px 8px rgba(10,45,68,0.06);
}

.ap-tab-bar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  height: 100%;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-muted);
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.ap-tab-bar__item.active {
  color: var(--color-accent);
}

.ap-tab-bar__item svg {
  width: 22px;
  height: 22px;
}

/* --- Card --- */
.ap-card {
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  transition: box-shadow 0.2s;
}

.ap-card:hover {
  box-shadow: var(--shadow-md);
}

.ap-card--surface {
  background: var(--color-surface);
  border-color: transparent;
}

.ap-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

.ap-card__title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-primary);
}

.ap-card__value {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.75rem;
  color: var(--color-primary);
  margin-top: var(--space-xs);
}

.ap-card__subtitle {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: var(--space-xs);
}

/* --- KPI Card Grid --- */
.ap-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

/* --- Button --- */
.ap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: 44px;
  padding: 0 var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.ap-btn--primary {
  background: var(--color-accent);
  color: var(--color-white);
}

.ap-btn--primary:hover {
  background: #D96C00;
}

.ap-btn--secondary {
  background: var(--color-surface);
  color: var(--color-primary);
}

.ap-btn--ghost {
  background: transparent;
  color: var(--color-primary);
}

.ap-btn--sm {
  height: 36px;
  padding: 0 var(--space-md);
  font-size: 0.8125rem;
}

.ap-btn--full {
  width: 100%;
}

/* --- Input --- */
.ap-input {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--color-text);
  background: var(--color-white);
  transition: border-color 0.2s;
  outline: none;
}

.ap-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(240,121,0,0.12);
}

.ap-input::placeholder {
  color: var(--color-muted);
}

.ap-input-group {
  margin-bottom: var(--space-md);
}

.ap-input-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-xs);
}

/* --- Select --- */
.ap-select {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--color-text);
  background: var(--color-white);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%235B7A8A' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  outline: none;
}

.ap-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(240,121,0,0.12);
}

/* --- Badge --- */
.ap-badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 var(--space-sm);
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ap-badge--accent  { background: rgba(240,121,0,0.12);  color: var(--color-accent);  }
.ap-badge--success { background: rgba(34,197,94,0.12);  color: var(--color-success); }
.ap-badge--warning { background: rgba(245,158,11,0.12); color: var(--color-warning); }
.ap-badge--danger  { background: rgba(239,68,68,0.12);  color: var(--color-danger);  }
.ap-badge--muted   { background: var(--color-surface);  color: var(--color-muted);   }

/* --- Table --- */
.ap-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.ap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.ap-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  font-weight: 600;
  color: var(--color-primary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.ap-table td {
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--color-border);
  white-space: nowrap;
}

.ap-table tr:hover td {
  background: rgba(240,121,0,0.03);
}

/* --- Modal --- */
.ap-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10,45,68,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.ap-modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.ap-modal {
  background: var(--color-white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80dvh;
  overflow-y: auto;
  padding: var(--space-lg);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.ap-modal-overlay.active .ap-modal {
  transform: translateY(0);
}

.ap-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.ap-modal__title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-primary);
}

.ap-modal__close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-surface);
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  font-size: 1.25rem;
}

/* --- Toast --- */
.ap-toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--space-md));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: calc(100% - var(--space-lg) * 2);
  max-width: 400px;
  pointer-events: none;
}

.ap-toast {
  background: var(--color-primary);
  color: var(--color-white);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: ap-toast-in 0.3s ease;
}

.ap-toast--success { background: var(--color-success); }
.ap-toast--warning { background: var(--color-warning); color: var(--color-text); }
.ap-toast--danger  { background: var(--color-danger);  }

@keyframes ap-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Loader --- */
.ap-loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(248,253,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.ap-loader-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.ap-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: ap-spin 0.8s linear infinite;
}

@keyframes ap-spin {
  to { transform: rotate(360deg); }
}

/* --- Empty State --- */
.ap-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
}

.ap-empty__icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-md);
  color: var(--color-muted);
  opacity: 0.4;
}

.ap-empty__title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--color-primary);
  margin-bottom: var(--space-xs);
}

.ap-empty__desc {
  font-size: 0.875rem;
  color: var(--color-muted);
  max-width: 280px;
  margin-bottom: var(--space-lg);
}

/* --- Brand Switcher --- */
.ap-brand-switcher {
  position: relative;
}

.ap-brand-switcher__btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  height: 36px;
  padding: 0 var(--space-sm);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  color: var(--color-white);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
}

.ap-brand-switcher__dropdown {
  position: absolute;
  top: calc(100% + var(--space-xs));
  right: 0;
  min-width: 200px;
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  overflow: hidden;
  display: none;
  z-index: 110;
}

.ap-brand-switcher__dropdown.open {
  display: block;
}

.ap-brand-switcher__item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--color-text);
  text-align: left;
}

.ap-brand-switcher__item:hover {
  background: var(--color-surface);
}

.ap-brand-switcher__item.active {
  color: var(--color-accent);
  font-weight: 600;
}

/* --- Kanban --- */
.ap-kanban {
  display: flex;
  gap: var(--space-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-md);
}

.ap-kanban__col {
  min-width: 260px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.ap-kanban__col-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ap-kanban__count {
  font-size: 0.6875rem;
  color: var(--color-muted);
  font-weight: 500;
}

/* --- Pipeline --- */
.ap-pipeline {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-md);
}

.ap-pipeline__stage {
  flex: 1;
  min-width: 180px;
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  text-align: center;
}

.ap-pipeline__stage-name {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: var(--space-xs);
}

.ap-pipeline__stage-value {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--color-primary);
}

/* --- Search Bar --- */
.ap-search {
  position: relative;
  margin-bottom: var(--space-md);
}

.ap-search__input {
  width: 100%;
  height: 44px;
  padding: 0 var(--space-md) 0 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.875rem;
  background: var(--color-white);
  outline: none;
}

.ap-search__input:focus {
  border-color: var(--color-accent);
}

.ap-search__icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--color-muted);
}

/* --- Section Header --- */
.ap-section {
  margin-bottom: var(--space-lg);
}

.ap-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.ap-section__title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-primary);
}

/* --- Tabs (horizontal) --- */
.ap-tabs {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
}

.ap-tabs__item {
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
}

.ap-tabs__item.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* --- Calendar Grid --- */
.ap-cal-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  text-align: center;
  margin-bottom: var(--space-xs);
}

.ap-cal-header span {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-muted);
  padding: var(--space-xs) 0;
}

.ap-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.ap-cal-cell {
  background: var(--color-white);
  min-height: 48px;
  padding: var(--space-xs);
  font-size: 0.75rem;
}

.ap-cal-cell--today {
  background: rgba(240,121,0,0.06);
}

/* --- Page title --- */
.ap-page-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--color-primary);
  margin-bottom: var(--space-md);
}

/* --- Login Page --- */
.ap-login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: var(--color-primary);
}

.ap-login__card {
  width: 100%;
  max-width: 400px;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-lg);
}

.ap-login__logo {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.ap-login__logo h1 {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--color-primary);
}

.ap-login__logo p {
  font-size: 0.8125rem;
  color: var(--color-muted);
  margin-top: var(--space-xs);
}

/* --- Nav (side menu for larger screens) --- */
.ap-nav {
  display: none;
}

/* --- Responsive --- */
@media (min-width: 768px) {
  .ap-kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .ap-modal {
    border-radius: var(--radius-lg);
    max-width: 560px;
    margin-bottom: auto;
  }

  .ap-modal-overlay {
    align-items: center;
  }

  .ap-content {
    padding: var(--space-lg);
  }
}

@media (min-width: 1024px) {
  .ap-tab-bar {
    display: none;
  }

  .ap-nav {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: 240px;
    background: var(--color-white);
    border-right: 1px solid var(--color-border);
    padding: var(--space-md);
    overflow-y: auto;
    z-index: 90;
  }

  .ap-nav__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
  }

  .ap-nav__item:hover {
    background: var(--color-surface);
  }

  .ap-nav__item.active {
    background: rgba(240,121,0,0.08);
    color: var(--color-accent);
    font-weight: 600;
  }

  .ap-content {
    margin-left: 240px;
    margin-bottom: 0;
  }
}

/* --- Utility --- */
.ap-flex { display: flex; }
.ap-gap-sm { gap: var(--space-sm); }
.ap-gap-md { gap: var(--space-md); }
.ap-mt-sm { margin-top: var(--space-sm); }
.ap-mt-md { margin-top: var(--space-md); }
.ap-mt-lg { margin-top: var(--space-lg); }
.ap-mb-md { margin-bottom: var(--space-md); }
.ap-text-muted { color: var(--color-muted); }
.ap-text-sm { font-size: 0.8125rem; }
.ap-text-center { text-align: center; }
.ap-hidden { display: none !important; }
