:root{
  --app-bg:#eaf1f8;
  --app-surface:#ffffff;
  --app-surface-soft:#f5f9fd;
  --app-border:#d5e0ec;
  --app-border-strong:#bccddd;
  --app-text:#122235;
  --app-muted:#536b84;
  --app-primary:#0f67b6;
  --app-primary-hover:#0c5698;
  --app-primary-soft:#e6f0fb;
  --app-danger:#c6313a;
  --app-danger-soft:#fff4f4;
  --app-success:#167a45;
  --app-success-soft:#e9f7ef;
  --app-warning:#9c651e;
  --radius-xl:16px;
  --radius-lg:12px;
  --radius-md:10px;
  --radius-sm:8px;
  --shadow-soft:0 1px 1px rgba(18,34,53,.04),0 10px 28px rgba(18,34,53,.08);
}

*{box-sizing:border-box}
html,body{
  min-height:100%;
  width:100%;
  max-width:100%;
  overflow-y:auto;
  overflow-x:hidden;
}
body{
  margin:0;
  color:var(--app-text);
  font-family:"Segoe UI Variable Display","Segoe UI","Helvetica Neue",Arial,sans-serif;
  background:linear-gradient(180deg,#eef4fb 0%,#e7eef7 100%);
  overscroll-behavior-y:auto;
}

body.modal-open{
  overflow:hidden;
}

body.app-page{
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}

body.app-page .app-shell{
  display:block;
}

a{text-decoration:none;color:inherit}
button,input,select{font:inherit}
button{cursor:pointer}
button,input,select,.formula-input{
  touch-action:manipulation;
}

.app-shell{
  min-height:100vh;
  width:100%;
  max-width:100%;
  display:grid;
  grid-template-rows:auto auto;
}

.app-topbar{
  position:sticky;
  top:0;
  z-index:40;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:10px 18px;
  background:rgba(246,250,254,.96);
  backdrop-filter:blur(10px);
  border-bottom:1px solid var(--app-border);
}

.app-topbar-left,.app-topbar-right{
  display:flex;
  align-items:center;
  gap:14px;
}

.app-brand-mark{
  width:40px;
  height:40px;
  border-radius:12px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  background:linear-gradient(180deg,#1a75c7,#0f67b6);
  color:#fff;
  font-weight:800;
  letter-spacing:.05em;
}

.app-brand-copy{
  display:flex;
  align-items:baseline;
  gap:14px;
  flex-wrap:wrap;
}

.app-brand-copy strong{
  font-size:30px;
  line-height:1;
  letter-spacing:-.03em;
}

.app-brand-copy span{
  font-size:15px;
  color:#36506b;
  font-weight:600;
}

.app-layout{
  min-height:0;
  min-width:0;
  width:100%;
  max-width:100%;
  display:grid;
  grid-template-columns:260px minmax(0,1fr);
}

.app-layout > *{
  min-width:0;
}

.app-sidebar{
  position:sticky;
  top:72px;
  align-self:start;
  min-width:0;
  max-width:100%;
  height:calc(100vh - 72px);
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding:14px 12px 18px;
  background:#f4f8fc;
  border-right:1px solid var(--app-border);
  display:flex;
  flex-direction:column;
  gap:14px;
}

.app-sidebar-section{
  display:flex;
  flex-direction:column;
  min-width:0;
  gap:8px;
}

.app-sidebar-label{
  padding:0 10px;
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.1em;
  font-weight:700;
  color:var(--app-muted);
}

.erp-sidebar-nav,.app-sidebar-nav{
  display:flex;
  flex-direction:column;
  min-width:0;
  width:100%;
  max-width:100%;
  gap:4px;
}

.erp-nav-link{
  min-height:44px;
  padding:0 14px;
  border-radius:10px;
  display:flex;
  align-items:center;
  border:1px solid transparent;
  color:#30445a;
  font-weight:650;
  transition:.16s ease;
}

.erp-nav-link:hover{
  background:#e9f1f9;
  border-color:#d5e3f1;
}

.erp-nav-link.is-active{
  background:var(--app-primary-soft);
  border-color:#c5d9ee;
  color:var(--app-primary);
  box-shadow:inset 3px 0 0 var(--app-primary);
}

.sidebar-tip{
  padding:14px;
  border:1px solid var(--app-border);
  border-radius:var(--radius-lg);
  background:#fff;
  color:var(--app-muted);
  line-height:1.7;
}

.sidebar-tip strong{
  display:block;
  margin-bottom:6px;
  color:var(--app-text);
}

.erp-stage{
  min-width:0;
  min-height:0;
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:14px;
}

.erp-topbar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:18px;
  flex-wrap:wrap;
}

.app-page-head{
  padding:18px 20px 14px;
  border:1px solid var(--app-border);
  border-radius:var(--radius-lg);
  background:#fff;
}

.app-page-head h1{
  margin:0;
  font-size:clamp(34px,3vw,56px);
  font-weight:780;
  letter-spacing:-.03em;
}

.app-page-head p{
  margin:10px 0 0;
  padding-top:10px;
  border-top:1px solid #dfe8f1;
  color:var(--app-muted);
  font-size:16px;
  line-height:1.65;
  max-width:980px;
}

.erp-card{
  background:var(--app-surface);
  border:1px solid var(--app-border);
  border-radius:var(--radius-xl);
  box-shadow:var(--shadow-soft);
  overflow:hidden;
}

.erp-card-head{
  padding:16px 18px;
  border-bottom:1px solid var(--app-border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  flex-wrap:wrap;
}

.erp-card-head h2,.erp-card-head h3{
  margin:0;
  font-size:22px;
  font-weight:760;
  letter-spacing:-.02em;
}

.erp-card-body{
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.panel-grid{
  display:grid;
  grid-template-columns:minmax(0,1.08fr) minmax(340px,.92fr);
  gap:14px;
  align-items:start;
}

.aux-grid{
  grid-template-columns:minmax(0,1.15fr) minmax(320px,.85fr);
}

.erp-form-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:14px;
}

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

.full{grid-column:1/-1}

.erp-field{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.erp-field label{
  font-size:12px;
  font-weight:750;
  color:#3e546b;
  text-transform:uppercase;
  letter-spacing:.06em;
}

.field-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}

.field-badge{
  display:inline-flex;
  align-items:center;
  min-height:28px;
  padding:0 10px;
  border-radius:999px;
  background:#edf4fb;
  border:1px solid #c9daee;
  color:var(--app-primary);
  font-size:12px;
  font-weight:700;
}

input,select{
  width:100%;
  min-height:46px;
  border:1px solid var(--app-border-strong);
  background:#fff;
  color:var(--app-text);
  border-radius:10px;
  padding:10px 12px;
  font-size:15px;
  outline:none;
  transition:border-color .15s ease,box-shadow .15s ease,background-color .15s ease;
}

input:focus,select:focus{
  border-color:#84add3;
  box-shadow:0 0 0 3px rgba(15,103,182,.14);
}

.formula-input[readonly]{
  background:#f2f7fc;
}

.hint{
  font-size:13px;
  line-height:1.65;
  color:var(--app-muted);
}

.erp-btn{
  min-height:42px;
  padding:0 16px;
  border-radius:10px;
  border:1px solid var(--app-border-strong);
  background:#fff;
  color:#23384f;
  font-weight:700;
  transition:background-color .14s ease,border-color .14s ease,color .14s ease;
}

.erp-btn:hover{
  background:#f5f9fc;
  border-color:#a8c0d8;
}

.erp-btn-primary{
  background:var(--app-primary);
  border-color:var(--app-primary);
  color:#fff;
}

.erp-btn-primary:hover{
  background:var(--app-primary-hover);
  border-color:var(--app-primary-hover);
}

.erp-btn-danger{
  color:var(--app-danger);
  border-color:#e9b9bf;
  background:#fff7f8;
}

.erp-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}

.status-chip{
  display:inline-flex;
  align-items:center;
  min-height:30px;
  padding:0 11px;
  border-radius:999px;
  border:1px solid #c9daee;
  background:#edf4fb;
  color:var(--app-primary);
  font-size:12px;
  font-weight:700;
  white-space:nowrap;
}

.status-chip.neutral{
  background:#f3f6f9;
  border-color:#d7e2ec;
  color:#4b5f73;
}

.project-toolbar-card .erp-card-body{
  gap:12px;
}

.project-toolbar-grid{
  display:grid;
  grid-template-columns:minmax(0,1.1fr) minmax(240px,.7fr) minmax(280px,.9fr);
  gap:12px;
  align-items:end;
}

.project-toolbar-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.project-toolbar-actions .erp-btn{
  flex:0 0 auto;
}

.project-toolbar-footer{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
  color:var(--app-muted);
}

.project-toolbar-footer p{
  margin:0;
  line-height:1.6;
}

.collapse-card{
  border:1px solid #dbe5f3;
  border-radius:14px;
  background:#fbfdff;
  padding:12px 14px;
}

.collapse-card summary{
  list-style:none;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  font-weight:760;
}

.collapse-card summary::-webkit-details-marker{display:none}
.summary-note{font-size:12px;color:var(--app-muted);font-weight:600}

.result-surface{
  min-height:180px;
  padding:16px;
  border-radius:14px;
  border:1px solid #d8e6f4;
  background:linear-gradient(180deg,#f8fbff,#f1f6fd);
  line-height:1.75;
  color:#1b3653;
}

.result-surface.is-error{
  border-color:#efc1c3;
  background:#fff6f6;
  color:var(--app-danger);
}

.result-surface.is-empty{
  color:var(--app-muted);
}

.result-title{
  margin:0 0 8px;
  font-size:20px;
  font-weight:780;
  letter-spacing:-.02em;
  color:#0f2947;
}

.result-surface strong{color:#10233f}

.banner-404{
  padding:13px 16px;
  border-radius:10px;
  border:1px solid #efc1c3;
  background:#fff6f6;
  color:var(--app-danger);
  font-size:14px;
}

.subsection-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}

.subsection-head h3{
  margin:0;
  font-size:18px;
  font-weight:760;
}

.office-wrap{
  display:flex;
  flex-direction:column;
  gap:12px;
}

.office-card{
  padding:14px;
  border-radius:14px;
  border:1px solid var(--app-border);
  background:var(--app-surface-soft);
}

.office-card-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:12px;
}

.office-tag{
  display:inline-flex;
  align-items:center;
  min-height:28px;
  padding:0 10px;
  border-radius:999px;
  background:#eef4ff;
  border:1px solid #d2deff;
  color:#1b4ac3;
  font-size:12px;
  font-weight:700;
}

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

.office-hint{
  min-height:46px;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid #d8e6f4;
  background:#fff;
  color:#1b4ac3;
  font-weight:700;
  display:flex;
  align-items:center;
}

.guide-body{
  line-height:1.8;
  color:var(--app-muted);
}

.guide-nav{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}

.guide-section{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.guide-section h3{
  margin:0;
  color:var(--app-text);
  font-size:20px;
}

.table-wrap{
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border:1px solid var(--app-border);
  border-radius:12px;
  background:#fff;
}

table{
  width:100%;
  border-collapse:collapse;
  min-width:680px;
}

th,td{
  padding:10px 12px;
  border-bottom:1px solid #e6edf4;
  text-align:left;
  font-size:14px;
  vertical-align:top;
}

th{
  background:#f3f8fd;
  color:#3f5871;
  font-size:12px;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.08em;
}

.guide-accordion{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.guide-accordion details{
  border:1px solid #dbe5f3;
  border-radius:14px;
  background:#fafcff;
  padding:12px 14px;
}

.guide-accordion summary{
  cursor:pointer;
  font-weight:760;
  color:var(--app-text);
}

.guide-accent-box{
  margin-top:10px;
  padding:12px 14px;
  border-radius:12px;
  background:#eef4ff;
  color:#274765;
}

.tab-panel.hidden,
.hidden{display:none !important}

.logout-form{margin:0}
.app-logout-btn{min-height:38px;border-radius:8px;padding:0 14px;background:#fff}

.app-modal{
  position:fixed;
  inset:0;
  z-index:90;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  background:rgba(18,34,53,.34);
}

.app-modal-card{
  width:min(640px,100%);
  max-height:calc(100vh - 48px);
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border-radius:18px;
  border:1px solid var(--app-border);
  background:#fff;
  box-shadow:0 24px 56px rgba(18,34,53,.22);
}

.app-modal-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  padding:18px 20px 16px;
  border-bottom:1px solid var(--app-border);
}

.app-modal-head h3{
  margin:0;
  font-size:24px;
  font-weight:780;
  letter-spacing:-.02em;
}

.app-modal-head p{
  margin:8px 0 0;
  color:var(--app-muted);
  line-height:1.6;
}

.app-modal-body{
  padding:18px 20px 20px;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.app-modal-close{
  width:40px;
  min-width:40px;
  height:40px;
  border-radius:10px;
  border:1px solid var(--app-border-strong);
  background:#fff;
  color:#4a6177;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:24px;
  line-height:1;
}

.app-modal-close:hover{
  background:#f5f9fc;
  border-color:#a8c0d8;
}

.settings-modal-card{
  width:min(680px,100%);
}

.settings-hint{
  margin-top:-4px;
}

.calc-overlay{
  position:fixed;
  inset:0;
  z-index:80;
  display:none;
  align-items:flex-end;
  justify-content:center;
  padding:18px;
  background:rgba(18,34,53,.34);
}

.calc-overlay.show{display:flex}

.calc-panel{
  width:min(620px,100%);
  max-height:min(82vh,720px);
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border-radius:24px;
  background:#fff;
  border:1px solid var(--app-border);
  box-shadow:0 24px 56px rgba(18,34,53,.22);
  padding:16px;
}

.calc-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
  position:sticky;
  top:0;
  z-index:2;
  background:#fff;
  padding-bottom:10px;
}

.calc-title{font-size:20px;font-weight:780}
.calc-target,.calc-preview{color:var(--app-muted);font-size:13px}

.calc-screen{
  min-height:66px;
  padding:14px 16px;
  border-radius:14px;
  border:1px solid #d6e0ed;
  background:#f8fbff;
  color:var(--app-text);
  font-size:24px;
  line-height:1.4;
  word-break:break-all;
  margin-bottom:8px;
}

.calc-screen .caret{
  display:inline-block;
  width:2px;
  height:1.1em;
  background:var(--app-primary);
  vertical-align:text-bottom;
  animation:blink 1s steps(1) infinite;
}

@keyframes blink{50%{opacity:0}}

.calc-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:8px;
  margin-top:10px;
}

.calc-grid button{
  min-height:52px;
  border:1px solid var(--app-border);
  border-radius:12px;
  background:#fff;
  color:var(--app-text);
  font-weight:780;
  user-select:none;
  -webkit-user-select:none;
}

.calc-grid button:hover{background:#f4f9ff}
.calc-grid button:active{transform:scale(.985);background:#eef5fc}
.calc-grid .danger{background:var(--app-danger-soft);color:var(--app-danger);border-color:#efc1c3}
.calc-grid .success{background:var(--app-success);color:#fff;border-color:var(--app-success)}

.auth-shell{grid-template-rows:auto minmax(0,1fr)}
.auth-topbar .app-brand-copy{flex-direction:column;align-items:flex-start;gap:2px}
.auth-topbar .app-brand-copy strong{font-size:20px}
.auth-topbar .app-brand-copy span{font-size:12px;font-weight:500}

.auth-stage{
  min-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:32px 18px;
}

.auth-panel{
  width:min(460px,100%);
  padding:30px;
  border-radius:28px;
  border:1px solid var(--app-border);
  background:rgba(255,255,255,.95);
  box-shadow:0 18px 46px rgba(18,34,53,.12);
}

.auth-panel-badge{
  display:inline-flex;
  min-height:30px;
  padding:0 12px;
  border-radius:999px;
  align-items:center;
  background:var(--app-primary-soft);
  color:var(--app-primary);
  font-size:12px;
  font-weight:700;
}

.auth-panel h1{
  margin:16px 0 0;
  font-size:34px;
  line-height:1.08;
  letter-spacing:-.03em;
}

.auth-panel p{
  margin:12px 0 0;
  color:var(--app-muted);
  line-height:1.7;
}

.auth-alert{
  margin-top:16px;
  padding:12px 14px;
  border-radius:12px;
  border:1px solid #efc1c3;
  background:#fff6f6;
  color:var(--app-danger);
  font-size:14px;
}

.auth-form{
  margin-top:18px;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.auth-submit{width:100%}

@media (max-width:1180px){
  .project-toolbar-grid{
    grid-template-columns:1fr 1fr;
  }

  .project-toolbar-actions{
    grid-column:1/-1;
  }
}

@media (max-width:980px){
  .app-layout{grid-template-columns:220px minmax(0,1fr)}
  .panel-grid,.aux-grid{grid-template-columns:1fr}
  .compact-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}

@media (max-width:760px){
  .auth-shell{
    grid-template-rows:auto minmax(0,1fr);
  }

  .app-topbar{
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    padding:14px 16px;
    align-items:start;
    gap:12px;
  }

  .app-topbar-left,.app-topbar-right{
    min-width:0;
    align-items:flex-start;
  }

  .app-topbar-left{
    flex-direction:column;
    gap:8px;
  }

  .app-topbar-right{
    flex-direction:column;
    align-items:stretch;
    gap:8px;
  }

  .app-topbar-right .status-chip{
    display:none;
  }

  .app-topbar-right .erp-btn,
  .app-topbar-right .logout-form,
  .app-topbar-right .logout-form .erp-btn{
    width:100%;
  }

  .app-brand-copy{
    flex-direction:column;
    align-items:flex-start;
    gap:2px;
    min-width:0;
  }

  .app-brand-copy strong{
    max-width:100%;
    font-size:20px;
    line-height:1.08;
  }

  .app-brand-copy span{
    max-width:30ch;
    font-size:13px;
    line-height:1.35;
  }

  .app-layout{
    grid-template-columns:1fr;
  }

  .app-sidebar{
    position:static;
    top:auto;
    height:auto;
    overflow:visible;
    border-right:0;
    border-bottom:1px solid var(--app-border);
    padding:10px 10px 12px;
  }

  .app-sidebar-nav{
    flex-direction:row;
    width:100%;
    max-width:100%;
    overflow:auto;
    padding-bottom:4px;
    scroll-snap-type:x proximity;
  }

  .erp-nav-link{
    flex:0 0 auto;
    white-space:nowrap;
    min-width:max-content;
    scroll-snap-align:start;
  }

  .app-sidebar-note{
    display:none;
  }

  .erp-stage,.auth-stage{
    padding:12px;
  }

  .project-toolbar-grid,
  .erp-form-grid,
  .compact-grid,
  .office-card-grid{
    grid-template-columns:1fr;
  }

  .project-toolbar-card .erp-card-body,
  .erp-card-body{
    padding:14px;
  }

  .project-toolbar-actions{
    display:grid;
    grid-template-columns:1fr;
    gap:10px;
    width:100%;
  }

  .project-toolbar-actions .erp-btn{
    width:100%;
  }

  .project-toolbar-footer{
    align-items:flex-start;
  }

  .project-toolbar-footer .status-chip{
    order:0;
  }

  .project-toolbar-footer p{
    width:100%;
  }

  .erp-card-head,
  .subsection-head{
    flex-direction:column;
    align-items:flex-start;
  }

  .app-page-head h1,
  .auth-panel h1{
    font-size:28px;
  }

  .app-page-head p{
    font-size:14px;
  }

  .table-wrap table{
    min-width:600px;
  }

  .calc-overlay{
    padding:0;
  }

  .calc-panel{
    width:100%;
    max-height:calc(100vh - 8px);
    border-radius:22px 22px 0 0;
    border-bottom:0;
    padding:14px 14px calc(14px + env(safe-area-inset-bottom));
  }

  .calc-head{
    margin-bottom:10px;
  }

  .calc-screen{
    min-height:62px;
    font-size:22px;
  }

  .calc-grid{
    gap:7px;
  }

  .calc-grid button{
    min-height:56px;
    font-size:17px;
  }

  .app-modal{
    padding:12px;
  }

  .app-modal-card{
    max-height:calc(100vh - 24px);
  }

  .app-modal-head,
  .app-modal-body{
    padding:16px;
  }

  .result-surface{
    min-height:128px;
    padding:14px;
    line-height:1.68;
  }

  .guide-nav{
    flex-wrap:nowrap;
    overflow:auto;
    -webkit-overflow-scrolling:touch;
    padding-bottom:4px;
  }

  .guide-nav .erp-btn{
    white-space:nowrap;
  }
}

@media (max-width:420px){
  .app-topbar{
    padding:12px 12px 10px;
  }

  .app-brand-mark{
    width:36px;
    height:36px;
  }

  .project-toolbar-actions{
    grid-template-columns:1fr;
  }

  .erp-actions{
    flex-direction:column;
  }

  .erp-actions .erp-btn{
    width:100%;
  }

  .calc-title{
    font-size:18px;
  }

  .app-modal-head h3{
    font-size:22px;
  }

  .calc-grid button{
    min-height:54px;
    font-size:16px;
  }
}
