:root{
  --bg:#eef3f9;
  --bg-soft:#f7f9fc;
  --surface:#ffffff;
  --surface-2:#f9fbfd;
  --surface-3:#edf3f9;
  --text:#122033;
  --muted:#66778c;
  --line:#dbe4ee;
  --line-strong:#c3d1df;
  --primary:#1f5eff;
  --primary-2:#1648c5;
  --primary-soft:#e9f0ff;
  --success:#18794e;
  --success-soft:#ebf8f1;
  --danger:#c0362c;
  --danger-soft:#fff2f0;
  --warning:#b56b00;
  --warning-soft:#fff7e8;
  --shadow:0 18px 40px rgba(15,23,42,.08);
  --shadow-strong:0 24px 60px rgba(15,23,42,.16);
  --radius:18px;
  --radius-sm:14px;
  --topbar-total-height:88px;
}
body.theme-escuro{
  --bg:#0b1220;
  --bg-soft:#101827;
  --surface:#121d31;
  --surface-2:#17233a;
  --surface-3:#1d2b44;
  --text:#eef4ff;
  --muted:#9baec8;
  --line:#283958;
  --line-strong:#36507a;
  --primary:#6a98ff;
  --primary-2:#4f7de7;
  --primary-soft:#1b2d56;
  --success:#35c183;
  --success-soft:#113227;
  --danger:#ff8c84;
  --danger-soft:#3a1d24;
  --warning:#ffbe59;
  --warning-soft:#3d2f12;
  --shadow:0 18px 40px rgba(0,0,0,.34);
  --shadow-strong:0 28px 68px rgba(0,0,0,.46);
}
*{box-sizing:border-box}
html,body{margin:0;padding:0;background:var(--bg);color:var(--text);font-family:Inter,Segoe UI,Arial,sans-serif}
body{min-height:100vh}
a{text-decoration:none;color:inherit}
button,input,select,textarea{font:inherit}
img{max-width:100%}
mark,.search-hit{background:#ffe86c;color:#1d2430;padding:0 3px;border-radius:4px}
.hidden{display:none!important}

.topbar{
  position:fixed;top:0;left:0;right:0;z-index:1000;
  background:rgba(255,255,255,.9);backdrop-filter:blur(14px);
  border-bottom:1px solid var(--line);box-shadow:0 8px 28px rgba(15,23,42,.06)
}
body.theme-escuro .topbar{background:rgba(11,18,32,.93)}
.topbar-inner{max-width:1600px;margin:0 auto;padding:0 20px}
.topbar-main-row{
  min-height:var(--topbar-total-height);
  display:grid;
  grid-template-columns:auto auto minmax(180px,320px) auto;
  align-items:center;
  gap:16px;
}
.brand{display:flex;align-items:center;gap:12px;min-width:0}
.brand-logo-wrap{
  width:94px;height:46px;border-radius:14px;background:var(--surface);
  border:1px solid var(--line);box-shadow:var(--shadow);display:flex;
  align-items:center;justify-content:center;padding:7px 10px;overflow:hidden;flex:0 0 auto
}
.brand-logo-wrap img{width:100%;height:100%;object-fit:contain;object-position:center}
.brand-copy{min-width:0}
.brand strong{display:block;font-size:18px;letter-spacing:-.02em;line-height:1.1}
.brand small{display:block;color:var(--muted);margin-top:2px;font-size:12px}

.topbar-nav{display:flex;align-items:center;gap:8px;min-width:0;flex-wrap:nowrap}
.nav-link{
  display:inline-flex;align-items:center;gap:8px;height:42px;padding:0 14px;border-radius:12px;
  color:var(--text);font-weight:700;white-space:nowrap;border:1px solid transparent;background:transparent
}
.nav-link:hover{background:var(--surface-2);border-color:var(--line)}
.nav-link.active,.topnav-item.is-active > .nav-link,.topnav-item[open] > .nav-link{background:var(--primary-soft);color:var(--primary);border-color:transparent}
body.theme-escuro .nav-link.active,
body.theme-escuro .topnav-item.is-active > .nav-link,
body.theme-escuro .topnav-item[open] > .nav-link{color:#fff;background:rgba(106,152,255,.22)}

.topnav-item{position:relative}
.topnav-item summary{list-style:none;cursor:pointer}
.topnav-item summary::-webkit-details-marker,.nav-group summary::-webkit-details-marker{display:none}
.topnav-item summary.nav-link::after{content:'▾';font-size:11px;opacity:.8;margin-left:2px}
.topnav-dropdown{
  position:absolute;top:calc(100% + 10px);left:0;min-width:260px;max-width:340px;max-height:70vh;overflow:auto;
  background:var(--surface);border:1px solid var(--line);border-radius:18px;box-shadow:var(--shadow-strong);
  padding:8px;display:none
}
.topnav-item[open] .topnav-dropdown{display:block}
.topnav-dropdown a{display:block;padding:11px 13px;border-radius:12px;color:var(--text)}
.topnav-dropdown a:hover{background:var(--surface-3)}
.topnav-dropdown a.active{background:var(--primary-soft);color:var(--primary)}
body.theme-escuro .topnav-dropdown a.active{color:#fff;background:rgba(106,152,255,.22)}

.global-search{display:flex;align-items:center;gap:10px}
.global-search-top{width:100%;max-width:320px}
.search-box{position:relative;flex:1;min-width:0}
.search-icon{position:absolute;left:14px;top:50%;transform:translateY(-50%);font-size:18px;color:var(--muted);pointer-events:none}
.global-search input{
  width:100%;height:42px;border:1px solid var(--line);border-radius:12px;padding:0 14px 0 40px;
  background:var(--surface);color:var(--text);outline:none
}
.global-search input:focus,input[type=text]:focus,input[type=email]:focus,input[type=password]:focus,select:focus,textarea:focus{border-color:var(--primary);box-shadow:0 0 0 4px rgba(31,94,255,.12)}

.topbar-actions{display:flex;align-items:center;justify-content:flex-end;gap:10px;min-width:0}
.compact-control,.profile-chip{
  display:inline-flex;align-items:center;gap:8px;height:42px;padding:0 12px;border-radius:12px;
  background:var(--surface);border:1px solid var(--line);box-shadow:0 6px 18px rgba(15,23,42,.04)
}
.compact-control span{font-size:11px;font-weight:800;color:var(--muted);text-transform:uppercase;letter-spacing:.08em}
.compact-control select{border:0;background:transparent;color:var(--text);font-weight:700;outline:none;min-width:74px}
.profile-chip{font-weight:700}
.profile-chip-exit{color:var(--danger)}
.user-chip{max-width:220px;overflow:hidden;text-overflow:ellipsis}
button,.btn,.icon-btn{border:0;border-radius:12px;padding:12px 16px;font-weight:700;cursor:pointer;transition:transform .18s ease,box-shadow .18s ease,background .18s ease}
button:hover,.btn:hover,.icon-btn:hover{transform:translateY(-1px)}
button[type=submit],.btn-primary,.global-search button{background:linear-gradient(180deg,var(--primary),var(--primary-2));color:#fff;box-shadow:0 12px 22px rgba(31,94,255,.22)}
.btn-secondary{background:var(--surface-3);color:var(--text)}
.btn-warning{background:var(--warning-soft);color:var(--warning)}
.btn-danger{background:var(--danger-soft);color:var(--danger)}
.btn-success{background:var(--success-soft);color:var(--success)}
.btn-outline{background:transparent;color:var(--text);border:1px solid var(--line)}
.btn-sm{padding:9px 12px;font-size:13px;border-radius:10px}
.icon-btn{background:var(--surface);border:1px solid var(--line);padding:10px 14px}
.mobile-menu-btn{display:none}

.mobile-dropdown{
  display:none;position:fixed;top:calc(var(--topbar-total-height) + 10px);right:14px;left:14px;
  background:var(--surface);border:1px solid var(--line);border-radius:20px;box-shadow:var(--shadow-strong);
  padding:16px;max-height:calc(100vh - var(--topbar-total-height) - 24px);overflow:auto;
  z-index:1200;opacity:0;visibility:hidden;pointer-events:none;transform:translateY(-8px);
  transition:opacity .2s ease,transform .2s ease,visibility .2s ease;
}
.mobile-dropdown.open{opacity:1;visibility:visible;pointer-events:auto;transform:translateY(0)}
.mobile-dropdown-section + .mobile-dropdown-section{margin-top:14px;padding-top:14px;border-top:1px solid var(--line)}
.mobile-dropdown-actions{display:grid;grid-template-columns:1fr;gap:10px}
.mobile-dropdown-actions .profile-chip,.mobile-dropdown-actions .compact-control{justify-content:center}
.global-search-mobile{display:flex}
.nav-stack{display:flex;flex-direction:column;gap:8px}
.nav-stack>a,.nav-group summary,.submenu a{display:block;padding:12px 14px;border-radius:12px;color:inherit}
.nav-stack>a:hover,.nav-group summary:hover,.submenu a:hover{background:var(--surface-3)}
.nav-stack a.active,.submenu a.active{background:var(--primary-soft);color:var(--primary)}
body.theme-escuro .nav-stack a.active,body.theme-escuro .submenu a.active{color:#fff;background:rgba(106,152,255,.22)}
.nav-group{margin-top:6px;background:var(--surface-2);border-radius:14px;padding:4px}
.nav-group summary{font-weight:700;cursor:pointer;list-style:none}
.submenu{display:flex;flex-direction:column;gap:4px;padding:4px}

.page-content{padding:calc(var(--topbar-total-height) + 28px) 28px 28px;max-width:1480px;margin:0 auto}
.page-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:22px}
.page-header h1{margin:0;font-size:32px;letter-spacing:-.03em}
.page-subtitle{margin:6px 0 0 0;color:var(--muted)}
.card{background:var(--surface);border:1px solid var(--line);box-shadow:var(--shadow);border-radius:var(--radius);padding:22px;margin-bottom:20px}
.card.soft{background:linear-gradient(180deg,var(--surface),var(--surface-2))}
.card-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:14px}
.muted{color:var(--muted)}

.grid{display:grid;gap:18px}
.grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}
.grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}
.stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:18px}
.stat-card,.note-card,.search-result{padding:20px;border-radius:20px;background:var(--surface-2);border:1px solid var(--line)}
.note-card h3,.search-result h3{margin:10px 0 8px 0}
.note-preview{color:var(--muted);line-height:1.65}
.note-meta{display:flex;flex-wrap:wrap;gap:8px;align-items:center;color:var(--muted);font-size:13px;margin-bottom:10px}
.badge{display:inline-flex;align-items:center;gap:6px;background:var(--primary-soft);color:var(--primary);padding:7px 10px;border-radius:999px;font-size:12px;font-weight:700}
.badge.admin{background:var(--warning-soft);color:var(--warning)}
.actions{display:flex;flex-wrap:wrap;gap:10px}

.form-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
.form-grid .full{grid-column:1/-1}
label{display:block;font-size:13px;font-weight:800;color:var(--muted);margin-bottom:8px;text-transform:uppercase;letter-spacing:.03em}
input[type=text],input[type=email],input[type=password],select,textarea{width:100%;border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--text);padding:13px 15px;outline:none}
textarea{min-height:140px;resize:vertical}
.form-actions{display:flex;flex-wrap:wrap;gap:10px;margin-top:18px}

.table-wrap{overflow:auto;border:1px solid var(--line);border-radius:18px}
table{width:100%;border-collapse:collapse;background:var(--surface)}
th,td{padding:14px 16px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
thead th{background:var(--surface-2);font-size:12px;text-transform:uppercase;letter-spacing:.05em;color:var(--muted)}
tr:hover td{background:var(--surface-2)}

.status{display:none;padding:14px 16px;border-radius:14px;margin-bottom:14px;font-weight:700}
.status.show{display:block}
.status.ok{background:var(--success-soft);color:var(--success);border:1px solid rgba(24,121,78,.22)}
.status.error{background:var(--danger-soft);color:var(--danger);border:1px solid rgba(192,54,44,.22)}
.view-content{border:1px solid var(--line);border-radius:16px;padding:20px;background:var(--surface);line-height:1.8;min-height:180px}
.view-content :first-child{margin-top:0}.view-content :last-child{margin-bottom:0}
.search-result p{line-height:1.7}
.ql-toolbar.ql-snow,.ql-container.ql-snow{border-color:var(--line)!important;background:var(--surface);color:var(--text)}
.ql-container.ql-snow{min-height:280px;border-radius:0 0 14px 14px}
.ql-toolbar.ql-snow{border-radius:14px 14px 0 0}

.note-hero{display:grid;grid-template-columns:minmax(0,1fr);gap:18px}
.note-view-box{border:1px solid var(--line);border-radius:18px;background:linear-gradient(180deg,var(--surface),var(--surface-2));padding:22px}
.note-title{margin:0;font-size:28px;letter-spacing:-.03em}
.note-content-wrap{position:relative}
.note-image-frame{margin:18px 0 0 0;padding:12px;border-radius:18px;border:1px solid var(--line);background:var(--surface-2);display:flex;justify-content:center;align-items:center;overflow:hidden}
.note-image-frame img{display:block;max-width:100%;max-height:420px;width:auto;height:auto;object-fit:contain;border-radius:12px}

.modal{position:fixed;inset:0;display:none;align-items:center;justify-content:center;padding:24px;background:rgba(15,23,42,.48);z-index:1300}
.modal.show{display:flex}
.modal-card{width:min(980px,100%);max-height:min(92vh,1000px);overflow:auto;background:var(--surface);border:1px solid var(--line);border-radius:24px;box-shadow:var(--shadow-strong);padding:24px}
.modal-header{display:flex;align-items:flex-start;justify-content:space-between;gap:14px;margin-bottom:16px}
.modal-header h3{margin:0;font-size:24px;letter-spacing:-.03em}
.modal-close{background:var(--surface-3);color:var(--text);border:1px solid var(--line);width:42px;height:42px;border-radius:12px;padding:0;font-size:20px;line-height:1}
body.modal-open{overflow:hidden}

.shell-login{min-height:100vh;display:grid;place-items:center;padding:28px;background:radial-gradient(circle at top,#dbe9ff 0,var(--bg) 36%,var(--bg-soft) 100%)}
body.theme-escuro .shell-login{background:radial-gradient(circle at top,#1c2c54 0,var(--bg) 40%,var(--bg-soft) 100%)}
.login-panel{width:min(460px,100%);background:rgba(255,255,255,.9);border:1px solid rgba(255,255,255,.55);backdrop-filter:blur(16px);border-radius:30px;box-shadow:var(--shadow-strong);padding:34px}
body.theme-escuro .login-panel{background:rgba(18,29,49,.92);border-color:var(--line)}
.login-logo{text-align:center;margin-bottom:14px}
.login-logo-frame{width:min(290px,100%);height:118px;margin:0 auto;border-radius:20px;background:var(--surface);border:1px solid var(--line);display:flex;align-items:center;justify-content:center;padding:14px 22px;box-shadow:var(--shadow)}
.login-logo-frame img{width:100%;height:100%;object-fit:contain;object-position:center}
.login-panel h1{margin:0 0 8px 0;text-align:center;font-size:30px;letter-spacing:-.03em}
.login-panel p{margin:0 0 22px 0;text-align:center;color:var(--muted)}
.login-footer{text-align:center;margin-top:18px;color:var(--muted);font-size:13px}

@media (max-width:1380px){
  .topbar-main-row{grid-template-columns:auto minmax(300px,1fr) minmax(170px,260px) auto}
  .topbar-nav{overflow-x:auto;scrollbar-width:none}
  .topbar-nav::-webkit-scrollbar{display:none}
}
@media (max-width:1100px){
  .topbar-inner{padding:0 14px}
  .topbar-main-row{grid-template-columns:auto 1fr auto;gap:12px}
  .desktop-nav{display:none}
  .global-search-top{max-width:none}
}
@media (max-width:980px){
  :root{--topbar-total-height:78px}
  .topbar-main-row{grid-template-columns:1fr auto;gap:12px}
  .brand-copy{display:none}
  .brand-logo-wrap{width:90px;height:44px}
  .desktop-actions,.global-search-top,.desktop-nav{display:none}
  .mobile-menu-btn{display:inline-flex}
  .mobile-dropdown{display:block}
  .page-content{padding:calc(var(--topbar-total-height) + 22px) 16px 24px}
  .form-grid,.grid-2,.grid-3,.stats{grid-template-columns:1fr}
  .modal{padding:14px}
  .modal-card{padding:18px}
}
@media (max-width:640px){
  .page-header h1{font-size:28px}
  .card{padding:18px}
  .global-search-mobile{flex-direction:column;align-items:stretch}
  .global-search-mobile button{width:100%}
}
