/* ═══════════════════════════════════════════════════════════
   CSS Custom Properties — Light Theme (default)
   ═══════════════════════════════════════════════════════════ */
:root {
  --accent:          #0078d4;
  --accent-dark:     #005a9e;
  --accent-light:    #deecf9;
  --bg:              #f0f2f5;
  --surface:         #ffffff;
  --surface2:        #f8f8f8;
  --surface3:        #f0f0f0;
  --text:            #323130;
  --text-secondary:  #605e5c;
  --text-disabled:   #a19f9d;
  --border:          #e1dfdd;
  --shadow-sm:       0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:       0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg:       0 8px 32px rgba(0,0,0,0.16);
  --header-bg:       var(--accent);
  --header-text:     #ffffff;
  --radius-sm:       4px;
  --radius-md:       8px;
  --radius-lg:       12px;
  --radius-xl:       16px;
  --transition:      0.18s ease;
  --icon-size:        64px;
  --tile-w:           88px;
  --tile-letter-size: 26px;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg:              #1a1a1a;
  --surface:         #252525;
  --surface2:        #2e2e2e;
  --surface3:        #3a3a3a;
  --text:            #f3f2f1;
  --text-secondary:  #c8c6c4;
  --text-disabled:   #797775;
  --border:          #3a3a3a;
  --shadow-sm:       0 1px 4px rgba(0,0,0,0.3);
  --shadow-md:       0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:       0 8px 32px rgba(0,0,0,0.5);
  --accent-light:    #003966;
  --header-bg:       #2e2e2e;
  --header-text:     #f3f2f1;
}

/* System preference dark mode */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg:              #1a1a1a;
    --surface:         #252525;
    --surface2:        #2e2e2e;
    --surface3:        #3a3a3a;
    --text:            #f3f2f1;
    --text-secondary:  #c8c6c4;
    --text-disabled:   #797775;
    --border:          #3a3a3a;
    --shadow-sm:       0 1px 4px rgba(0,0,0,0.3);
    --shadow-md:       0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg:       0 8px 32px rgba(0,0,0,0.5);
    --accent-light:    #003966;
    --header-bg:       #2e2e2e;
    --header-text:     #f3f2f1;
  }
}

/* ═══════════════════════════════════════════════════════════
   Reset & Base
   ═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════
   Login Screen
   ═══════════════════════════════════════════════════════════ */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
  z-index: 9999;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.login-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 8px;
}

.btn-ms {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: #ffffff;
  color: #323130;
  border: 1px solid #d2d0ce;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-sm);
}
.btn-ms:hover {
  background: #f8f8f8;
  box-shadow: var(--shadow-md);
}
.btn-ms:active { transform: scale(0.98); }

.config-warning {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #fde7e9;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: left;
  font-size: 12px;
  color: #7f1d1d;
  line-height: 1.5;
  margin-top: 4px;
}
.config-warning svg { flex-shrink: 0; margin-top: 1px; }
.config-warning code {
  background: rgba(0,0,0,0.08);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

.auth-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #fde7e9;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: left;
  font-size: 12px;
  color: #7f1d1d;
  line-height: 1.5;
  margin-top: 8px;
  word-break: break-word;
}
.auth-error svg { flex-shrink: 0; margin-top: 1px; }

.auth-redirect-info {
  background: #f0f4ff;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: left;
  font-size: 12px;
  color: #1e1b4b;
  line-height: 1.6;
  margin-top: 12px;
  word-break: break-all;
}
.auth-redirect-info code {
  display: block;
  background: rgba(0,0,0,0.06);
  padding: 4px 6px;
  border-radius: 3px;
  font-size: 11px;
  margin: 4px 0;
}
.auth-redirect-info small {
  color: #4338ca;
}

.pin-auth-diagnostic {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  line-height: 1.5;
  text-align: left;
  word-break: break-all;
}
.pin-auth-local {
  background: #fff8e1;
  border: 1px solid #ffe082;
  color: #5d4037;
}
.pin-auth-entra {
  background: #f0f4ff;
  border: 1px solid #c7d2fe;
  color: #1e1b4b;
}
.pin-diag-uri { opacity: 0.8; }
.pin-diag-uri code {
  background: rgba(0,0,0,0.06);
  padding: 1px 3px;
  border-radius: 3px;
}

.settings-auth-info {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 2px 0;
}
.settings-auth-info strong { color: var(--text); }
.settings-auth-info em { font-style: normal; color: var(--text-secondary); }

.pin-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(0,120,212,0.16), transparent 40%),
    rgba(8,18,32,0.58);
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 700;
}

.pin-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.pin-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.pin-brand .login-icon {
  margin-bottom: 0;
}

.pin-app-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.pin-input {
  width: min(100%, 220px);
  height: 56px;
  margin: 0 auto;
  text-align: center;
  letter-spacing: 0.35em;
  font-size: 30px;
  font-weight: 700;
}

.pin-error {
  margin: 0;
  font-size: 13px;
  color: #c50f1f;
}

.pin-actions {
  justify-content: flex-end;
}

.pin-actions .btn {
  min-width: 96px;
}

.pin-hint {
  margin: 0;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.pin-key {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 16px;
  min-height: 54px;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.pin-key:hover {
  background: var(--surface3);
  border-color: var(--accent);
}

.pin-key:active {
  transform: scale(0.97);
}

.pin-key-secondary {
  font-size: 14px;
  font-weight: 600;
}

.pin-key-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-size: 16px;
}

.pin-key-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

/* ═══════════════════════════════════════════════════════════
   App Shell
   ═══════════════════════════════════════════════════════════ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;       /* fallback */
  height: 100dvh;      /* dynamic viewport height — accounts for mobile browser chrome */
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px 10px 10px;
  min-height: 68px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0)),
    var(--header-bg);
  color: var(--header-text);
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(0,0,0,0.14);
  position: relative;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
  min-width: 0;
  flex: 1;
}

.header-app-icon {
  order: 2;
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 2px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.16);
}
.header-app-icon[src=""] { display: none; }

.header-app-name {
  order: 1;
  font-size: 26px;
  font-weight: 800;
  color: var(--header-text);
  letter-spacing: 0.005em;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  margin: 0 -4px;
  transition: background var(--transition), opacity var(--transition);
  text-align: left;
}
.header-app-name:hover { background: rgba(255,255,255,0.12); }

.header-meta {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 8px;
  min-height: 38px;
  margin-left: 2px;
}

.header-info-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  padding: 2px 3px;
  border-radius: 10px;
  cursor: grab;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}

.header-info-stack:hover {
  background: rgba(255,255,255,0.08);
}

.header-info-stack.dragging {
  opacity: 0.55;
}

.header-info-stack.drag-over {
  background: rgba(255,255,255,0.15);
  outline: 1px dashed rgba(255,255,255,0.4);
}

.header-meta-pill {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 18px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: rgba(255,255,255,0.82);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: none;
  position: relative;
  white-space: nowrap;
}

.header-meta-link {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  transition: color var(--transition), opacity var(--transition);
}

.header-meta-link:hover:not(:disabled) {
  color: rgba(255,255,255,0.96);
}

.header-meta-link:disabled {
  opacity: 0.72;
  cursor: default;
}

.header-meta-link.is-fallback::after {
  content: "manual";
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  background: rgba(255,255,255,0.15);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--header-text);
  text-transform: uppercase;
  flex-shrink: 0;
}

.user-display-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--header-text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--header-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.2); }
.icon-btn:active { background: rgba(255,255,255,0.3); }

/* Dark-surface icon buttons (used inside modals, flyout) */
.icon-btn.dark-surface { color: var(--text-secondary); }
.icon-btn.dark-surface:hover { background: var(--surface3); color: var(--text); }

/* ═══════════════════════════════════════════════════════════
   Main Content
   ═══════════════════════════════════════════════════════════ */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px calc(48px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  overscroll-behavior-y: contain;
}

.pull-refresh-indicator {
  --pull-progress: 0px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 0;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(-10px);
  transition: height 0.18s ease, opacity 0.18s ease, transform 0.18s ease;
}

body.is-pulling-refresh .pull-refresh-indicator,
.pull-refresh-indicator.ready,
.pull-refresh-indicator.active {
  height: calc(18px + var(--pull-progress));
  opacity: 1;
  transform: translateY(0);
}

.pull-refresh-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(0,120,212,0.16);
  transform: scale(0.9);
  transition: transform var(--transition), box-shadow var(--transition);
}

.pull-refresh-indicator.ready .pull-refresh-dot,
.pull-refresh-indicator.active .pull-refresh-dot {
  transform: scale(1.1);
}

/* ═══════════════════════════════════════════════════════════
   Groups
   ═══════════════════════════════════════════════════════════ */
.groups-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.group-section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.group-section.drag-over {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-md);
}

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  user-select: none;
}

.group-drag-handle {
  color: var(--text-disabled);
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 2px;
  transition: color var(--transition);
}
.group-header:hover .group-drag-handle { color: var(--text-secondary); }

.group-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--text-secondary);
}

.group-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}
.group-header:hover .group-actions { opacity: 1; }

.group-action-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.group-action-btn:hover { background: var(--surface3); color: var(--text); }
.group-action-btn.danger:hover { background: #fde7e9; color: #c50f1f; }
.group-action-btn:disabled { opacity: .3; cursor: default; pointer-events: none; }

.confirm-delete-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.confirm-delete-inline span { font-size: 12px; }
.confirm-yes {
  padding: 2px 8px;
  background: #c50f1f;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}
.confirm-no {
  padding: 2px 8px;
  background: var(--surface3);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
}

.btn-add-shortcut {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
  /* Override the fixed w/h from .group-action-btn so text fits */
  width: auto;
  height: auto;
  flex-shrink: 0;
}
.btn-add-shortcut:hover { background: var(--accent-dark); }

.group-shortcuts {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--tile-w, 88px));
  justify-content: center;
  gap: var(--tile-gap, 12px);
  padding: var(--tile-group-pad, 20px 16px);
  min-height: 60px;
  transition: background var(--transition);
}
.group-shortcuts.drag-target-empty {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
}

/* Hidden group state */
.group-section.group-hidden { display: none; }

/* ═══════════════════════════════════════════════════════════
   App Body Layout (sidebar + content)
   ═══════════════════════════════════════════════════════════ */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ═══════════════════════════════════════════════════════════
   Left Navigation Sidebar (overlay drawer)
   ═══════════════════════════════════════════════════════════ */
.app-nav {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 12px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
  z-index: 200;
  transform: translateX(0);
}
.app-nav.collapsed { transform: translateX(-100%); }

/* Nav backdrop — shown when drawer is open */
.nav-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 199;
  cursor: pointer;
}

/* Resize handle hidden in overlay mode */
.nav-resize-handle { display: none; }

.nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  white-space: nowrap;
}

.nav-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-settings-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.nav-settings-btn:hover {
  background: var(--surface3);
  color: var(--text);
}

.nav-group-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.nav-group-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px 9px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border-left: 3px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  user-select: none;
  touch-action: none;
}
.nav-group-item:hover  { background: var(--surface3); }
.nav-group-item.drag-over {
  background: var(--accent-light);
  border-left-color: var(--accent);
  color: var(--accent);
}
.nav-group-item.dragging { opacity: 0.4; }

.nav-drag-handle {
  color: var(--text-disabled);
  display: flex;
  align-items: center;
  cursor: grab;
  flex-shrink: 0;
  padding: 2px;
  transition: color var(--transition);
  touch-action: none;
}
.nav-group-item:hover .nav-drag-handle { color: var(--text-secondary); }

.nav-group-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-toggle-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  padding: 4px;
  margin-right: 6px;
  cursor: pointer;
  color: var(--header-text);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.nav-toggle-btn:hover { background: rgba(255,255,255,0.15); }

.nav-group-item.group-is-hidden { opacity: 0.6; }

.nav-hide-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  padding: 0;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}
.nav-group-item:hover .nav-hide-btn          { opacity: 1; }
.nav-group-item.group-is-hidden .nav-hide-btn { opacity: 0.8; } /* always show when hidden */
.nav-hide-btn:hover { background: var(--surface3); }

/* Show-hidden toggle button in nav header */
.nav-show-hidden-btn.active {
  color: var(--accent);
  background: var(--accent-light);
}

/* ═══════════════════════════════════════════════════════════
   Checkbox
   ═══════════════════════════════════════════════════════════ */
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}
.checkbox-input {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
  margin-top: 2px;
}
.checkbox-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

/* ═══════════════════════════════════════════════════════════
   Shortcut Tiles
   ═══════════════════════════════════════════════════════════ */
.shortcut-tile {
  width: calc(var(--tile-w) - var(--tile-width-trim, 0px));
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--tile-inner-gap, 8px);
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: var(--tile-pad, 8px 6px);
  transition: background var(--transition), transform var(--transition);
  position: relative;
  user-select: none;
  -webkit-user-drag: element;
}
.shortcut-tile:hover { background: var(--surface3); }
.shortcut-tile:active { transform: scale(0.96); }
.shortcut-tile.dragging { opacity: 0.4; }
.shortcut-tile.drag-over-left { box-shadow: -2px 0 0 0 var(--accent); }
.shortcut-tile.drag-over-right { box-shadow: 2px 0 0 0 var(--accent); }

.shortcut-icon {
  width: var(--icon-size);
  height: var(--icon-size);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  flex-shrink: 0;
  position: relative;
  transition: box-shadow var(--transition);
}
.shortcut-tile:hover .shortcut-icon { box-shadow: 0 4px 14px rgba(0,0,0,0.25); }

.shortcut-icon img {
  width: var(--tile-icon-fill, 84%);
  height: var(--tile-icon-fill, 84%);
  object-fit: contain;
  display: block;
  border-radius: var(--radius-md);
}

.shortcut-icon .letter-fallback {
  font-size: var(--tile-letter-size);
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  text-transform: uppercase;
  line-height: 1;
}

.shortcut-icon .text-icon,
.shortcut-icon-preview .text-icon,
.search-result-icon .text-icon {
  font-weight: 700;
  text-transform: uppercase;
  line-height: 1;
}

.shortcut-icon .text-icon {
  font-size: calc(var(--icon-size) * 0.3);
}

.shortcut-name {
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  width: calc(var(--tile-w) - var(--tile-width-trim, 0px) - 4px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  line-height: 1.3;
}

/* Tile action overlay */
.tile-actions {
  position: absolute;
  top: 4px;
  right: 2px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 10;
}
.shortcut-tile:hover .tile-actions { opacity: 1; }

.tile-action-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition);
}
.tile-action-btn:hover { transform: scale(1.15); }
.tile-refresh-btn { background: #107c10; color: white; }
.tile-edit-btn { background: #0078d4; color: white; }
.tile-delete-btn { background: #c50f1f; color: white; }

/* ═══════════════════════════════════════════════════════════
   Add Group Row
   ═══════════════════════════════════════════════════════════ */
.add-group-row {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.btn-add-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-add-group:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════
   Settings Flyout
   ═══════════════════════════════════════════════════════════ */
.flyout-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 500;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}

.settings-flyout {
  position: fixed;
  top: 0;
  right: -420px;
  width: 380px;
  height: 100vh;       /* fallback */
  height: 100dvh;      /* accounts for mobile browser chrome */
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 600;
  display: flex;
  flex-direction: column;
  transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.settings-flyout.open { right: 0; }

.flyout-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.flyout-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.flyout-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.flyout-footer {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }

.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* ═══════════════════════════════════════════════════════════
   Modals
   ═══════════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 700;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 800;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.18s ease;
}

@keyframes modalIn {
  from { transform: translate(-50%, -50%) scale(0.95); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1);    opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   Shortcut Preview (inside modal)
   ═══════════════════════════════════════════════════════════ */
.shortcut-preview-row {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.shortcut-preview-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.shortcut-icon-preview {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  background: #0078d4;
}
.shortcut-icon-preview img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}
.shortcut-icon-preview .letter-fallback {
  font-size: 30px;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

.shortcut-icon-preview .text-icon {
  font-size: 28px;
}

.shortcut-preview-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 88px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   Forms
   ═══════════════════════════════════════════════════════════ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.label-hint {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 12px;
}

.required { color: #c50f1f; }

.form-input, .form-select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.form-input::placeholder { color: var(--text-disabled); }

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23605e5c' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

/* Segmented control */
.segmented-control {
  display: flex;
  background: var(--surface3);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: 5px 8px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Radio group */
.radio-group {
  display: flex;
  gap: 20px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.radio-label input[type="radio"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════
   Color Row (swatches + custom picker)
   ═══════════════════════════════════════════════════════════ */
.color-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
  position: relative;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.swatch-light { box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.color-swatch.swatch-none {
  background: var(--surface2);
  box-shadow: inset 0 0 0 1px var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.color-swatch.swatch-transparent {
  background: repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0 0 / 10px 10px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}
.color-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}

.color-custom {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  box-shadow: 0 0 0 1.5px var(--border);
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: transform var(--transition);
}
.color-custom:hover { transform: scale(1.15); }
.color-custom input[type="color"] {
  position: absolute;
  inset: -4px;
  opacity: 0;
  cursor: pointer;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
}

/* ═══════════════════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  border: 1px solid transparent;
  line-height: 1;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface3); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-secondary:hover { background: var(--surface3); border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: #c50f1f;
  color: #fff;
  border-color: #c50f1f;
}
.btn-danger:hover { background: #a80000; border-color: #a80000; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

@media (max-width: 860px) {
  .app-header {
    min-height: 58px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .header-app-name {
    font-size: 21px;
  }

  .header-meta {
    gap: 8px;
  }

  .header-info-stack {
    min-width: 0;
    padding: 2px 4px;
  }

  .user-badge {
    display: none;
  }

  .header-meta-pill {
    font-size: 10px;
    padding: 0;
  }
}

/* ─── Import Modal ─────────────────────────────────────── */
.modal-wide { max-width: 560px; }

.import-instructions {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.import-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  color: var(--text-secondary);
  text-align: center;
  user-select: none;
}
.import-dropzone:hover,
.import-dropzone.drag-active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}
.dropzone-label { font-size: 14px; font-weight: 500; }
.dropzone-link  { color: var(--accent); text-decoration: underline; }
.dropzone-hint  { font-size: 12px; color: var(--text-disabled); }

.import-preview { margin-top: 20px; }
.import-preview-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.import-file-name  { font-size: 13px; font-weight: 600; color: var(--text); }
.import-count-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 99px;
}

.import-options { margin-bottom: 16px; }

.import-preview-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.import-folder-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.import-folder-count {
  font-size: 11px;
  font-weight: 400;
  background: var(--surface3);
  color: var(--text-secondary);
  padding: 1px 6px;
  border-radius: 99px;
  text-transform: none;
  letter-spacing: 0;
}
.import-folder-links {
  list-style: none;
  margin: 0;
  padding: 0 0 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.import-folder-links li {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.import-more { color: var(--text-disabled); font-style: italic; }
.import-truncate-note {
  font-size: 12px;
  color: var(--text-disabled);
  text-align: center;
  margin: 4px 0 0;
}

/* ═══════════════════════════════════════════════════════════
   Search Popup
   ═══════════════════════════════════════════════════════════ */
.search-popup {
  position: fixed;
  width: 340px;
  max-height: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  z-index: 400;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: dropdownIn 0.15s ease;
}
@keyframes dropdownIn {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.search-popup-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 6px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.search-icon-inline { color: var(--text-secondary); flex-shrink: 0; }

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  padding: 7px 0;
  outline: none;
  font-family: inherit;
}
.search-input::placeholder { color: var(--text-disabled); }

.search-clear-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  line-height: 1;
}
.search-clear-btn:hover { background: var(--surface3); color: var(--text); }

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 48px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background var(--transition);
}
.search-result-item:hover { background: var(--surface3); }

.search-result-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.search-result-icon img { width: 18px; height: 18px; object-fit: contain; }

.search-result-info { flex: 1; overflow: hidden; }
.search-result-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-group {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-empty, .search-no-results {
  padding: 20px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════
   Touch devices: long-press to reveal tile actions
   ═══════════════════════════════════════════════════════════ */
@media (hover: none) {
  /* Suppress hover-triggered tile actions on touch devices */
  .shortcut-tile:hover .tile-actions { opacity: 0; }
  /* Show tile actions only when long-press activates them */
  .shortcut-tile.show-actions .tile-actions { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════
   Scrollbar styling
   ═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-disabled); }
