/* ============================================================
   Prima Global Calculator — Layout
   Based on Prima Global Platform Design Language
   ============================================================ */

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: rgba(255, 75, 31, 0.2);
  color: inherit;
}

::placeholder {
  color: var(--color-text-hint);
  opacity: 0.6;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background: var(--color-bg-primary);
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

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

/* --- App Header (Prima Global branding) --- */
.app-header {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
  background: var(--color-bg-primary);
  border-bottom: 1px solid var(--color-border);
  min-height: 52px;
  flex-shrink: 0;
}

.app-header__logo {
  height: 28px;
  width: auto;
  display: block;
  max-width: calc(100vw - 32px);
  object-fit: contain;
}

/* --- Page Header --- */
.page-header {
  text-align: center;
  padding: var(--space-4) var(--space-4) var(--space-2);
}

.page-header__title {
  font-size: var(--font-size-h1);
  font-weight: var(--font-weight-extrabold);
  color: var(--color-text-primary);
  margin: 0;
  line-height: var(--line-height-tight);
}

.page-header__subtitle {
  font-size: var(--font-size-caption);
  color: var(--color-text-secondary);
  margin: var(--space-1) 0 0;
}

/* --- Tab Panels --- */
.tab-panel {
  display: none;
  padding: 0 var(--space-4) var(--space-4);
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

.tab-panel--active {
  display: block;
}

/* --- Tab Bar (Prima: orange active state) --- */
/* --- Standalone Action Button (outside Telegram) --- */
.standalone-action {
  position: fixed;
  bottom: 60px;
  left: 0;
  right: 0;
  padding: 8px 16px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 99;
  background: linear-gradient(to top, var(--color-bg-primary) 60%, transparent);
  pointer-events: none;
}

.standalone-action__btn {
  display: block;
  width: 100%;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-family);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: var(--color-accent, #FF4B1F);
  border: none;
  border-radius: var(--radius-sm, 10px);
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.standalone-action__btn:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.standalone-action__btn--loading {
  opacity: 0.7;
  pointer-events: none;
  animation: btn-pulse 1.2s ease-in-out infinite;
}

@keyframes btn-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0.5; }
}

.tab-bar {
  display: flex;
  flex-wrap: nowrap;
  position: fixed;
  bottom: 0;
  /* position context for .tab-bar__copyright */
  left: 0;
  right: 0;
  background: var(--color-bg-section);
  border-top: 1px solid var(--color-border);
  padding: 0 0 var(--space-2);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-tab-bar);
}

.tab-bar__copyright {
  position: absolute;
  top: -14px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  color: var(--color-text-hint);
  opacity: 0.5;
  pointer-events: none;
}

.tab-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-1) 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-small);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font-family);
  line-height: var(--line-height-tight);
  touch-action: manipulation;
}

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

.tab-bar__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  line-height: 1;
}

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

.tab-bar__label {
  font-size: 11px;
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.02em;
}

/* --- Form Section (Prima: border instead of shadow) --- */
.form-section {
  background: var(--color-bg-section);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}

/* --- Results Section --- */
.results-section {
  display: none;
  opacity: 0;
  transform: translateY(12px);
}

.results-section--visible {
  display: block;
  animation: fadeSlideUp 350ms ease-out forwards;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- App Footer (minimal copyright line) --- */
.app-footer {
  text-align: center;
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  font-size: var(--font-size-footer);
  color: var(--color-text-hint);
}

.app-footer__copyright {
  font-size: var(--font-size-small);
  color: var(--color-text-hint);
  opacity: 0.6;
}

/* --- Responsive: 320–414px base (mobile first) --- */
@media (min-width: 375px) {
  .kpi-grid {
    gap: var(--space-3);
  }
}

@media (min-width: 414px) {
  .page-header {
    padding-top: var(--space-5);
  }

  .form-section {
    padding: var(--space-5);
  }

  .app-header__logo {
    height: 32px;
  }
}

/* Tablet+ */
@media (min-width: 768px) {
  .tab-panel {
    max-width: 640px;
    margin: 0 auto;
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }

  .app-header {
    max-width: 640px;
    margin: 0 auto;
  }

  .app-footer {
    max-width: 640px;
    margin: 0 auto;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .data-table {
    min-width: unset;
  }

  .tab-bar {
    max-width: 640px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }

  .standalone-action {
    max-width: 640px;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* Desktop */
@media (min-width: 1024px) {
  /* Reorder: move tab bar above main content */
  #app-main {
    order: 1;
  }

  /* Wider content area */
  .tab-panel {
    max-width: 960px;
    padding-left: var(--space-8);
    padding-right: var(--space-8);
    padding-bottom: var(--space-8);
  }

  .app-header {
    max-width: 960px;
    padding: var(--space-4) var(--space-8);
  }

  .app-footer {
    max-width: 960px;
  }

  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Page header: bigger on desktop */
  .page-header {
    padding-top: var(--space-8);
    padding-bottom: var(--space-2);
  }

  .page-header__title {
    font-size: 28px;
  }

  .page-header__subtitle {
    font-size: var(--font-size-body);
  }

  /* Form sections: more padding */
  .form-section {
    padding: var(--space-6);
  }

  /* Tab bar → top horizontal navigation */
  .tab-bar {
    position: sticky;
    top: 0;
    bottom: auto;
    left: 0;
    right: 0;
    max-width: none;
    transform: none;
    border-top: none;
    border-bottom: 1px solid var(--color-border);
    border-radius: 0;
    padding: 0;
    justify-content: center;
    gap: 0;
    background: var(--color-bg-primary);
  }

  .tab-bar__copyright {
    display: none;
  }

  .tab-bar__item {
    flex: none;
    flex-direction: row;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--transition-fast), border-color var(--transition-fast);
  }

  .tab-bar__item:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-secondary);
  }

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

  .tab-bar__item--active:hover {
    background: transparent;
  }

  .tab-bar__label {
    font-size: var(--font-size-caption);
  }

  .tab-bar__icon svg {
    width: 18px;
    height: 18px;
  }

  /* Standalone action: adjust for top nav */
  .standalone-action {
    bottom: var(--space-4);
    max-width: 960px;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* Ultra-wide desktop */
@media (min-width: 1440px) {
  .tab-panel {
    max-width: 1080px;
  }

  .app-header {
    max-width: 1080px;
  }

  .app-footer {
    max-width: 1080px;
  }

  .standalone-action {
    max-width: 1080px;
  }
}

/* Small screens — compact tab bar and prevent text clipping */
@media (max-width: 374px) {
  .tab-bar__label {
    font-size: 9px;
    letter-spacing: 0;
  }
  .tab-bar__icon svg {
    width: 18px;
    height: 18px;
  }
  .tab-bar__item {
    padding: 2px 0;
    min-width: 0;
  }
}

@media (max-width: 280px) {
  .tab-bar__label {
    display: none;
  }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
