:root {
    --primary: #0f766e;
    --primary-dark: #0d5c56;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    padding: 12px;
}

.container { max-width: 1200px; margin: 0 auto; }

header {
    background: linear-gradient(135deg, #0f766e, #0d9488);
    color: white;
    padding: 22px 18px;
    border-radius: 14px;
    margin-bottom: 18px;
    box-shadow: 0 10px 25px rgba(15, 118, 110, 0.25);
}

header h1 { font-size: 1.35rem; margin-bottom: 10px; font-weight: 700; }

.meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.9rem; }
.meta span {
    background: rgba(255,255,255,0.18);
    padding: 3px 10px;
    border-radius: 20px;
}

.stats { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.stat {
    background: rgba(255,255,255,0.22);
    padding: 5px 12px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.85rem;
}

.nav-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.nav-links a {
    color: white;
    text-decoration: none;
    background: rgba(255,255,255,0.2);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
}

.nav-links a:hover { background: rgba(255,255,255,0.32); }

.toolbar {
    background: var(--card);
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toolbar-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

#search {
    flex: 1;
    min-width: 160px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    font-family: inherit;
}

#search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.filter-select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    background: white;
    color: var(--text);
    min-width: 140px;
    cursor: pointer;
    outline: none;
}

.filter-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.count { color: var(--muted); font-size: 0.88rem; white-space: nowrap; }

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: #f8fafc;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.chip:hover { background: #e2e8f0; }
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.chip.active-ok { background: #059669; border-color: #059669; color: white; }
.chip.active-bad { background: #dc2626; border-color: #dc2626; color: white; }
.chip.active-none { background: #64748b; border-color: #64748b; color: white; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
}

.card {
    background: var(--card);
    border-radius: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.card-main-link {
    display: block;
    text-decoration: none;
    color: inherit;
    flex: 1;
}

.card-main-link:hover h2 {
    text-decoration: underline;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.card-actions .btn-add-contact,
.card-actions .btn-lighthouse {
    flex: 1;
    min-width: 110px;
}

.card-site-text {
    word-break: break-all;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.07);
}

.card h2 {
    font-size: 1.05rem;
    color: var(--primary-dark);
    margin-bottom: 6px;
    line-height: 1.4;
}

.card .desc,
.contact-item .desc {
    color: var(--muted);
    font-size: 0.86rem;
    margin-bottom: 10px;
    flex-grow: 1;
}

.info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
    font-size: 0.84rem;
}

.badge {
    display: inline-block;
    background: #ccfbf1;
    color: #0f766e;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
}

.site-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 4px;
}

.site-status.ok { background: #d1fae5; color: #065f46; }
.site-status.error { background: #fee2e2; color: #991b1b; }
.site-status.timeout { background: #fef3c7; color: #92400e; }
.site-status.ssl_error { background: #e0e7ff; color: #3730a3; }
.site-status.unknown { background: #f1f5f9; color: #475569; }

.contact {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.84rem;
}

.contact a {
    color: var(--primary);
    text-decoration: none;
    word-break: break-all;
}

.contact a:hover { text-decoration: underline; }

footer {
    text-align: center;
    margin-top: 28px;
    padding: 16px;
    color: var(--muted);
    font-size: 0.82rem;
}

.no-result {
    text-align: center;
    padding: 40px 16px;
    color: var(--muted);
    grid-column: 1 / -1;
    display: none;
}

.list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.list-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, transform 0.2s;
    flex: 1;
    min-width: 0;
}

.list-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.list-row .btn-del {
    flex-shrink: 0;
    align-self: center;
    padding: 8px 14px;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
}

.list-item:hover {
    box-shadow: 0 8px 18px rgba(0,0,0,0.06);
    transform: translateY(-1px);
}

.list-item h2 {
    font-size: 1.05rem;
    color: var(--primary-dark);
    margin-bottom: 4px;
}

.list-meta {
    color: var(--muted);
    font-size: 0.86rem;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.list-count {
    background: #ccfbf1;
    color: #0f766e;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 10px;
    white-space: nowrap;
}

.form-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}

.form-box label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.form-box input,
.form-box textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.92rem;
    margin-bottom: 14px;
}

.form-box textarea { min-height: 180px; resize: vertical; }

.btn {
    display: inline-block;
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: var(--primary-dark); }

.btn-secondary {
    background: #e2e8f0;
    color: var(--text);
}

.btn-secondary:hover { background: #cbd5e1; }

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 0.9rem;
}

.alert-ok { background: #d1fae5; color: #065f46; }
.alert-err { background: #fee2e2; color: #991b1b; }

.hint {
    color: var(--muted);
    font-size: 0.88rem;
    margin-bottom: 14px;
    line-height: 1.8;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 0.92rem;
}
.check-row input { width: auto; margin: 0; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.code-sample {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow: auto;
    font-size: 0.8rem;
    margin-bottom: 16px;
    direction: ltr;
    text-align: left;
}

.log-box {
    display: none;
    margin-top: 14px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.78rem;
    white-space: pre-wrap;
    direction: ltr;
    text-align: left;
    max-height: 260px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn[disabled] { opacity: 0.7; cursor: wait; }

.empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--muted);
    background: var(--card);
    border-radius: 12px;
    border: 1px dashed var(--border);
}

.view-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.tab-btn {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 999px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
}

.tab-btn:hover { background: #f1f5f9; }

.tab-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.tab-badge {
    display: inline-block;
    min-width: 1.4em;
    margin-right: 6px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(255,255,255,0.22);
    font-size: 0.78rem;
}

.tab-btn:not(.active) .tab-badge {
    background: #ccfbf1;
    color: #0f766e;
}

.btn-add-contact {
    margin-top: 12px;
    width: 100%;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.86rem;
    cursor: pointer;
}

.btn-add-contact:hover { background: var(--primary-dark); }
.btn-add-contact:active { transform: translateY(1px); }

.btn-add-contact.is-saved {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.card-actions .btn-add-contact {
    margin-top: 0;
    width: auto;
}

.inline-form {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.inline-form.open { display: block; }

.inline-form label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 4px;
}

.inline-form .optional {
    font-weight: 400;
    color: var(--muted);
}

.inline-form input,
.inline-form textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.88rem;
    margin-bottom: 10px;
    outline: none;
}

.inline-form input:focus,
.inline-form textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.inline-form textarea { min-height: 64px; resize: vertical; }

.inline-form input[dir="ltr"] { text-align: left; }

.form-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.form-error {
    display: none;
    color: #991b1b;
    background: #fee2e2;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.form-error.show { display: block; }

.contacts-panel { display: none; }
.contacts-panel.is-on { display: block; }
.companies-wrap.is-off { display: none; }

.contact-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
}

.contact-item h2 {
    font-size: 1.05rem;
    color: var(--primary-dark);
    margin-bottom: 6px;
    line-height: 1.4;
}

.person-box {
    margin-top: 10px;
    padding: 10px 12px;
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    border-radius: 10px;
    font-size: 0.88rem;
}

.contact-item-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.contact-company {
    font-weight: 800;
    color: var(--primary-dark);
    font-size: 1rem;
}

.contact-person { font-size: 0.92rem; }

.contact-phone {
    direction: ltr;
    text-align: left;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
}

.contact-notes {
    color: var(--muted);
    font-size: 0.86rem;
    margin-top: 6px;
}

.contact-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.contact-links a,
.contact-links button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.82rem;
    text-decoration: none;
    border: none;
    cursor: pointer;
}

.btn-wa { background: #128c7e; color: #fff; }
.btn-wa:hover { background: #0e6e63; }
.btn-tg { background: #229ed9; color: #fff; }
.btn-tg:hover { background: #1b8dc4; }
.btn-del { background: #fee2e2; color: #991b1b; }
.btn-del:hover { background: #fecaca; }

.contacts-empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--muted);
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 12px;
}

#contacts-search {
    flex: 1;
    min-width: 160px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
}

#contacts-search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.45);
}

.confirm-overlay[hidden] { display: none; }

.confirm-box {
    width: min(420px, 100%);
    background: var(--card);
    border-radius: 14px;
    padding: 20px 18px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
}

.confirm-box p {
    font-weight: 700;
    margin-bottom: 16px;
    font-size: 1rem;
}

.contacts-panel .toolbar { margin-bottom: 14px; }
.contacts-grid { margin-bottom: 12px; }

.camp-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    background: linear-gradient(135deg, #f0fdfa 0%, #ecfeff 100%);
    border: 1px solid #99f6e4;
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 16px;
}

.camp-entry strong {
    display: block;
    font-size: 1.02rem;
    color: var(--primary-dark);
    margin-bottom: 4px;
}

.camp-entry p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

@media (max-width: 640px) {
    body { padding: 10px; }
    header { padding: 18px 14px; border-radius: 12px; }
    header h1 { font-size: 1.15rem; }
    .stat { font-size: 0.8rem; padding: 4px 10px; }
    .toolbar { padding: 12px; gap: 10px; }
    .toolbar-row { flex-direction: column; align-items: stretch; }
    #search,
    #contacts-search { min-width: 100%; width: 100%; }
    .filter-select { width: 100%; min-width: 100%; }
    .filter-chips { justify-content: center; }
    .count { text-align: center; width: 100%; }
    .grid { grid-template-columns: 1fr; gap: 12px; }
    .card { padding: 14px; }
    .card h2 { font-size: 1rem; }
    .info { grid-template-columns: 1fr; gap: 4px; }
    .chip { padding: 7px 14px; font-size: 0.85rem; }
    .list-item { flex-direction: column; align-items: flex-start; }
    .list-row { flex-direction: column; }
    .list-row .btn-del { width: 100%; }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (min-width: 641px) and (max-width: 900px) {
    .grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}
