:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #15181d;
  --muted: #667085;
  --accent: #2f6f5e;
  --accent-strong: #245a4c;
  --accent-soft: #e3f0ec;
  --accent-text: #ffffff;
  --danger: #c4372f;
  --danger-soft: #fbe9e7;
  --mark: #fff0b3;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 18%);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1f242d;
    --border: #2a303b;
    --text: #e8eaee;
    --muted: #949cab;
    --accent: #5fb39b;
    --accent-strong: #79c7b0;
    --accent-soft: #1d3530;
    --accent-text: #0b1512;
    --danger: #f06a60;
    --danger-soft: #3a1d1b;
    --mark: #5a4a12;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, .mono { font-family: var(--mono); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ic {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
}

/* ------------------------------------------------ views */

.view { min-height: 100dvh; }
.view-center {
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.spinner {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------ botões */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-sm .ic { width: 17px; height: 17px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  flex: none;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-sm { width: 32px; height: 32px; }
.icon-btn-sm .ic { width: 17px; height: 17px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------ formulários */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span:first-child { font-size: 14px; font-weight: 600; }
.field em { font-style: normal; font-weight: 400; }

input:not([type=file]),
textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px; /* evita zoom no iOS */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.4; }
textarea.mono { font-size: 15px; word-break: break-all; }
textarea.masked { -webkit-text-security: disc; text-security: disc; }
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.input-group { position: relative; display: block; }
.input-group input { padding-right: 52px; }
.input-group .icon-btn { position: absolute; right: 1px; top: 1px; }

.form-error { color: var(--danger); font-size: 14px; margin: 0 0 12px; min-height: 0; }
.form-error:empty { display: none; }
.note { font-size: 14px; margin: 10px 0 0; }

/* ------------------------------------------------ login */

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 22px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 12px 0 4px; font-size: 24px; }
.auth-card > p.muted { margin: 0 0 20px; font-size: 15px; }
.auth-logo {
  display: grid; place-items: center;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}
.auth-logo .ic { width: 28px; height: 28px; }

/* ------------------------------------------------ topo + busca */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) max(12px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  background: var(--bg);
}
.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 19px;
  font-weight: 700;
}
.ic-brand { color: var(--accent); width: 22px; height: 22px; }
.count { font-size: 14px; font-weight: 500; color: var(--muted); }
.topbar-spacer { width: 44px; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 30;
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 15px;
}
.menu button:hover { background: var(--surface-2); }
.menu .ic { color: var(--muted); }

.searchbar {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 56px);
  z-index: 15;
  display: flex;
  gap: 8px;
  padding: 2px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--bg);
}
.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.search > .ic { position: absolute; left: 13px; color: var(--muted); pointer-events: none; }
.search input {
  padding-left: 42px;
  padding-right: 40px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search .icon-btn { position: absolute; right: 6px; }
.search-inline { margin-bottom: 12px; }
.search-inline input { padding-right: 13px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.chip .ic { width: 17px; height: 17px; }

/* ------------------------------------------------ lista */

.content {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
#view-main .content { padding-top: 0; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.item.open { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.item-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 16px;
  min-height: 64px;
}
.item-text {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  background: transparent;
  text-align: left;
}
.item-title {
  font-weight: 650;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-desc {
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-desc:empty { display: none; }
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  vertical-align: 1px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  height: 48px;
  min-width: 52px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  font-size: 14px;
  transition: background .15s, color .15s, transform .05s;
}
.copy-btn:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }
.copy-btn:active { transform: scale(.96); }
.copy-btn.done { background: var(--accent); color: var(--accent-text); }
.copy-btn .label { display: none; }

mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.item-detail {
  padding: 2px 16px 14px;
  border-top: 1px dashed var(--border);
  display: grid;
  gap: 12px;
}
.secret-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 4px 4px 4px 12px;
  background: var(--surface-2);
  border-radius: 10px;
}
.secret-value {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 14px;
  word-break: break-all;
  white-space: pre-wrap;
  padding: 8px 0;
  user-select: all;
  -webkit-user-select: all;
}
.secret-value.masked { letter-spacing: 2px; color: var(--muted); user-select: none; -webkit-user-select: none; }

.desc-lines { display: grid; gap: 6px; font-size: 15px; }
.desc-line { white-space: pre-wrap; word-break: break-word; }
.desc-pair {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 2px 12px;
  background: var(--surface-2);
  border-radius: 10px;
}
.desc-pair-text { flex: 1; min-width: 0; padding: 7px 0; word-break: break-word; }
.desc-pair-label { color: var(--muted); font-size: 13px; display: block; }
.desc-pair-value { font-weight: 600; }

.item-meta { font-size: 12.5px; color: var(--muted); }

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* gerenciar */
.list-manage .item-head { padding-right: 8px; }
.list-manage .icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

.tabs {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 56px);
  z-index: 15;
  display: flex;
  gap: 4px;
  margin: 0 auto;
  max-width: 760px;
  padding: 2px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--bg);
}
.tab {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.tab[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card > p.muted { margin: 0 0 14px; font-size: 14px; }

.sessions { list-style: none; padding: 0; margin: 4px 0 14px; display: grid; gap: 8px; }
.sessions li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
}
.sessions .muted { font-size: 13px; text-align: right; }
.sessions .current { color: var(--accent); font-weight: 700; }

/* ------------------------------------------------ FAB */

.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 15px;
  box-shadow: var(--shadow-lg);
}
.fab .ic { width: 24px; height: 24px; stroke-width: 2.4; }
.fab:active { transform: scale(.97); }

/* ------------------------------------------------ diálogos */

dialog {
  padding: 0;
  border: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgb(10 12 16 / 50%); backdrop-filter: blur(2px); }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 24px);
  margin: auto auto 0;
  border-radius: 20px 20px 0 0;
}
.sheet form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 4px 20px;
}
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet-body { padding: 8px 20px 4px; overflow-y: auto; }
.sheet-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.sheet-foot .btn { flex: 1; }
.secret-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -4px; }

.modal {
  width: calc(100% - 32px);
  max-width: 400px;
  border-radius: 18px;
}
.modal form { padding: 20px; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal p.muted { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { flex: 1; }

/* ------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 15px;
  box-shadow: var(--shadow-lg);
  width: max-content;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ------------------------------------------------ telas maiores */

@media (min-width: 640px) {
  .copy-btn .label { display: inline; }
  .copy-btn { padding: 0 16px; }
  .sheet { margin: auto; border-radius: 20px; }
  .sheet-foot { padding-bottom: 14px; }
  .sheet-foot .btn { flex: none; min-width: 120px; }
  .searchbar, .topbar { max-width: 760px; margin: 0 auto; }
  .topbar { padding-left: 16px; padding-right: 12px; }
}

@media (max-width: 380px) {
  .fab span { display: none; }
  .fab { width: 56px; padding: 0; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
