/* ==========================================================================
   USMS App CSS
   File: public/assets/css/app.css
   ========================================================================== */

@import url("./base.css");
@import url("./layout.css");

/* ==========================================================================
   App Global
   ========================================================================== */

html,
body {
  background: var(--usms-bg);
}

body {
  overscroll-behavior: none;
}

#usmsApp {
  opacity: 1;
  transition: opacity 0.2s ease;
}

#usmsApp.hidden {
  opacity: 0;
  pointer-events: none;
}

.app-bg-pattern {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.08;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 18px 18px, rgba(233, 237, 239, 0.24) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  z-index: var(--usms-z-modal);
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(18px);
}

.modal-card {
  width: min(560px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--usms-border);
  border-radius: var(--usms-radius-xl);
  background: rgba(32, 44, 51, 0.96);
  box-shadow: var(--usms-shadow-lg);
  backdrop-filter: blur(22px);
}

html[data-theme="light"] .modal-card {
  background: rgba(255, 255, 255, 0.96);
}

.modal-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--usms-border);
  background: rgba(134, 150, 160, 0.06);
}

.modal-header h3 {
  color: var(--usms-text);
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.modal-body {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

.modal-footer {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--usms-border);
  background: rgba(134, 150, 160, 0.04);
}

.modal-list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.modal-list-item {
  min-height: 58px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 9px;
  border: 0;
  border-radius: var(--usms-radius-md);
  color: var(--usms-text);
  background: transparent;
  text-align: left;
  transition: background var(--usms-transition-fast);
}

.modal-list-item:hover {
  background: rgba(134, 150, 160, 0.1);
}

.modal-list-item.active {
  background: var(--usms-primary-soft);
}

.modal-list-avatar {
  width: 44px;
  height: 44px;
  border-radius: 999px;
}

.modal-list-content {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.modal-list-content strong,
.modal-list-content span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.modal-list-content strong {
  color: var(--usms-text);
  font-size: 14px;
}

.modal-list-content span {
  color: var(--usms-muted);
  font-size: 12px;
}

.modal-list-meta {
  color: var(--usms-muted);
  font-size: 12px;
}

.modal-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--usms-muted);
  text-align: center;
}

/* ==========================================================================
   Story Viewer
   ========================================================================== */

.story-viewer {
  position: fixed;
  z-index: calc(var(--usms-z-modal) + 20);
  inset: 0;
  display: grid;
  grid-template-rows: 86px minmax(0, 1fr);
  background: #000;
}

.story-viewer-header {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: 4px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 18px 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.68), transparent);
}

.story-progress {
  display: flex;
  gap: 4px;
}

.story-progress span {
  height: 4px;
  flex: 1;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
}

.story-progress span b {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #fff;
}

.story-progress span.active b {
  animation: usmsStoryProgress 5s linear forwards;
}

.story-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #fff;
}

.story-user img {
  width: 42px;
  height: 42px;
  border-radius: 999px;
}

.story-user div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.story-user strong,
.story-user span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.story-user strong {
  font-size: 14px;
}

.story-user span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
}

.story-viewer-header .icon-btn {
  position: absolute;
  right: 14px;
  bottom: 8px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.story-viewer-content {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px;
}

.story-viewer-content img,
.story-viewer-content video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  object-fit: contain;
}

.story-text-content {
  width: min(520px, 92vw);
  min-height: 420px;
  display: grid;
  place-items: center;
  padding: 34px;
  border-radius: 30px;
  color: #fff;
  text-align: center;
  font-size: clamp(24px, 6vw, 46px);
  line-height: 1.18;
  font-weight: 900;
  letter-spacing: -0.045em;
  background:
    radial-gradient(circle at top left, rgba(0, 168, 132, 0.42), transparent 42%),
    linear-gradient(135deg, #111b21, #005c4b);
}

.story-nav {
  position: absolute;
  z-index: 3;
  top: 50%;
  width: 54px;
  height: 74px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 42px;
  line-height: 1;
  backdrop-filter: blur(12px);
}

.story-nav:hover {
  background: rgba(255, 255, 255, 0.16);
}

.story-nav.prev {
  left: 18px;
}

.story-nav.next {
  right: 18px;
}

/* ==========================================================================
   Profile / Settings panels
   ========================================================================== */

.profile-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
}

.profile-card-avatar {
  position: relative;
  width: 126px;
  height: 126px;
  border-radius: 999px;
}

.profile-card-avatar img {
  width: 126px;
  height: 126px;
  border-radius: 999px;
}

.profile-card-avatar button {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2px solid var(--usms-panel);
  border-radius: 999px;
  color: #031d17;
  background: var(--usms-primary);
}

.profile-card h2 {
  color: var(--usms-text);
  font-size: 24px;
  letter-spacing: -0.04em;
}

.profile-card p {
  color: var(--usms-muted);
  font-size: 13px;
}

.settings-list {
  display: grid;
  gap: 8px;
}

.settings-row {
  min-height: 58px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 0;
  border-radius: var(--usms-radius-md);
  color: var(--usms-text);
  background: transparent;
  text-align: left;
}

.settings-row:hover {
  background: rgba(134, 150, 160, 0.09);
}

.settings-row-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--usms-primary-2);
  background: var(--usms-primary-soft);
}

.settings-row-text {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.settings-row-text strong,
.settings-row-text span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.settings-row-text strong {
  color: var(--usms-text);
  font-size: 14px;
}

.settings-row-text span {
  color: var(--usms-muted);
  font-size: 12px;
}

.settings-row-meta {
  color: var(--usms-muted);
  font-size: 13px;
}

/* ==========================================================================
   Toggle / Switch
   ========================================================================== */

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  display: inline-block;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(134, 150, 160, 0.28);
  transition: background var(--usms-transition-fast);
}

.switch span::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--usms-shadow-sm);
  transition: transform var(--usms-transition-fast);
}

.switch input:checked + span {
  background: var(--usms-primary);
}

.switch input:checked + span::before {
  transform: translateX(20px);
}

/* ==========================================================================
   Context / Selection
   ========================================================================== */

.selection-bar {
  position: fixed;
  z-index: var(--usms-z-panel);
  left: 50%;
  bottom: 18px;
  width: min(620px, calc(100vw - 32px));
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid var(--usms-border);
  border-radius: 999px;
  background: rgba(32, 44, 51, 0.96);
  box-shadow: var(--usms-shadow-lg);
  backdrop-filter: blur(20px);
  transform: translateX(-50%);
}

html[data-theme="light"] .selection-bar {
  background: rgba(255, 255, 255, 0.96);
}

.selection-info {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--usms-text);
  font-size: 14px;
  font-weight: 800;
}

.selection-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

/* ==========================================================================
   Empty / Error states
   ========================================================================== */

.error-state,
.success-state,
.warning-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.state-card {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 12px;
}

.state-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  font-size: 28px;
  font-weight: 900;
}

.error-state .state-icon {
  color: var(--usms-danger);
  background: var(--usms-danger-soft);
}

.success-state .state-icon {
  color: var(--usms-success);
  background: var(--usms-success-soft);
}

.warning-state .state-icon {
  color: var(--usms-warning);
  background: var(--usms-warning-soft);
}

.state-card h2,
.state-card h3 {
  color: var(--usms-text);
  font-size: 22px;
  letter-spacing: -0.035em;
}

.state-card p {
  color: var(--usms-muted);
  font-size: 14px;
  line-height: 1.55;
}

/* ==========================================================================
   Progress / Upload
   ========================================================================== */

.upload-list {
  display: grid;
  gap: 10px;
}

.upload-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--usms-border);
  border-radius: var(--usms-radius-md);
  background: rgba(134, 150, 160, 0.06);
}

.upload-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--usms-info);
  background: var(--usms-info-soft);
}

.upload-content {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.upload-content strong {
  overflow: hidden;
  color: var(--usms-text);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.upload-content span {
  color: var(--usms-muted);
  font-size: 12px;
}

.progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(134, 150, 160, 0.18);
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--usms-primary);
  transition: width 0.2s ease;
}

/* ==========================================================================
   Notification permission
   ========================================================================== */

.permission-banner {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(83, 189, 235, 0.25);
  border-radius: var(--usms-radius-md);
  background: var(--usms-info-soft);
}

.permission-banner-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--usms-info);
  background: rgba(83, 189, 235, 0.14);
}

.permission-banner-text {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.permission-banner-text strong {
  color: var(--usms-text);
  font-size: 14px;
}

.permission-banner-text p {
  color: var(--usms-muted);
  font-size: 12px;
  line-height: 1.35;
}

/* ==========================================================================
   Browser update / offline banner
   ========================================================================== */

.app-banner {
  position: fixed;
  z-index: calc(var(--usms-z-toast) + 1);
  left: 50%;
  top: 14px;
  width: min(580px, calc(100vw - 28px));
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--usms-border);
  border-radius: var(--usms-radius-md);
  color: var(--usms-text);
  background: rgba(32, 44, 51, 0.96);
  box-shadow: var(--usms-shadow-md);
  backdrop-filter: blur(20px);
  transform: translateX(-50%);
}

html[data-theme="light"] .app-banner {
  background: rgba(255, 255, 255, 0.96);
}

.app-banner.warning {
  border-color: rgba(245, 197, 66, 0.24);
}

.app-banner.danger {
  border-color: rgba(255, 92, 117, 0.24);
}

.app-banner.success {
  border-color: rgba(6, 207, 156, 0.24);
}

.app-banner-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--usms-info);
  background: var(--usms-info-soft);
}

.app-banner.warning .app-banner-icon {
  color: var(--usms-warning);
  background: var(--usms-warning-soft);
}

.app-banner.danger .app-banner-icon {
  color: var(--usms-danger);
  background: var(--usms-danger-soft);
}

.app-banner.success .app-banner-icon {
  color: var(--usms-success);
  background: var(--usms-success-soft);
}

.app-banner-text {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.app-banner-text strong,
.app-banner-text span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.app-banner-text strong {
  color: var(--usms-text);
  font-size: 14px;
}

.app-banner-text span {
  color: var(--usms-muted);
  font-size: 12px;
}

.app-banner button {
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  border-radius: 999px;
  color: #031d17;
  background: var(--usms-primary);
  font-size: 12px;
  font-weight: 900;
}

/* ==========================================================================
   Keyboard shortcuts
   ========================================================================== */

.shortcuts-list {
  display: grid;
  gap: 8px;
}

.shortcut-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 42px;
  padding: 8px 0;
  border-bottom: 1px solid var(--usms-border);
}

.shortcut-row:last-child {
  border-bottom: 0;
}

.shortcut-row span {
  color: var(--usms-muted);
  font-size: 13px;
}

.shortcut-keys {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.shortcut-keys kbd {
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border: 1px solid var(--usms-border);
  border-radius: 8px;
  color: var(--usms-text);
  background: rgba(134, 150, 160, 0.08);
  font: 800 12px var(--usms-font);
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes usmsStoryProgress {
  from {
    width: 0;
  }

  to {
    width: 100%;
  }
}

@keyframes usmsFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes usmsSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes usmsScaleIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.animate-fade-in {
  animation: usmsFadeIn 0.2s ease both;
}

.animate-slide-up {
  animation: usmsSlideUp 0.22s ease both;
}

.animate-scale-in {
  animation: usmsScaleIn 0.2s ease both;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 760px) {
  .modal-backdrop {
    padding: 12px;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100dvh - 24px);
    border-radius: 22px;
  }

  .modal-header {
    min-height: 58px;
    padding: 0 14px;
  }

  .modal-body {
    padding: 14px;
  }

  .modal-footer {
    min-height: 60px;
    padding: 12px 14px;
  }

  .story-viewer {
    height: 100dvh;
    grid-template-rows: 80px minmax(0, 1fr);
  }

  .story-viewer-header {
    padding-left: 12px;
    padding-right: 12px;
  }

  .story-nav {
    width: 44px;
    height: 62px;
    font-size: 34px;
  }

  .story-nav.prev {
    left: 8px;
  }

  .story-nav.next {
    right: 8px;
  }

  .story-text-content {
    min-height: 360px;
    border-radius: 24px;
  }

  .selection-bar {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    transform: none;
    border-radius: 20px;
  }

  .permission-banner {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .permission-banner .primary-btn,
  .permission-banner .secondary-btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .app-banner {
    top: 10px;
    width: calc(100vw - 20px);
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .app-banner button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .upload-item {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .upload-item > button {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 430px) {
  .modal-list-item {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .modal-list-meta {
    grid-column: 1 / -1;
    padding-left: 52px;
  }

  .profile-card-avatar,
  .profile-card-avatar img {
    width: 108px;
    height: 108px;
  }

  .settings-row {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    min-height: 54px;
    padding: 8px;
  }

  .settings-row-icon {
    width: 38px;
    height: 38px;
  }

  .shortcut-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}