:root{
  --app-mobile-max: 767px;
  --app-tablet-min: 768px;
  --app-desktop-min: 1200px;

  --app-space-1: 4px;
  --app-space-2: 8px;
  --app-space-3: 12px;
  --app-space-4: 16px;
  --app-space-5: 20px;
  --app-space-6: 24px;
  --app-space-7: 32px;

  --app-container: 1180px;
  --app-container-narrow: 1100px;
  --app-gutter: 16px;
}

html, body{
  width:100%;
  max-width:100%;
  min-width:0;
  overflow-x:hidden;
}

body{
  min-height:100vh;
  margin:0;
  padding-top:calc(env(safe-area-inset-top) + 6px) !important;
  padding-bottom:calc(env(safe-area-inset-bottom) + 10px) !important;
  padding-left:0 !important;
  padding-right:0 !important;
  overflow-x:hidden;
}

.app-page{
  min-height:100vh;
  width:100%;
  padding-top:calc(env(safe-area-inset-top) + 6px);
  padding-bottom:calc(env(safe-area-inset-bottom) + 10px);
  padding-left:0;
  padding-right:0;
  background:linear-gradient(180deg,#edf3f8 0%,#f7fafc 100%);
}

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

img,
.logo,
.admin-logo{
  max-width:100%;
  height:auto;
}

h1,
h2,
h3,
p{
  max-width:100%;
  overflow-wrap:anywhere;
}

button,
.btn,
.admin-btn{
  max-width:100%;
}

.app-shell,
.page-shell,
.app-container,
body > .page,
body > .admin-page,
body > .admin-shell,
body > .main-content,
body > .app-shell,
body > .page-shell{
  width:100%;
  max-width:var(--app-container);
  margin:0 auto;
  padding-left:var(--app-gutter);
  padding-right:var(--app-gutter);
  padding-top:0;
  padding-bottom:0;
}

.app-shell.narrow,
.page-shell.narrow,
.app-container.narrow{
  max-width:var(--app-container-narrow);
}

.app-shell.flush,
.page-shell.flush,
.app-container.flush{
  max-width:none;
  padding-left:0;
  padding-right:0;
}

.page-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:var(--app-space-3);
  flex-wrap:wrap;
  min-width:0;
}

.logo-title-row,
.brand-wrap,
.brand-row{
  display:flex;
  align-items:center;
  gap:var(--app-space-3);
  min-width:0;
  flex:1 1 auto;
}

.brand-text,
.brand{
  min-width:0;
  display:flex;
  flex-direction:column;
  justify-content:center;
}

.page-title{
  margin:0;
  font-size:clamp(24px, 3vw, 36px);
  line-height:1.08;
  font-weight:900;
  overflow-wrap:anywhere;
  max-width:100%;
}

.page-subtitle{
  margin:4px 0 0 0;
  color:#64748b;
  font-size:14px;
  line-height:1.45;
  overflow-wrap:anywhere;
  max-width:100%;
}

.button-stack{
  display:flex;
  flex-direction:column;
  gap:var(--app-space-3);
  min-width:0;
}

.action-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  min-width:0;
  width:100%;
}

.action-list > *{
  width:100%;
  max-width:500px;
}

.action-buttons{
  display:flex;
  flex-direction:column;
  gap:10px;
  min-width:0;
}

.button-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(160px,1fr));
  gap:var(--app-space-3);
  min-width:0;
}

.button-grid > *,
.button-stack > *{
  min-width:0;
}

.status-message{
  border:1px solid transparent;
  border-radius:16px;
  padding:12px 14px;
  font-size:14px;
  line-height:1.5;
}

.page-card{
  background:#fff;
  border:1px solid rgba(148,163,184,.25);
  border-radius:16px;
  box-shadow:0 10px 20px rgba(15,23,42,.05);
  overflow:hidden;
  min-width:0;
}

.stack{
  display:flex;
  flex-direction:column;
  gap:var(--app-space-3);
  min-width:0;
}

.stack.tight{
  gap:var(--app-space-2);
}

.stack.loose{
  gap:var(--app-space-4);
}

.row-layout,
.responsive-row{
  display:flex;
  align-items:center;
  gap:var(--app-space-3);
  min-width:0;
  flex-wrap:wrap;
}

.row-layout.nowrap{
  flex-wrap:nowrap;
}

.row-layout.center{
  justify-content:center;
}

.row-layout.space-between{
  justify-content:space-between;
}

.row-layout.end{
  justify-content:flex-end;
}

.row-layout.stretch{
  align-items:stretch;
}

.row-layout > *,
.responsive-row > *{
  min-width:0;
}

.grid-1{
  display:grid;
  grid-template-columns:1fr;
  gap:var(--app-space-3);
}

.grid-2{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:var(--app-space-3);
}

.grid-auto{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:var(--app-space-3);
}

.content-width{
  width:100%;
  max-width:var(--app-container);
  margin:0 auto;
}

.content-width.narrow{
  max-width:var(--app-container-narrow);
}

.toolbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:var(--app-space-3);
  flex-wrap:wrap;
  min-width:0;
}

.toolbar .toolbar-actions{
  display:flex;
  align-items:center;
  gap:var(--app-space-2);
  flex-wrap:wrap;
  min-width:0;
}

.section-grid{
  display:grid;
  grid-template-columns:1fr;
  gap:var(--app-space-4);
}

.section-card{
  width:100%;
  min-width:0;
}

.section-card + .section-card{
  margin-top:var(--app-space-4);
}

.row-grid{
  display:grid;
  grid-template-columns:1fr;
  gap:var(--app-space-3);
  min-width:0;
}

.row-grid > *{
  min-width:0;
}

.mobile-hide{
  display:none !important;
}

.mobile-show{
  display:block !important;
}

@media (min-width: 768px){
  .app-shell,
  .page-shell,
  .app-container{
    padding-left:20px;
    padding-right:20px;
  }

  .grid-2{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .section-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .mobile-hide{
    display:initial !important;
  }

  .tablet-hide{
    display:none !important;
  }
}

@media (min-width: 1200px){
  .app-shell,
  .page-shell,
  .app-container{
    padding-left:24px;
    padding-right:24px;
  }

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

  .row-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .desktop-hide{
    display:none !important;
  }
}

@media (max-width: 767px){
  .admin-page,
  .admin-shell,
  .admin-container,
  .app-shell,
  .page-shell,
  .app-container,
  .page{
    width:100%;
    max-width:480px;
    min-width:0;
    margin:0 auto;
    padding-left:16px;
    padding-right:16px;
    padding-top:calc(env(safe-area-inset-top) + 6px);
    padding-bottom:calc(env(safe-area-inset-bottom) + 10px);
    overflow-x:hidden;
  }

  .page-header{
    padding-top:calc(env(safe-area-inset-top) + 4px);
    gap:8px;
  }

  .logo-title-row{
    gap:8px;
  }

  .page-title{
    font-size:26px;
  }

  .page-subtitle{
    font-size:13px;
    line-height:1.35;
  }

  .logo-title-row img,
  .logo-title-row .brand-logo,
  .logo-title-row .admin-logo,
  .page-header img.brand-logo,
  .page-header img.admin-logo{
    width:64px;
    height:64px;
  }

  .button-stack,
  .button-grid{
    width:100%;
    max-width:100%;
  }

  .button-grid{
    grid-template-columns:1fr;
    gap:10px;
  }

  .admin-actions,
  .admin-button-stack,
  .btn-group,
  .button-group,
  .action-buttons{
    width:100%;
    max-width:100%;
    flex-wrap:wrap;
  }

  .admin-actions .btn,
  .admin-button-stack .btn,
  .btn-group .btn,
  .button-group .btn,
  .action-buttons .btn{
    width:100%;
    max-width:100%;
  }

  .status-message{
    padding:10px 12px;
    font-size:13px;
  }
}

@supports not (padding-top: env(safe-area-inset-top)){
  .admin-page,
  .admin-shell,
  .admin-container,
  .app-shell,
  .page-shell,
  .app-container,
  .page{
    padding-top:16px;
    padding-bottom:16px;
  }
}
