/* KIRA Clean UI v27 */
*,*::before,*::after{box-sizing:border-box}
html,body{height:100%;overflow-x:hidden}
body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:#f6f7fb;
  color:#111;
}
a{color:inherit}
.wrap{
  width:100%;
  max-width:980px;
  margin:18px auto;
  padding:0 14px;
}
.card{
  background:#fff;
  border:1px solid #e4e7ef;
  border-radius:14px;
  padding:16px;
  margin:12px 0;
  box-shadow:0 1px 2px rgba(0,0,0,.03);
}
.card h2{margin:0 0 10px;font-size:34px;letter-spacing:-.3px}
.card h3{margin:0 0 10px;font-size:22px}
.small{font-size:13px;opacity:.75}
.msg{padding:10px 12px;border-radius:12px;margin:12px 0}
.msg.err{background:#ffe8e8;border:1px solid #ffb2b2}
.msg.ok{background:#eaffea;border:1px solid #a9f0a9}

label{display:block;font-size:13px;opacity:.8;margin:8px 0 4px}
input,select,textarea{
  width:100%;
  max-width:100%;
  padding:10px 12px;
  border:1px solid #d7dce8;
  border-radius:12px;
  outline:none;
  background:#fff;
}
input:focus,select:focus,textarea:focus{border-color:#111}
button,.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:12px 14px;
  border-radius:14px;
  border:1px solid #d7dce8;
  background:#fff;
  cursor:pointer;
  text-decoration:none;
  user-select:none;
}
button.primary,.btn.primary{
  background:#111;
  border-color:#111;
  color:#fff;
}
button:active,.btn:active{transform:translateY(1px)}
.actions{display:flex;gap:12px;flex-wrap:wrap;align-items:center}
.actions .btn, .actions button{min-width:140px}
@media (max-width:600px){
  .actions{gap:12px}
  .actions .btn, .actions button{flex:1 1 46%; min-width:150px}
}

.badge{
  display:inline-block;
  padding:4px 10px;
  border-radius:999px;
  border:1px solid #e4e7ef;
  background:#f3f5fb;
  font-size:12px;
}

.tabs{display:flex;gap:10px;flex-wrap:wrap;margin:10px 0}
.tab{
  padding:10px 12px;
  border-radius:999px;
  border:1px solid #d7dce8;
  text-decoration:none;
  background:#fff;
}
.tab.active{background:#111;color:#fff;border-color:#111}

.table-scroll{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
.table{width:100%;border-collapse:collapse;min-width:700px}
.table th,.table td{padding:10px 10px;border-bottom:1px solid #eceff6;text-align:left;vertical-align:top}
.table th{font-size:13px;opacity:.75}
.table tr:hover td{background:#fafbff}

.order-row{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px;align-items:start}
.field{min-width:0}
.field.actions{display:flex;gap:10px;align-items:center}
.iconbtn{
  width:44px;height:40px;border-radius:12px;
  border:1px solid #d7dce8;background:#fff;
  display:inline-flex;align-items:center;justify-content:center;
}
.iconbtn:active{transform:translateY(1px)}
@media (max-width:600px){
  .order-row{grid-template-columns:repeat(auto-fit,minmax(140px,1fr))}
}

/* Header */
header.top{
  position:sticky;
  top:0;
  width:100%;
  background:#111;
  z-index:999;
  padding:10px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
}
.top-center{
  display:flex;
  align-items:center;
  gap:12px;
  white-space:nowrap;
  min-width:0;
}
.brand{
  color:#fff;
  text-decoration:none;
  font-weight:800;
  letter-spacing:.4px;
}
.userchip-btn{
  display:flex;
  align-items:center;
  gap:8px;
  background:transparent;
  border:0;
  padding:6px 8px;
  border-radius:12px;
  cursor:pointer;
  color:#fff;
}
.userchip-btn:hover{background:rgba(255,255,255,.06)}
.userchip-btn:active{background:rgba(255,255,255,.10)}
.userchip-ava{
  width:28px;height:28px;border-radius:999px;
  object-fit:cover;
  border:1px solid rgba(255,255,255,.35);
  display:block;
}
.userchip-name{
  font-weight:600;
  font-size:14px;
  opacity:.95;
  max-width:180px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

/* Desktop nav (optional) */
nav.desktop-nav{
  display:flex;
  gap:14px;
  flex-wrap:wrap;
  align-items:center;
}
nav.desktop-nav a{
  color:#fff;
  text-decoration:none;
  padding:8px 10px;
  border-radius:10px;
}
nav.desktop-nav a:hover{background:rgba(255,255,255,.08)}

/* User menu dropdown */
.nav-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:998}
.nav-backdrop[hidden]{display:none !important}

.user-menu{
  position:fixed;
  z-index:1000;
  background:#111;
  padding:12px;
  border-radius:14px;
  box-shadow:0 16px 40px rgba(0,0,0,.35);
  width:280px;
  max-width:calc(100vw - 24px);
}
.user-menu[hidden]{display:none !important}
.user-menu a{
  display:block;
  color:#fff;
  text-decoration:none;
  background:rgba(255,255,255,.06);
  padding:14px 16px;
  border-radius:14px;
  margin:8px 0;
}
.user-menu a:active{background:rgba(255,255,255,.12)}

/* Mobile: like app */
@media (max-width:720px){
  header.top{justify-content:center}
  nav.desktop-nav{display:none}
  body.menu-open{overflow:hidden}
  .user-menu{width:min(420px, calc(100vw - 24px))}
}

/* Footer */
.foot{
  padding:18px 14px;
  text-align:center;
  color:#666;
  font-size:13px;
}

/* v28 UI fixes */
.table th.sortable{cursor:pointer; user-select:none; position:relative}
.table th.sortable:hover{background:#f3f5fb}
.table th.sortable::after{content:"↕"; font-size:12px; opacity:.35; margin-left:6px}

/* legacy dict links */
a.btnlink{display:inline-block; padding:10px 12px; border-radius:999px; border:1px solid #d7dce8; background:#fff; text-decoration:none}
a.btnlink:hover{background:#f0f2f8}
a.btnlink.active{background:#111;color:#fff;border-color:#111}

/* table action controls should not stretch out of cards */
.table td input[type="text"],
.table td input[type="password"],
.table td input:not([type]),
.table td select{
  width:220px;
  max-width:100%;
}

/* avatar preview */
.avatar-preview{width:120px;height:120px;object-fit:cover;border-radius:12px;border:1px solid #e2e6f3;display:block}

/* compatibility */
.row{display:flex;gap:12px;flex-wrap:wrap;align-items:center}

/* v31: stack actions buttons */
.actions.stack{flex-direction:column;align-items:stretch}
.actions.stack .btn,
.actions.stack button{width:100%}
.actions.stack form{width:100%; margin:0}
.actions.stack form + form{margin-top:8px}

/* v34: table filter tools */
.table-tools{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
  margin:10px 0 10px;
}
.table-tools .table-filter-col{max-width:240px}
.table-tools .table-filter-text{max-width:320px}

/* v34: header layout KIRA left, avatar center, login right */
header.top{
  display:grid !important;
  grid-template-columns: 1fr auto 1fr;
  align-items:center;
}
header.top .brand{justify-self:start}
header.top .hdr-avatar{justify-self:center}
header.top .hdr-login{justify-self:end}

.hdr-avatar,.hdr-login{
  background:transparent;
  border:0;
  padding:6px 8px;
  border-radius:12px;
  cursor:pointer;
  color:#fff;
}
.hdr-avatar:hover,.hdr-login:hover{background:rgba(255,255,255,.06)}
.hdr-avatar:active,.hdr-login:active{background:rgba(255,255,255,.10)}
.hdr-login{
  font-weight:600;
  font-size:14px;
  opacity:.95;
  max-width:200px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
@media (max-width:720px){
  .hdr-login{max-width:120px}
}

/* v35: header layout KIRA left, login+avatar right */
header.top{
  display:flex !important;
  justify-content:space-between !important;
  align-items:center !important;
  grid-template-columns: unset !important;
}
header.top .hdr-right{
  display:flex;
  align-items:center;
  gap:10px;
}

/* v36: milling picker modal */
body.modal-open{overflow:hidden}
.modal-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.35);
  z-index:2000;
}
.milling-modal{
  position:fixed;
  left:50%;
  top:72px;
  transform:translateX(-50%);
  width:min(860px, calc(100vw - 24px));
  max-height:calc(100vh - 120px);
  background:#fff;
  border:1px solid #e4e7ef;
  border-radius:16px;
  z-index:2001;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  box-shadow:0 18px 50px rgba(0,0,0,.25);
}
.milling-modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;
  border-bottom:1px solid #eceff6;
}
.milling-modal-title{
  font-weight:800;
  font-size:16px;
}
.milling-modal-close{
  width:38px;
  height:38px;
  border-radius:12px;
  border:1px solid #d7dce8;
  background:#fff;
  cursor:pointer;
  font-size:22px;
  line-height:1;
}
.milling-modal-body{
  padding:12px;
  overflow:auto;
}
.milling-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(130px, 1fr));
  gap:12px;
}
.milling-tile{
  border:1px solid #d7dce8;
  background:#fff;
  border-radius:14px;
  padding:8px;
  cursor:pointer;
  text-align:center;
}
.milling-tile:active{transform:translateY(1px)}
.milling-tile.selected{
  border-color:#111;
  outline:2px solid #111;
  outline-offset:1px;
}
.milling-img{
  width:100%;
  height:auto;
  border-radius:12px;
  display:block;
}
.milling-cap{
  margin-top:8px;
  font-size:13px;
  font-weight:700;
}
@media (max-width:720px){
  .milling-modal{top:64px; max-height:calc(100vh - 92px)}
  .milling-grid{grid-template-columns:repeat(auto-fill, minmax(110px, 1fr))}
}

/* v37: milling modal search + empty */
.milling-modal-head{gap:10px}
.milling-modal-headtop{display:flex;align-items:center;justify-content:space-between;gap:10px}
.milling-modal-search{
  width:100%;
  max-width:100%;
  padding:10px 12px;
  border:1px solid #d7dce8;
  border-radius:12px;
}
.milling-modal-close{cursor:pointer}
.milling-empty{
  padding:18px;
  text-align:center;
  font-weight:700;
  opacity:.7;
}

/* v39: label on milling image */
.milling-thumb{
  position:relative;
  border-radius:12px;
  overflow:hidden;
}
.milling-label{
  position:absolute;
  left:0; right:0; bottom:0;
  padding:10px 10px 9px;
  text-align:center;
  color:#fff;
  font-weight:800;
  line-height:1.1;
  background:linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,.0));
  text-shadow:0 1px 2px rgba(0,0,0,.6);
  word-break:break-word;
}
.milling-modal.labels-off .milling-label{display:none;}
.milling-modal-toggle{
  display:flex;
  align-items:center;
  gap:10px;
  font-size:13px;
  opacity:.85;
  user-select:none;
}
.milling-modal-toggle input{width:18px;height:18px}

/* v41: obkat picker modal */
.obkat-modal{
  position:fixed;
  left:50%;
  top:72px;
  transform:translateX(-50%);
  width:min(860px, calc(100vw - 24px));
  max-height:calc(100vh - 120px);
  background:#fff;
  border:1px solid #e4e7ef;
  border-radius:16px;
  z-index:2001;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  box-shadow:0 18px 50px rgba(0,0,0,.25);
}
.obkat-modal-head{
  display:flex;
  flex-direction:column;
  gap:10px;
  padding:12px 14px;
  border-bottom:1px solid #eceff6;
}
.obkat-modal-headtop{display:flex;align-items:center;justify-content:space-between;gap:10px}
.obkat-modal-title{font-weight:800;font-size:16px}
.obkat-modal-close{
  width:38px;height:38px;border-radius:12px;border:1px solid #d7dce8;background:#fff;cursor:pointer;
  font-size:22px;line-height:1;
}
.obkat-modal-search{
  width:100%;
  max-width:100%;
  padding:10px 12px;
  border:1px solid #d7dce8;
  border-radius:12px;
}
.obkat-modal-toggle{
  display:flex;align-items:center;gap:10px;font-size:13px;opacity:.85;user-select:none;
}
.obkat-modal-toggle input{width:18px;height:18px}

.obkat-modal-body{padding:12px;overflow:auto}
.obkat-grid{display:grid;grid-template-columns:repeat(auto-fill, minmax(130px, 1fr));gap:12px}
.obkat-tile{border:1px solid #d7dce8;background:#fff;border-radius:14px;padding:8px;cursor:pointer;text-align:center}
.obkat-tile:active{transform:translateY(1px)}
.obkat-tile.selected{border-color:#111;outline:2px solid #111;outline-offset:1px}
.obkat-thumb{position:relative;border-radius:12px;overflow:hidden}
.obkat-img{width:100%;height:auto;display:block;border-radius:12px}
.obkat-label{
  position:absolute;left:0;right:0;bottom:0;
  padding:10px 10px 9px;
  text-align:center;
  color:#fff;
  font-weight:800;
  line-height:1.1;
  background:linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,.0));
  text-shadow:0 1px 2px rgba(0,0,0,.6);
  word-break:break-word;
}
.obkat-modal.labels-off .obkat-label{display:none;}
.obkat-empty{padding:18px;text-align:center;font-weight:700;opacity:.7}

@media (max-width:720px){
  .obkat-modal{top:64px; max-height:calc(100vh - 92px)}
  .obkat-grid{grid-template-columns:repeat(auto-fill, minmax(110px, 1fr))}
}
