/* ===================================================================
   名片箱 / Name Card Box - Theme CSS
   Purple primary palette + minimal hand-rolled components
   =================================================================== */

:root {
    --purple-50:  #F5F3FF;
    --purple-100: #EDE9FE;
    --purple-200: #DDD6FE;
    --purple-400: #A78BFA;
    --purple-500: #8B5CF6;
    --purple-600: #7C3AED;
    --purple-700: #6D28D9;
    --purple-800: #5B21B6;
    --gray-50:  #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    --green-500: #10B981;
    --red-500:   #EF4444;
    --red-600:   #DC2626;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow:    0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius:    0.5rem;
    --radius-lg: 0.75rem;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Helvetica Neue", Arial, sans-serif;

    /* Semantic aliases (used by templates + components) */
    --primary:       #7C3AED;  /* purple-600 */
    --primary-hover: #5B21B6;  /* purple-800 */
    --primary-light: #EDE9FE;  /* purple-100 */
    --bg:            #F5F3FF;  /* purple-50 */
    --bg-card:       #FFFFFF;
    --text:          #1F2937;  /* gray-800 */
    --text-muted:    #6B7280;  /* gray-500 */
    --border:        #E5E7EB;  /* gray-200 */
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    color: var(--gray-800);
    background: var(--purple-50);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--purple-600); text-decoration: none; }
a:hover { color: var(--purple-800); text-decoration: underline; }

/* ============== Top Nav ============== */

.topnav {
    background: linear-gradient(135deg, var(--purple-600), var(--purple-800));
    color: white;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topnav-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    height: 64px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    font-weight: 700;
    font-size: 1.125rem;
    text-decoration: none;
    flex-shrink: 0;
}
.brand:hover { color: white; text-decoration: none; }
.brand-icon { font-size: 1.5rem; }

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    align-items: center;
    flex-wrap: nowrap;
}
.nav-links a {
    color: rgba(255,255,255,0.85);
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius);
    transition: all 0.15s;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    text-decoration: none;
}
.nav-links a:hover {
    color: white;
    background: rgba(255,255,255,0.15);
    text-decoration: none;
}
.nav-links .nav-icon {
    font-size: 1.05rem;
    line-height: 1;
}
.nav-links .nav-text {
    line-height: 1;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.lang-toggle {
    display: inline-flex;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius);
    overflow: hidden;
}
.lang-toggle a {
    color: rgba(255,255,255,0.75);
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
    font-weight: 600;
}
.lang-toggle a.active {
    background: white;
    color: var(--purple-700);
}
.lang-toggle a:hover { color: white; text-decoration: none; }
.lang-toggle a.active:hover { color: var(--purple-700); }

.user-badge {
    color: rgba(255,255,255,0.9);
    font-size: 0.875rem;
}
.user-badge .admin-tag {
    display: inline-block;
    background: var(--purple-400);
    color: white;
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    margin-left: 0.375rem;
    vertical-align: middle;
}

.logout-btn {
    color: white;
    background: rgba(255,255,255,0.15);
    padding: 0.375rem 0.875rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: all 0.15s;
}
.logout-btn:hover {
    background: rgba(255,255,255,0.25);
    text-decoration: none;
}

/* Hamburger button: hidden by default (desktop) */
.mobile-menu-toggle {
    display: none;
    /* shown via @media (max-width: 768px) */
}

/* Mobile drawer: hidden by default (desktop) */
.mobile-menu-drawer {
    display: none;
}

/* ============== Layout ============== */

.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

.page-header {
    margin-bottom: 2rem;
}
.page-header h1 {
    margin: 0;
    font-size: 1.875rem;
    color: var(--gray-900);
}
.page-header .subtitle {
    margin: 0.5rem 0 0;
    color: var(--gray-500);
    font-size: 0.95rem;
}

.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--gray-400);
    font-size: 0.8125rem;
    border-top: 1px solid var(--purple-100);
    background: white;
    display: flex;
    justify-content: center;
    gap: 0.625rem;
}

/* ============== Auth (login / setup) ============== */

.auth-container {
    min-height: calc(100vh - 64px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    margin-top: -2rem;
}

.auth-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 26rem;
    border-top: 4px solid var(--purple-600);
}

.auth-header {
    text-align: center;
    margin-bottom: 1.75rem;
}
.auth-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}
.auth-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--purple-700);
}
.auth-tagline {
    margin: 0.375rem 0 0;
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* ============== Forms ============== */

.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--purple-500);
    box-shadow: 0 0 0 3px var(--purple-100);
}
.form-group textarea { min-height: 6rem; resize: vertical; }

.auth-form { margin-top: 1rem; }

/* ============== Buttons ============== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.625rem 1.25rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary {
    background: var(--purple-600);
    color: white;
}
.btn-primary:hover {
    background: var(--purple-700);
    color: white;
    text-decoration: none;
}
.btn-block { width: 100%; }
.btn-secondary {
    background: white;
    color: var(--purple-700);
    border-color: var(--purple-200);
}
.btn-secondary:hover {
    background: var(--purple-50);
    color: var(--purple-800);
    text-decoration: none;
}
.btn-danger {
    background: var(--red-500);
    color: white;
}
.btn-danger:hover {
    background: var(--red-600);
    color: white;
    text-decoration: none;
}

/* ============== Alerts ============== */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.alert-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}
.alert-success {
    background: #F0FDF4;
    color: #166534;
    border: 1px solid #BBF7D0;
}

/* ============== Language picker (login page) ============== */

.lang-picker {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-100);
    color: var(--gray-400);
    font-size: 0.875rem;
}
.lang-picker a {
    color: var(--gray-500);
    padding: 0 0.5rem;
}
.lang-picker a.active {
    color: var(--purple-700);
    font-weight: 600;
}
.lang-picker a:hover { color: var(--purple-600); }

/* ============== Dashboard ============== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--purple-400);
    display: flex;
    align-items: center;
    gap: 1rem;
}
.stat-icon {
    font-size: 2rem;
    opacity: 0.85;
}
.stat-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}
.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.action-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    color: var(--gray-800);
    transition: all 0.15s;
    border: 1px solid var(--gray-100);
}
.action-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: var(--purple-700);
    text-decoration: none;
    border-color: var(--purple-200);
}
.action-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}
.action-card h3 {
    margin: 0 0 0.375rem;
    font-size: 1.0625rem;
    color: var(--purple-700);
}
.action-card p {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.875rem;
}

.dev-notice {
    background: var(--purple-100);
    color: var(--purple-800);
    border: 1px solid var(--purple-200);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ============== Tables ============== */

.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
}
th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}
tr:hover { background: var(--purple-50); }

/* ============== Responsive (handled in comprehensive block below) ============== */

/* ============== Parse Badge ============== */
.parse-badge {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    background: var(--gray-50);
    border: 1px solid var(--gray-100);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.badge-ai, .badge-rule, .badge-fallback, .badge-engine, .badge-time, .badge-vision {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 12px;
    white-space: nowrap;
}
.badge-ai {
    background: linear-gradient(135deg, #7C3AED 0%, #5B21B6 100%);
    color: white;
    font-weight: 600;
}
.badge-vision {
    background: linear-gradient(135deg, #EC4899 0%, #DB2777 100%);
    color: white;
    font-weight: 600;
}
.badge-rule {
    background: var(--purple-50, #F5F3FF);
    color: var(--purple-700, #5B21B6);
    border: 1px solid var(--purple-100, #EDE9FE);
}
.badge-fallback {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #FDE68A;
}
.badge-engine {
    background: var(--gray-100, #F3F4F6);
    color: var(--gray-700, #374151);
}
.badge-time {
    background: transparent;
    color: var(--gray-500, #6B7280);
    font-family: monospace;
}

/* ============== Settings page ============== */
.settings-form {
    max-width: 760px;
    margin: 0 auto;
}
.settings-group {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 20px;
}
.settings-group legend {
    font-size: 16px;
    font-weight: 600;
    color: #5B21B6;
    padding: 0 8px;
}
.form-row {
    margin-bottom: 18px;
}
.form-row:last-child {
    margin-bottom: 0;
}
.form-row label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #374151;
    font-size: 14px;
}
.form-row input[type="text"],
.form-row input[type="url"],
.form-row input[type="password"],
.form-row input[type="number"],
.form-row select {
    display: block;          /* force block to guarantee 100% width on all browsers (Android WebView fix) */
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
    -webkit-appearance: none;   /* strip iOS/Android native form chrome that can shrink the box */
    -moz-appearance: none;
    appearance: none;
}
.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: #7C3AED;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}
.form-row-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-help {
    display: block;
    color: #6B7280;
    font-size: 12px;
    margin-top: 4px;
}
.form-toggle {
    display: flex !important;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500 !important;
}
.form-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #7C3AED;
    cursor: pointer;
}
.form-actions {
    max-width: 760px;
    margin: 24px auto 0;
    text-align: right;
}
.alert {
    max-width: 760px;
    margin: 0 auto 20px;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 14px;
}
.alert-success {
    background: #D1FAE5;
    color: #065F46;
    border: 1px solid #6EE7B7;
}
.btn-lg {
    padding: 12px 28px;
    font-size: 15px;
}

/* ============== Card detail ============== */
.card-detail-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 28px;
    align-items: start;
}
.card-detail-header {
    border-bottom: 1px solid #E5E7EB;
    padding-bottom: 16px;
    margin-bottom: 20px;
}
.card-detail-name {
    font-size: 28px;
    margin: 0 0 4px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.card-detail-title {
    font-size: 16px;
    color: var(--text-muted);
    margin: 2px 0;
}
.card-detail-company {
    font-size: 18px;
    color: var(--text);
    font-weight: 600;
    margin: 4px 0 0;
}
.card-detail-fields {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 0;
    padding: 0;
}
.field-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.field-label {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    min-width: 90px;
    flex-shrink: 0;
    padding-top: 2px;
}
.field-value {
    flex: 1;
    min-width: 0;        /* allow content to shrink so wrap works */
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}
.field-value.multi-line {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
}
.field-value a {
    color: var(--primary);
    text-decoration: none;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.field-value a:hover {
    text-decoration: underline;
}
.phone-line, .email-line, .web-line {
    line-height: 1.6;
}
.card-detail-actions {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 12px;
}
.card-detail-aside {
    position: sticky;
    top: 80px;
}
.card-image-frame {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card-image-frame img {
    width: 100%;
    height: auto;
    max-height: 320px;
    aspect-ratio: 1.75 / 1;  /* standard business card ratio (wider than tall) */
    object-fit: contain;     /* prevent stretch on iOS/iPad wide screens */
    border-radius: 6px;
    display: block;
    background: #F3F4F6;     /* letterbox color if image ratio differs */
}
.card-meta {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    padding: 12px 16px;
    margin: 0;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.meta-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
}
.meta-label {
    color: #6B7280;
    font-size: 12px;
    flex-shrink: 0;
}
.meta-value {
    color: #374151;
    font-size: 13px;
    text-align: right;
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
}
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
}
.badge-vision { background: #DBEAFE; color: #1E40AF; }
.badge-ai { background: #FEF3C7; color: #92400E; }
.badge-rule { background: #E5E7EB; color: #374151; }

.inline-form {
    display: inline;
}

/* ============== Card edit ============== */
.card-edit-form {
    max-width: 760px;
    margin: 0 auto;
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    padding: 24px 28px;
}
.card-edit-form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
}
.card-edit-form textarea:focus {
    outline: none;
    border-color: #7C3AED;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}
.form-help-inline {
    color: #6B7280;
    font-weight: 400;
    font-size: 12px;
}
.page-title {
    margin: 0 16px;
    font-size: 20px;
    color: #111827;
    display: inline-block;
    vertical-align: middle;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

/* ============== Error page ============== */
.error-page {
    text-align: center;
    padding: 60px 20px;
}
.error-code {
    font-size: 96px;
    color: #7C3AED;
    margin: 0 0 16px;
    font-weight: 700;
}
.error-message {
    color: #6B7280;
    font-size: 18px;
    margin: 0 0 32px;
}

/* ============== Buttons ============== */
.btn-danger {
    background: #DC2626;
    color: white;
    border: 1px solid #DC2626;
}
.btn-danger:hover {
    background: #B91C1C;
    border-color: #B91C1C;
}

/* ============== Users management page ============== */
.user-create-form {
    margin-bottom: 24px;
}
.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    color: var(--text);
}
.users-table th,
.users-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.users-table th {
    background: var(--purple-50);
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.users-table tbody tr:hover {
    background: var(--purple-50);
}
[data-theme="dark"] .users-table th {
    background: rgba(124, 58, 237, 0.15);
    color: #C4B5FD;
}
[data-theme="dark"] .users-table tbody tr:hover {
    background: rgba(124, 58, 237, 0.08);
}
[data-theme="dark"] .admin-tag {
    background: rgba(146, 64, 14, 0.25);
    color: #FCD34D;
}
.admin-tag {
    display: inline-block;
    background: #FEF3C7;
    color: #92400E;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
}
.form-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-weight: 500;
}
.form-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--purple-600);
}

/* ============== Mobile responsive (≤ 768px) ============== */
@media (max-width: 768px) {
    /* Top nav: collapse to essentials */
    .topnav-inner { gap: 0; padding: 0; }
    .nav-links { display: none; }
    .user-badge { display: none; }
    .theme-toggle { display: none; }   /* moved to mobile drawer */
    .lang-toggle { display: none; }    /* moved to mobile drawer */
    .logout-btn { display: none; }     /* moved to mobile drawer */
    .brand-name { display: none; }     /* icon only on mobile */

    /* Push hamburger to far right (only nav item visible in topbar) */
    .nav-right {
        margin-left: auto;
        padding: 12px 12px 12px 0;
        gap: 0;
    }

    /* Hamburger button: visible on mobile only */
    .mobile-menu-toggle {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        padding: 10px;
        background: transparent;
        border: none;
        border-radius: var(--radius);
        cursor: pointer;
        align-items: center;
        transition: background 0.15s;
    }
    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:focus,
    .mobile-menu-toggle:active {
        background: rgba(255, 255, 255, 0.18);
        outline: none;
    }
    .hamburger-line {
        display: block;
        width: 24px;
        height: 3px;
        background: white;
        border-radius: 2px;
        transition: transform 0.2s, opacity 0.2s;
        flex-shrink: 0;
    }
    .mobile-menu-toggle.open .hamburger-line:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }
    .mobile-menu-toggle.open .hamburger-line:nth-child(2) {
        opacity: 0;
    }
    .mobile-menu-toggle.open .hamburger-line:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }

    /* Mobile drawer */
    .mobile-menu-drawer {
        display: flex;
        flex-direction: column;
        background: linear-gradient(180deg, var(--purple-700), var(--purple-900));
        box-shadow: var(--shadow-md);
        padding: 0.5rem 0;
        animation: slideDown 0.2s ease-out;
    }
    .mobile-menu-drawer[hidden] { display: none; }
    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-8px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .mobile-menu-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.875rem 1.25rem;
        /* Force white text — do NOT inherit from .nav-links a which is purple-tinted */
        color: #FFFFFF !important;
        text-decoration: none;
        font-size: 1rem;
        font-weight: 500;
        border-left: 3px solid transparent;
        transition: background 0.15s, border-color 0.15s;
    }
    .mobile-menu-link:hover,
    .mobile-menu-link:focus,
    .mobile-menu-link:active {
        background: rgba(255, 255, 255, 0.15);
        border-left-color: white;
        color: #FFFFFF !important;
        text-decoration: none;
        outline: none;
    }
    .mobile-menu-link:visited {
        color: #FFFFFF !important;
    }
    .mobile-menu-link .nav-icon {
        font-size: 1.25rem;
        width: 28px;
        text-align: center;
    }
    .mobile-menu-link-danger {
        color: #FECACA !important;
    }
    .mobile-menu-link-danger:hover,
    .mobile-menu-link-danger:focus {
        background: rgba(220, 38, 38, 0.3);
        color: #FFFFFF !important;
    }
    .mobile-menu-divider {
        height: 1px;
        background: rgba(255, 255, 255, 0.15);
        margin: 0.5rem 1.25rem;
    }

    /* Settings section inside drawer (lang + theme + logout) */
    .mobile-menu-settings {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1.25rem 0.5rem;
        margin-top: 0.25rem;
    }
    .mobile-menu-row {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }
    .mobile-menu-row .nav-icon {
        font-size: 1.1rem;
        width: 28px;
        text-align: center;
    }
    .mobile-menu-row-label {
        color: rgba(255, 255, 255, 0.75);
        font-size: 0.875rem;
        flex: 1;
    }
    .mobile-menu-lang {
        display: inline-flex;
        background: rgba(255, 255, 255, 0.15);
        border-radius: var(--radius);
        overflow: hidden;
    }
    .mobile-menu-lang a {
        color: rgba(255, 255, 255, 0.85);
        padding: 0.25rem 0.75rem;
        font-size: 0.8125rem;
        font-weight: 600;
        text-decoration: none;
    }
    .mobile-menu-lang a.active {
        background: white;
        color: var(--purple-700) !important;
    }
    .mobile-menu-theme-btn {
        background: rgba(255, 255, 255, 0.15);
        border: none;
        color: white;
        padding: 0.375rem 0.75rem;
        border-radius: var(--radius);
        cursor: pointer;
        font-size: 0.875rem;
    }
    .mobile-menu-theme-btn:hover {
        background: rgba(255, 255, 255, 0.25);
    }

    /* Prevent body scroll when drawer open */
    body.mobile-menu-open {
        overflow: hidden;
    }

    /* Main content padding */
    .main-content { padding: 0.75rem; }

    /* Page header stacks vertically */
    .page-header {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 16px;
    }
    .page-header h1 { font-size: 18px; }
    .page-title { margin: 0; font-size: 18px; }

    /* Auth pages */
    .auth-card { padding: 1.5rem 1rem; }
    .auth-header h1 { font-size: 22px; }

    /* Action grid: single column */
    .action-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .action-card { padding: 16px; }
    .action-icon { font-size: 32px; }

    /* Stat grid: 2 cols */
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 22px; }

    /* Card detail: stack */
    .card-detail-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .card-detail-aside { order: -1; }  /* image on top */
    .card-detail-name { font-size: 22px; }
    .card-image-frame img { max-height: 200px; }

    /* Card list items */
    .card-list-item { padding: 12px; }
    .card-list-name { font-size: 15px; }
    .card-list-meta { font-size: 12px; }
    .card-list-contact { font-size: 13px; word-break: break-all; }

    /* Search bar: stack input & button */
    .search-bar {
        flex-wrap: wrap;
    }
    .search-bar input[type="text"] {
        flex: 1 1 100%;
        margin-bottom: 8px;
    }
    .search-bar button { width: 100%; }

    /* Settings form: stack columns */
    .form-row-2col {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .form-row input[type="text"],
    .form-row input[type="url"],
    .form-row input[type="password"],
    .form-row input[type="number"],
    .form-row select {
        font-size: 16px;  /* prevent iOS zoom on focus */
    }

    /* Buttons: easier to tap */
    .btn { padding: 8px 14px; font-size: 14px; }
    .btn-lg { padding: 12px 18px; font-size: 16px; }

    /* Card edit form fields: bigger tap targets */
    .card-edit-form input,
    .card-edit-form textarea {
        font-size: 16px;
    }

    /* Table on small screens: horizontal scroll */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .users-table { min-width: 640px; }
    .users-table th, .users-table td { padding: 8px 6px; font-size: 13px; }

    /* Footer: hide tagline */
    .footer { font-size: 11px; }
    .footer span:nth-child(3) { display: none; }

    /* ============ Scan page mobile ============ */
    .scan-layout { grid-template-columns: 1fr; gap: 16px; }
    .drop-zone { padding: 32px 16px; min-height: 220px; }
    .drop-zone-icon { font-size: 42px; }
    .drop-zone-text { font-size: 16px; }
    .preview-container img { max-height: 200px; }
    .btn-row { flex-direction: column; }
    .btn-row .btn { width: 100%; }
    .engine-select { max-width: 100%; }

    /* ============ Card detail mobile (override grid) ============ */
    .card-detail-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .card-detail-aside { order: -1; position: static; }   /* image on top, no sticky */
    .card-detail-name { font-size: 20px; line-height: 1.2; word-break: break-word; }
    .card-detail-title { font-size: 14px; }
    .card-detail-company { font-size: 14px; }
    .field-row {
        flex-direction: column;       /* label stacks above value on narrow screens */
        gap: 4px;
    }
    .field-label {
        min-width: 0;
        font-size: 12px;
    }
    .field-value {
        font-size: 14px;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .card-image-frame img { max-height: 220px; }
    .card-detail-actions {
        flex-direction: column;       /* Edit + Delete stack */
        gap: 8px;
    }
    .card-detail-actions .btn { width: 100%; }
    .card-meta { padding: 12px; font-size: 12px; }

    /* ============ Dashboard mobile ============ */
    .dashboard-header h1 { font-size: 22px; }
    .action-card { padding: 16px 14px; }
    .action-card h3 { font-size: 16px; }
    .action-card p { font-size: 13px; }
}

/* ============== AI Test button result ============== */
.form-row-test {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-top: 8px;
}
.ai-test-result {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.ai-test-result code {
    background: rgba(0,0,0,0.06);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
}
.ai-test-result small {
    display: block;
    margin-top: 4px;
    opacity: 0.85;
}
.ai-test-success {
    background: #DCFCE7;
    color: #166534;
    border-left: 4px solid #16A34A;
}
.ai-test-error {
    background: #FEE2E2;
    color: #991B1B;
    border-left: 4px solid #DC2626;
}

/* ============== Alert with inline action button ============== */
.alert-with-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.alert-with-action .btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 6px;
}
@media (max-width: 768px) {
    .alert-with-action {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    .alert-with-action .btn-sm {
        width: 100%;
    }
}

/* ============== Page header actions + dropdown ============== */
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-toggle {
    cursor: pointer;
}
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;             /* NO gap (was calc(100% + 4px) — owner hit
                              2026-06-26 16:36 GMT+8 where mouse briefly
                              left the toggle while traversing the 4px gap,
                              triggering mouseleave and collapsing the menu
                              before the mouse could reach an item). */
    margin-top: 0;         /* explicit no-gap, even with future resets */
    padding-top: 4px;      /* visual breathing room without breaking hover */
    min-width: 180px;
    background: white;
    border: 1px solid var(--gray-200, #E5E7EB);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 100;
    overflow: hidden;
}
.dropdown.open .dropdown-menu {
    display: block;
}
.dropdown-item {
    display: block;
    padding: 10px 14px;
    color: var(--gray-700, #374151);
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100, #F3F4F6);
    transition: background 0.15s;
}
.dropdown-item:last-child {
    border-bottom: none;
}
.dropdown-item:hover {
    background: var(--gray-50, #F9FAFB);
    color: var(--primary, #7C3AED);
}
@media (max-width: 768px) {
    .page-header-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }
    .page-header-actions .btn,
    .page-header-actions .dropdown {
        width: 100%;
    }
    .dropdown-menu {
        right: auto;
        left: 0;
        width: 100%;
    }
}

/* ============== PWA install banner ============== */
.pwa-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    z-index: 9999;
    background: white;
    border: 1.5px solid var(--primary, #7C3AED);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.25);
    padding: 12px 16px;
    max-width: 480px;
    margin: 0 auto;
    animation: pwaSlideUp 0.3s ease-out;
}
@keyframes pwaSlideUp {
    from { transform: translateY(120%); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.pwa-banner-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.pwa-banner-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.pwa-banner-text strong {
    font-size: 14px;
    color: var(--text, #1F2937);
}
.pwa-banner-sub {
    font-size: 12px;
    color: var(--text-muted, #6B7280);
}
.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.pwa-banner .btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 6px;
}
@media (max-width: 768px) {
    .pwa-banner {
        bottom: 8px;
        left: 8px;
        right: 8px;
        padding: 10px 12px;
    }
    .pwa-banner-content {
        flex-wrap: wrap;
    }
    .pwa-banner-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ============== Card share buttons ============== */
.card-detail-share {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border, #E5E7EB);
    flex-wrap: wrap;
}

/* ============== Enhanced image badge ============== */
.card-image-frame {
    position: relative;
}
.card-image-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: linear-gradient(135deg, #7C3AED, #5B21B6);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
    pointer-events: none;
}

/* ============== Toast ============== */
.toast-msg {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1F2937;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    max-width: 90vw;
    text-align: center;
}
.toast-msg.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast-msg.toast-error {
    background: #DC2626;
}

/* ============== QR Modal ============== */
.qr-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.qr-modal {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.qr-modal h3 { margin: 0 0 8px 0; font-size: 18px; }
.qr-modal p { color: #6B7280; font-size: 13px; margin: 0 0 16px 0; }
.qr-modal img {
    max-width: 280px;
    width: 100%;
    height: auto;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 8px;
    background: white;
}
.qr-modal .qr-close {
    margin-top: 16px;
    width: 100%;
}
@media (max-width: 768px) {
    .qr-modal { padding: 20px 16px; }
    .toast-msg { font-size: 13px; padding: 10px 16px; }
}

/* ============== Share dialog (send-via tiles) ============== */
.share-dialog {
    max-width: 440px;
}
.share-targets {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 12px 0 16px 0;
}
.share-tile {
    display: block;
    text-align: center;
    padding: 14px 8px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    color: white;
    transition: transform 0.1s, box-shadow 0.1s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.share-tile:active { transform: scale(0.97); }
.share-wa   { background: #25D366; }   /* WhatsApp green */
.share-tg   { background: #0088CC; }   /* Telegram blue */
.share-mail { background: #EA4335; }   /* Gmail red */
.share-sms  { background: #5856D6; }   /* iOS purple */
.share-details {
    margin: 10px 0;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 8px 12px;
    background: #FAFAFA;
}
.share-details summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    color: #4B5563;
    padding: 4px 0;
    list-style: none;
}
.share-details summary::-webkit-details-marker { display: none; }
.share-details summary::before { content: '▶ '; font-size: 10px; }
.share-details[open] summary::before { content: '▼ '; }
.share-textarea {
    width: 100%;
    min-height: 80px;
    max-height: 200px;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    background: white;
    resize: vertical;
    box-sizing: border-box;
}
.share-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}
@media (max-width: 480px) {
    .share-targets { grid-template-columns: 1fr 1fr; }
    .share-tile { padding: 12px 6px; font-size: 13px; }
}

/* ============== Backups list ============== */
.backups-list {
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 12px;
    max-height: 280px;
    overflow-y: auto;
}
.backup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid #E5E7EB;
    font-size: 13px;
}
.backup-item:last-child { border-bottom: none; }
.backup-item-info { flex: 1; min-width: 0; }
.backup-item-name { font-family: ui-monospace, monospace; font-size: 12px; color: #374151; word-break: break-all; }
.backup-item-meta { color: #6B7280; font-size: 11px; margin-top: 2px; }
.backup-item-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: 8px; }
.backup-item-actions .btn { padding: 4px 10px; font-size: 12px; }
.backup-status {
    display: inline-block;
    margin-left: 12px;
    font-size: 13px;
    color: #4B5563;
}
.backup-status.success { color: #059669; font-weight: 600; }
.backup-status.error   { color: #DC2626; font-weight: 600; }
.settings-hint { color: #6B7280; font-size: 13px; margin: 0 0 8px 0; }
/* ============== Backup actions row ============== */
.backup-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.backup-actions .btn-upload { cursor: pointer; margin: 0; }

@media (max-width: 768px) {
    .backup-item { flex-direction: column; align-items: flex-start; }
    .backup-item-actions { margin-left: 0; margin-top: 6px; }

    .backup-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
    }
    .backup-actions .btn {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        justify-content: center;
    }
    .backup-actions .backup-status {
        margin-left: 0;
        margin-top: 4px;
        text-align: center;
        width: 100%;
        max-width: 100%;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    /* ALL settings fieldset should be constrained to viewport */
    .settings-form,
    fieldset.settings-group,
    .form-row,
    .backup-actions,
    .backups-list,
    .backup-item,
    .backup-item-info,
    .backup-item-actions,
    .backup-status,
    .settings-hint,
    fieldset.settings-group pre,
    fieldset.settings-group code,
    fieldset.settings-group p {
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    /* <pre> blocks in backup help: contain long UNC paths */
    fieldset.settings-group pre {
        max-width: 100%;
        overflow-x: hidden;
        word-break: break-all;
        white-space: pre-wrap;
    }
    /* Reduce padding on mobile so 760px max-width doesn't overflow */
    .settings-group {
        padding: 16px 14px;
    }
}

/* ============== Settings — tiny phone (≤480px) extra-tight constraints ==============
   Owner reports backup-status section still wider than other settings
   sections on phones < 480px wide. Cause: pre blocks / status spans
   inheriting min-content sizing from long filenames / UNC paths.
   Force EVERY descendant of fieldset.settings-group to fit the parent,
   not the viewport — break words instead of overflowing. */
@media (max-width: 480px) {
    .settings-form,
    fieldset.settings-group,
    .form-row,
    .backup-actions,
    .backups-list,
    .backup-item,
    .backup-item-info,
    .backup-item-actions,
    .backup-status,
    .settings-hint,
    fieldset.settings-group pre,
    fieldset.settings-group code,
    fieldset.settings-group p {
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .backup-item-info {
        /* Force filename + meta to wrap below action buttons on tiny screens */
        flex-basis: 100%;
    }
    .settings-group {
        padding: 12px 10px;
        margin-left: 0;
        margin-right: 0;
    }
    .form-row-2col {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .form-row-2col > div {
        min-width: 0;
    }
    .backup-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .backup-actions .btn {
        width: 100%;
        margin: 0;
    }
    .backup-actions .backup-status {
        margin-left: 0;
        margin-top: 4px;
        text-align: center;
        white-space: normal;
    }
    fieldset.settings-group pre {
        white-space: pre-wrap;
        overflow-x: hidden;
        word-break: break-all;
    }
    /* legend should not force fieldset to be wide */
    .settings-group legend {
        font-size: 14px;
        padding: 0 6px;
        word-break: break-word;
    }
}

/* ============== iOS install modal ============== */
.ios-install-modal {
    max-width: 460px;
    text-align: left;
    position: relative;
}
.ios-install-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 22px;
    color: #6B7280;
    cursor: pointer;
    padding: 4px 10px;
    line-height: 1;
}
.ios-install-close:hover { color: var(--text); }
.ios-install-intro {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 16px 0;
    line-height: 1.5;
}
.ios-install-steps {
    list-style: none;
    counter-reset: step;
    padding: 0;
    margin: 0 0 16px 0;
}
.ios-install-steps li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.5;
}
.step-num {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}
.step-text { flex: 1; min-width: 0; }
.step-text b { color: var(--text); }
.ios-install-warning {
    background: #FEF3C7;
    border: 1px solid #FDE68A;
    color: #92400E;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 16px;
}
#ios-install-got-it { width: 100%; }
@media (max-width: 480px) {
    .ios-install-modal { max-width: 92vw; padding: 20px 18px; }
    .ios-install-steps li { font-size: 13px; }
    .step-num { flex: 0 0 24px; width: 24px; height: 24px; font-size: 12px; }
}

/* ============== Public card share page ============== */
.public-card-page {
    background: linear-gradient(135deg, #F5F3FF 0%, #EDE9FE 100%);
    min-height: 100vh;
}
.public-card {
    padding: 32px 28px;
    margin-top: 32px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(124, 58, 237, 0.15);
}
.public-card-header {
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #EDE9FE;
}
.public-card-badge {
    display: inline-block;
    background: linear-gradient(135deg, #7C3AED, #A78BFA);
    color: white;
    padding: 4px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}
.public-card-name {
    font-size: 28px;
    font-weight: 700;
    color: #1F2937;
    margin-bottom: 4px;
}
.public-card-title {
    font-size: 16px;
    color: #6B7280;
    margin-bottom: 2px;
}
.public-card-company {
    font-size: 15px;
    color: #7C3AED;
    font-weight: 600;
    margin-bottom: 16px;
}
.public-card-section {
    margin: 14px 0;
    padding: 10px 0;
    border-top: 1px solid #F3F4F6;
}
.public-card-label {
    font-size: 11px;
    color: #9CA3AF;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    font-weight: 600;
}
.public-card-link {
    display: block;
    color: #4F46E5;
    text-decoration: none;
    padding: 4px 0;
    font-size: 15px;
    word-break: break-all;
}
.public-card-link:hover {
    color: #7C3AED;
    text-decoration: underline;
}
.public-card-text {
    color: #374151;
    font-size: 14px;
    line-height: 1.5;
}
.public-card-image {
    max-width: 100%;
    width: 100%;
    max-height: 360px;
    aspect-ratio: 1.75 / 1;  /* business card ratio — prevent stretch on iOS/iPad */
    object-fit: contain;     /* preserve aspect ratio, no distortion */
    border-radius: 8px;
    margin-top: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    background: #F3F4F6;
}
.public-card-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #EDE9FE;
    font-size: 12px;
    color: #9CA3AF;
}

/* ============== Dashboard Phase 2 widgets ============== */
.stat-card.stat-warning {
    background: linear-gradient(135deg, #FEF3C7, #FDE68A);
    color: #92400E;
}
.stat-card.stat-danger {
    background: linear-gradient(135deg, #FEE2E2, #FECACA);
    color: #991B1B;
}
.stat-card.stat-success {
    background: linear-gradient(135deg, #D1FAE5, #A7F3D0);
    color: #065F46;
}
.stat-card.stat-warning .stat-label,
.stat-card.stat-danger .stat-label,
.stat-card.stat-success .stat-label {
    color: inherit;
    opacity: 0.85;
}

/* ============== Card list with avatars ============== */
.card-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
}
.card-list-avatar {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    overflow: hidden;
    background: #F3F4F6;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-list-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #7C3AED, #A78BFA);
    color: white;
    font-size: 18px;
    font-weight: 700;
}
.card-list-body {
    flex: 1;
    min-width: 0;
}
.card-list-due {
    background: linear-gradient(to right, #FEE2E2 0%, transparent 50%);
}
.card-list-birthday {
    background: linear-gradient(to right, #FEF3C7 0%, transparent 50%);
}

/* ============== Card list as a panel (matches .server-urls-card style) ============== */
.card-list {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    margin: 12px 0 24px 0;
    overflow: hidden;
}
.card-list .card-list-item {
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent !important;
}
.card-list .card-list-item:last-child {
    border-bottom: none;
}

/* ============== Dark mode ============== */
[data-theme="dark"] {
    --bg:            #0F172A;  /* slate-900 */
    --bg-card:       #1E293B;  /* slate-800 */
    --text:          #F1F5F9;  /* slate-100 */
    --text-muted:    #94A3B8;  /* slate-400 */
    --border:        #334155;  /* slate-700 */
}
[data-theme="dark"] body {
    background: var(--bg);
    color: var(--text);
}
[data-theme="dark"] .card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .action-card,
[data-theme="dark"] .card-list-item,
[data-theme="dark"] .form-field input,
[data-theme="dark"] .form-field textarea,
[data-theme="dark"] .topnav,
[data-theme="dark"] .drop-zone,
[data-theme="dark"] .backup-item,
[data-theme="dark"] .backups-list {
    background: var(--bg-card) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
[data-theme="dark"] .card-list-item:hover {
    background: rgba(124, 58, 237, 0.15) !important;
}
[data-theme="dark"] .topnav {
    background: linear-gradient(135deg, #1E1B4B 0%, #312E81 100%) !important;
}
[data-theme="dark"] .subtitle,
[data-theme="dark"] .pwa-banner-text span,
[data-theme="dark"] .pwa-banner-sub {
    color: var(--text-muted);
}
[data-theme="dark"] .hint-box {
    background: #1E1B4B !important;
    border-color: #4C1D95 !important;
    color: #C4B5FD !important;
}
[data-theme="dark"] .warn-box {
    background: #422006 !important;
    border-color: #92400E !important;
    color: #FCD34D !important;
}
[data-theme="dark"] .stat-card.stat-warning {
    background: linear-gradient(135deg, #422006, #78350F);
    color: #FCD34D;
}
[data-theme="dark"] .stat-card.stat-danger {
    background: linear-gradient(135deg, #450A0A, #7F1D1D);
    color: #FCA5A5;
}
[data-theme="dark"] .stat-card.stat-success {
    background: linear-gradient(135deg, #064E3B, #065F46);
    color: #6EE7B7;
}
[data-theme="dark"] .stat-card.stat-primary {
    background: linear-gradient(135deg, #4C1D95, #6D28D9);
    color: #DDD6FE;
}
[data-theme="dark"] .action-card {
    background: var(--bg-card);
}
[data-theme="dark"] .form-field label {
    color: var(--text-muted);
}
[data-theme="dark"] .tag {
    background: #312E81;
    color: #C4B5FD;
}
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select {
    background: #0F172A !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

/* Theme toggle button (in nav) */
.theme-toggle {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 16px;
    margin-right: 8px;
}
.theme-toggle:hover { background: rgba(255,255,255,0.25); }

/* ============== Card detail Phase 2 ============== */
.card-detail-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.card-detail-title-row h1 {
    flex: 1;
    min-width: 0;
    margin: 0;
}
.pin-btn {
    background: white;
    border: 1.5px solid #E5E7EB;
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #6B7280;
    white-space: nowrap;
    transition: all 0.2s;
}
.pin-btn:hover {
    border-color: #7C3AED;
    color: #7C3AED;
}
.pin-btn.pinned {
    background: #7C3AED;
    border-color: #7C3AED;
    color: white;
}
[data-theme="dark"] .pin-btn {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border);
}
.card-detail-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0 16px 0;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: #F3F4F6;
    color: #4B5563;
}
.tag-chip-birthday { background: #FEF3C7; color: #92400E; }
.tag-chip-followup { background: #DBEAFE; color: #1E40AF; }
.tag-chip-due { background: #FEE2E2; color: #991B1B; font-weight: 600; }
.tag-chip-info { background: #D1FAE5; color: #065F46; }
[data-theme="dark"] .tag-chip { background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); }
[data-theme="dark"] .tag-chip-birthday { background: #422006; color: #FCD34D; }
[data-theme="dark"] .tag-chip-followup { background: #1E3A8A; color: #93C5FD; }
[data-theme="dark"] .tag-chip-due { background: #450A0A; color: #FCA5A5; }
[data-theme="dark"] .tag-chip-info { background: #064E3B; color: #6EE7B7; }

.card-detail-phase2 {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #E5E7EB;
}
[data-theme="dark"] .card-detail-phase2 { border-top-color: var(--border); }

.form-section-title {
    font-size: 14px;
    color: var(--text-muted);
    margin: 24px 0 8px 0;
    padding-top: 16px;
    border-top: 1px solid #E5E7EB;
}
[data-theme="dark"] .form-section-title { border-top-color: var(--border); }

.tag-editor {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    min-height: 40px;
}
.tag-editor:focus-within { border-color: #7C3AED; box-shadow: 0 0 0 3px rgba(124,58,237,0.1); }
.tag-editor .tag-list { display: contents; }
.tag-remove { cursor: pointer; margin-left: 4px; font-weight: bold; }
.tag-remove:hover { color: #DC2626; }

/* ============== Settings page dark mode ============== */
[data-theme="dark"] .settings-group {
    background: var(--bg-card);
    border-color: var(--border);
}
[data-theme="dark"] .settings-group legend {
    color: #C4B5FD;  /* lighter purple so it's readable on dark bg */
}
[data-theme="dark"] .form-row label {
    color: var(--text);
}
[data-theme="dark"] .form-row input,
[data-theme="dark"] .form-row select,
[data-theme="dark"] .form-row textarea {
    background: #0F172A;
    color: var(--text);
    border-color: var(--border);
}
[data-theme="dark"] .alert-success {
    background: #064E3B;
    color: #6EE7B7;
    border-color: #065F46;
}
[data-theme="dark"] .alert-error {
    background: #450A0A;
    color: #FCA5A5;
    border-color: #7F1D1D;
}
[data-theme="dark"] .settings-hint {
    color: var(--text-muted);
}
[data-theme="dark"] .backups-list,
[data-theme="dark"] .backup-item {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
}
[data-theme="dark"] .backup-item-name { color: var(--text); }
[data-theme="dark"] .backup-item-meta { color: var(--text-muted); }

/* ============== QR display ============== */
.qr-display {
    display: flex;
    justify-content: center;
    margin: 16px 0;
    padding: 12px;
    background: white;
    border-radius: 8px;
}
.qr-display svg {
    max-width: 280px;
    width: 100%;
    height: auto;
}

/* ============== Custom date picker (3 dropdowns) ============== */
.date-picker {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 6px;
    align-items: center;
}
.date-picker select {
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text);
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
}
.date-picker select:focus {
    outline: none;
    border-color: var(--primary);
}
@media (max-width: 480px) {
    .date-picker { grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
    .date-picker select { padding: 6px 4px; font-size: 13px; }
}

/* ============== Card edit dark mode (titles were invisible) ============== */
[data-theme="dark"] .page-title {
    color: var(--text);
}
[data-theme="dark"] .page-header h1 {
    color: var(--text);
}
[data-theme="dark"] .form-section-title {
    color: #C4B5FD;  /* light purple */
}
[data-theme="dark"] label[for="name"],
[data-theme="dark"] label[for="title"],
[data-theme="dark"] label[for="company"],
[data-theme="dark"] label[for="phones"],
[data-theme="dark"] label[for="emails"],
[data-theme="dark"] label[for="websites"],
[data-theme="dark"] label[for="address"],
[data-theme="dark"] label[for="notes"] {
    color: var(--text);
}
/* Catch-all for any other form labels (birthday, next_followup_at, tags, etc.) */
[data-theme="dark"] .form-row label {
    color: #C4B5FD;  /* light purple - readable on dark slate */
}

/* ============== btn-secondary dark mode (was white bg + white text) ============== */
[data-theme="dark"] .btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border);
}
[data-theme="dark"] .btn-secondary:hover {
    background: #312E81;
    color: white;
    border-color: #4C1D95;
}

/* ============== Tag filter bar + row tags ============== */
.tag-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: -4px 0 16px 0;
    padding: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.tag-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.15s;
}
.tag-filter-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}
.tag-filter-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}
.tag-filter-chip.tag-filter-pinned.active {
    background: #F59E0B;
    border-color: #F59E0B;
}
.tag-filter-count {
    background: rgba(0,0,0,0.15);
    color: inherit;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}
.tag-filter-chip.active .tag-filter-count {
    background: rgba(255,255,255,0.3);
}
.card-list-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}
.card-row-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}
[data-theme="dark"] .tag-filter-bar {
    background: #1E293B;
    border-color: var(--border);
}

/* ============== Card list row with inline actions ============== */
.card-list-item {
    display: flex !important;
    align-items: stretch;
    gap: 0;
    padding: 0 !important;
    overflow: hidden;
}
.card-list-main {
    flex: 1;
    min-width: 0;
    padding: 14px 18px;
    color: var(--text);
    text-decoration: none;
}
.card-list-actions {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    border-left: 1px solid var(--border);
    background: transparent;
}
.card-list-action-btn {
    flex: 1;
    min-width: 36px;
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    border-bottom: 1px solid var(--border);
}
.card-list-action-btn:last-child { border-bottom: none; }
.card-list-action-btn:hover {
    background: var(--primary);
    color: white;
    text-decoration: none;
}
.card-list-action-btn.pinned {
    background: #7C3AED;
    color: white;
}
.card-list-action-btn.pinned:hover {
    background: #5B21B6;
}
[data-theme="dark"] .card-list-actions {
    border-left-color: var(--border);
}
[data-theme="dark"] .card-list-action-btn {
    border-bottom-color: var(--border);
}
@media (max-width: 600px) {
    .card-list-actions { flex-direction: row; }
    .card-list-action-btn { border-bottom: none; border-right: 1px solid var(--border); }
    .card-list-action-btn:last-child { border-right: none; }
    .card-list-action-btn { min-width: 44px; }
}

/* ============== Server URLs widget (Dashboard) ============== */
.server-urls-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    margin: 24px 0;
    max-width: 100%;
    box-sizing: border-box;
}
.server-urls-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
}
.server-urls-help {
    margin: 4px 0 12px 0;
    font-size: 12px;
    color: var(--text-muted);
}
.server-urls-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.server-url-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    flex-wrap: wrap;
}
.server-url-icon { font-size: 16px; flex: 0 0 auto; }
.server-url-label {
    flex: 0 0 140px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}
.server-url-code {
    flex: 1;
    min-width: 200px;
    font-family: 'SFMono-Regular', Consolas, 'Courier New', monospace;
    font-size: 13px;
    color: #7C3AED;
    background: rgba(124, 58, 237, 0.08);
    padding: 3px 8px;
    border-radius: 4px;
    user-select: all;
    word-break: break-all;
}
[data-theme="dark"] .server-url-code {
    color: #C4B5FD;
    background: rgba(124, 58, 237, 0.15);
}
.btn-tiny {
    flex: 0 0 auto;
    padding: 4px 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    transition: all 0.15s;
}
.btn-tiny:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Port status badges */
.port-status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}
.port-status-ok { background: #D1FAE5; color: #065F46; border-color: #6EE7B7; }
.port-status-self { background: #DBEAFE; color: #1E40AF; border-color: #93C5FD; }
.port-status-conflict { background: #FEE2E2; color: #991B1B; border-color: #FCA5A5; animation: pulse-warning 1.5s infinite; }
[data-theme="dark"] .port-status-ok { background: #064E3B; color: #6EE7B7; }
[data-theme="dark"] .port-status-self { background: #1E3A8A; color: #93C5FD; }
[data-theme="dark"] .port-status-conflict { background: #450A0A; color: #FCA5A5; }

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.port-conflict-warning {
    background: linear-gradient(135deg, #FEE2E2, #FECACA);
    color: #991B1B;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid #FCA5A5;
    font-size: 13px;
}
[data-theme="dark"] .port-conflict-warning {
    background: linear-gradient(135deg, #450A0A, #7F1D1D);
    color: #FCA5A5;
    border-color: #991B1B;
}

@media (max-width: 600px) {
    .server-url-label { flex: 0 0 100%; }
    .server-url-code { min-width: 100%; }
}

/* ============== Settings: port check + access URLs ============== */
.port-check-result {
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 500;
}
.port-check-ok { background: #D1FAE5; color: #065F46; }
.port-check-conflict { background: #FEE2E2; color: #991B1B; }
.port-check-error { background: #FEF3C7; color: #92400E; }
[data-theme="dark"] .port-check-ok { background: #064E3B; color: #6EE7B7; }
[data-theme="dark"] .port-check-conflict { background: #450A0A; color: #FCA5A5; }
[data-theme="dark"] .port-check-error { background: #422006; color: #FCD34D; }

.access-urls-display {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.access-urls-list h4 {
    color: var(--text);
}
.access-url-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    flex-wrap: wrap;
}
.access-url-icon { font-size: 14px; }
.access-url-label {
    flex: 0 0 130px;
    font-size: 13px;
    color: var(--text-muted);
}
.access-url-row code {
    flex: 1;
    min-width: 200px;
    font-family: monospace;
    font-size: 12px;
    background: rgba(124, 58, 237, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    color: #7C3AED;
}
[data-theme="dark"] .access-url-row code {
    color: #C4B5FD;
    background: rgba(124, 58, 237, 0.15);
}
.port-suggestion {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    font-size: 13px;
}

/* ============== Dark mode: checkbox labels in settings ============== */
[data-theme="dark"] label[style*="cursor: pointer"] {
    color: var(--text);
}

/* Port check: "in use by us" info state */
.port-check-info {
    background: #DBEAFE;
    color: #1E40AF;
}
[data-theme="dark"] .port-check-info {
    background: #1E3A8A;
    color: #93C5FD;
}

/* ============== Card detail: explicit dark mode (vars don't always work) ============== */
[data-theme="dark"] .card-detail-name { color: #F1F5F9; }
[data-theme="dark"] .card-detail-title { color: #94A3B8; }
[data-theme="dark"] .card-detail-company { color: #C4B5FD; }
[data-theme="dark"] .field-label { color: #94A3B8; }
[data-theme="dark"] .field-value { color: #F1F5F9; }
[data-theme="dark"] .field-value a { color: #C4B5FD; }
[data-theme="dark"] .field-value a:hover { color: #DDD6FE; }
[data-theme="dark"] .meta-label { color: #94A3B8; }
[data-theme="dark"] .meta-value { color: #F1F5F9; }
[data-theme="dark"] .card-image-badge { color: white; background: rgba(124, 58, 237, 0.9); }

/* ============== Scan: optional back image section ============== */
.back-image-section {
    margin-top: 20px;
}
.drop-zone-compact {
    padding: 16px !important;
    min-height: auto !important;
}
.drop-zone-compact .drop-zone-icon {
    margin-bottom: 6px;
}
[data-theme="dark"] .back-image-section {
    border-top-color: var(--border) !important;
}
[data-theme="dark"] .drop-zone-compact {
    background: rgba(124, 58, 237, 0.05);
    border-color: var(--border);
}

/* ============== Card detail: back image (2 images stacked or side-by-side) ============== */
.card-image-back {
    margin-top: 12px;
}
.card-image-badge {
    color: white;
    background: rgba(124, 58, 237, 0.9);
}
.card-image-badge-front {
    background: rgba(124, 58, 237, 0.75);
}
.card-image-badge-back {
    background: rgba(59, 130, 246, 0.85);
}
[data-theme="dark"] .card-image-badge {
    color: white;
}

/* ============== Quick Search Bar (Dashboard) ============== */
.quick-search-container {
    position: relative;
    margin: 16px 0 8px 0;
}
.quick-search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.quick-search-box:focus-within {
    border-color: var(--primary, #7C3AED);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.quick-search-icon { font-size: 18px; opacity: 0.6; }
.quick-search-box input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 15px;
    outline: none;
    padding: 4px 0;
}
.quick-search-kbd {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: monospace;
}
.quick-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 100;
    max-height: 420px;
    overflow-y: auto;
}
.quick-search-results-inner { padding: 6px 0; }
.quick-search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.1s;
}
.quick-search-result-item:hover,
.quick-search-result-item.focused {
    background: rgba(124, 58, 237, 0.1);
    text-decoration: none;
}
.quick-search-result-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, #7C3AED, #A78BFA);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex: 0 0 36px;
    overflow: hidden;
}
.quick-search-result-avatar img { width: 100%; height: 100%; object-fit: cover; }
.quick-search-result-body { flex: 1; min-width: 0; }
.quick-search-result-name { font-weight: 600; font-size: 14px; }
.quick-search-result-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.quick-search-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}
.quick-search-hint {
    padding: 8px 14px;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ============== Recent Tags (Dashboard) ============== */
.recent-tags-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 6px 0 16px 0;
    padding: 4px 0;
}
.recent-tags-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.recent-tags-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.recent-tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--tag-color, #7C3AED);
    color: white;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    opacity: 0.92;
    transition: opacity 0.15s, transform 0.1s;
}
.recent-tag-chip:hover {
    opacity: 1;
    transform: translateY(-1px);
    text-decoration: none;
    color: white;
}
.recent-tag-count {
    background: rgba(255,255,255,0.25);
    border-radius: 8px;
    padding: 0 5px;
    font-size: 11px;
    min-width: 14px;
    text-align: center;
}

/* ============== Cards page: Sidebar layout (A) ============== */
.cards-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.cards-sidebar {
    flex: 0 0 240px;
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 8px;
}
.sidebar-section { margin-bottom: 12px; }
.sidebar-section:last-child { margin-bottom: 0; }
.sidebar-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 12px 4px 12px;
}
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 7px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    transition: background 0.1s;
    margin: 1px 0;
}
.sidebar-item:hover {
    background: rgba(124, 58, 237, 0.08);
    text-decoration: none;
    color: var(--text);
}
.sidebar-item.active {
    background: rgba(124, 58, 237, 0.15);
    color: #7C3AED;
    font-weight: 600;
}
[data-theme="dark"] .sidebar-item.active {
    background: rgba(167, 139, 250, 0.18);
    color: #A78BFA;
}
.sidebar-icon {
    flex: 0 0 18px;
    font-size: 14px;
    line-height: 1;
    text-align: center;
}
.sidebar-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-count {
    flex: 0 0 auto;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 9px;
    min-width: 22px;
    text-align: center;
}
.sidebar-item.active .sidebar-count {
    background: rgba(124, 58, 237, 0.18);
    color: #7C3AED;
}
.cards-main { flex: 1; min-width: 0; }
.sidebar-toggle { display: none; padding: 6px 12px; }
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
}
.sidebar-backdrop.open { display: block; }
@media (max-width: 900px) {
    .cards-layout { display: block; }
    .cards-sidebar {
        position: fixed;
        top: 60px;
        left: 0;
        bottom: 0;
        width: 260px;
        max-height: none;
        border-radius: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.2s;
    }
    .cards-sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
    .cards-main { width: 100%; }
}

/* ============== Batch Action Toolbar (B) ============== */
.batch-toolbar {
    background: linear-gradient(135deg, #7C3AED, #A78BFA);
    color: white;
    border-radius: 10px;
    padding: 12px 16px;
    margin: 16px 0;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    animation: slideDown 0.2s ease-out;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.batch-toolbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.batch-count { font-weight: 600; font-size: 14px; }
.batch-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.batch-actions .btn { background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.2); }
.batch-actions .btn:hover { background: rgba(255,255,255,0.25); }
.batch-btn-danger { background: rgba(220, 38, 38, 0.7) !important; }
.batch-btn-danger:hover { background: rgba(220, 38, 38, 0.9) !important; }
.batch-select-all {
    padding: 8px 0;
    font-size: 13px;
    color: var(--text-muted);
}
.batch-select-all label { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.batch-checkbox-label {
    cursor: pointer;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
}
.batch-checkbox, #batchSelectAll {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #7C3AED;
}
.card-list-item { position: relative; }
.card-list-item.selected { background: rgba(124, 58, 237, 0.05); border-color: #7C3AED; }
[data-theme="dark"] .card-list-item.selected { background: rgba(124, 58, 237, 0.12); }

/* ============== Card image upload in edit form (E) ============== */
.card-images-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    margin: 16px 0 24px 0;
}
.card-images-section h3 { margin-top: 0; }
.card-images-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 12px;
}
@media (max-width: 600px) { .card-images-grid { grid-template-columns: 1fr; } }
.card-image-slot {
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 12px;
    text-align: center;
}
.card-image-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
    margin-bottom: 8px;
}
.card-image-icon { font-size: 18px; }
.card-image-preview {
    margin: 8px 0;
    border-radius: 6px;
    overflow: hidden;
    max-height: 180px;
}
.card-image-preview img {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    display: block;
}
.card-image-empty {
    padding: 24px 12px;
    color: var(--text-muted);
    font-size: 13px;
}
.card-image-empty span { font-size: 32px; display: block; margin-bottom: 4px; opacity: 0.4; }
.card-image-empty p { margin: 0; }
.card-image-input {
    display: block;
    width: 100%;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text);
}
.card-image-hint {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 11px;
}

/* ============== Share templates (C) ============== */
.share-templates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    padding: 8px 0;
}
.share-template-tile {
    display: block;
    padding: 10px 8px;
    text-align: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 12px;
    transition: all 0.15s;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
}
.share-template-tile:hover {
    background: #7C3AED;
    color: white;
    border-color: #7C3AED;
    transform: translateY(-1px);
    text-decoration: none;
}
/* Click-feedback flash (copy-on-click layout tiles, 2026-06-30).
   Keeps the hover purple, then flashes brighter so user knows the click registered. */
.share-template-tile-flash {
    animation: share-tile-flash 0.6s ease-out;
}
@keyframes share-tile-flash {
    0%   { background: #7C3AED; color: white; transform: scale(1.05); }
    50%  { background: #5B21B6; color: white; transform: scale(1.08); }
    100% { background: var(--bg-card); color: var(--text); transform: scale(1); }
}

/* ============== Edit page image upload buttons (E) ============== */
/* File input is hidden visually but stays form-submittable.
   DO NOT use display:none or position:absolute (with off-screen) on file inputs —
   they will NOT be submitted with the form. Use opacity:0 + 0×0 size. */
.card-image-input-hidden {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    opacity: 0;
    z-index: -1;
}
.card-image-upload-btn {
    display: inline-block !important;
    margin-top: 8px;
    cursor: pointer;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}
.card-image-hint-block {
    display: block;
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
}

/* ============== Public card image caption (C fix) ============== */
.public-card-image-caption {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 10px;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.public-card-image-caption:first-child { margin-top: 0; }

/* ============== Two-button upload group (E) ============== */
.card-image-btn-group {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}
.card-image-btn-group .card-image-upload-btn {
    flex: 1;
    margin-top: 0;
    font-size: 12px;
    padding: 8px 4px;
}

/* ============== Card action buttons responsive (mobile: vertical stack) ============== */
@media (max-width: 700px) {
    .card-list-item {
        flex-wrap: wrap;
    }
    .card-list-actions {
        flex-direction: column;
        gap: 2px;
        margin-left: auto;
        align-self: stretch;
        justify-content: center;
    }
    .card-list-action-btn {
        width: 32px;
        height: 28px;
        padding: 2px 4px;
        font-size: 13px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============== Windows autostart section (EXE deployment) ============== */
.autostart-section {
    padding: 8px 0;
}
.autostart-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
}
.autostart-status-text {
    font-weight: 600;
    font-size: 14px;
}

/* ============== OCR check status (settings) ============== */
.ocr-check-status {
    margin-left: 12px;
    font-size: 13px;
    line-height: 1.5;
}
.ocr-ok { color: #16A34A; font-weight: 600; }
.ocr-fail { color: #DC2626; font-weight: 600; }
[data-theme="dark"] .ocr-ok { color: #4ADE80; }
[data-theme="dark"] .ocr-fail { color: #F87171; }
