:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #e2e4e9;
    --color-text: #1f2430;
    --color-muted: #6b7280;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-danger: #dc2626;
    --color-danger-bg: #fee2e2;
    --color-ok-bg: #dcfce7;
    --color-ok-text: #15803d;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth ---------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}
.auth-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 32px;
    width: 340px;
}
.auth-box h1 { font-size: 20px; margin: 0 0 20px; text-align: center; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; }
.auth-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--color-muted); }
.auth-box input {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
}
.msg-error { color: var(--color-danger); font-size: 13px; text-align: center; }
.msg-ok { color: var(--color-ok-text); font-size: 14px; text-align: center; }
.msg-warn { color: #b45309; font-size: 13px; text-align: center; }

/* ---------- Layout ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 12px 24px;
}
.topbar-logo { font-weight: 700; font-size: 16px; color: var(--color-text); }
.topbar-logo:hover { text-decoration: none; }
.topbar-nav { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.topbar-user { color: var(--color-muted); }
.topbar-logout { color: var(--color-danger); }

.layout {
    display: flex;
    height: calc(100vh - 49px);
}

.sidebar {
    width: 260px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}
.sidebar-top { margin-bottom: 12px; }
.sidebar-label { font-size: 12px; color: var(--color-muted); margin-bottom: 6px; }
.client-dropdown {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    flex: 1;
}
.client-dropdown option { padding: 6px 8px; }

.content {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    text-align: center;
}
.btn:hover { text-decoration: none; }
.btn-block { display: block; width: 100%; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); border: none; }
.btn-danger:hover { background: #fecaca; }
.btn-icon {
    background: none; border: none; cursor: pointer; font-size: 15px; padding: 4px;
    border-radius: 4px;
}
.btn-icon:hover { background: #f3f4f6; }

/* ---------- Search ---------- */
.search-wrap { position: relative; max-width: 520px; margin-bottom: 24px; }
.search-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 15px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}
.search-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    max-height: 340px;
    overflow-y: auto;
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
    z-index: 20;
}
.search-results.active { display: block; }
.search-result-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f3f4f6; text-decoration: none; }
.search-result-logo { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; }
.search-result-logo.placeholder { background: #e5e7eb; display: inline-block; }
.search-empty { padding: 12px 14px; color: var(--color-muted); font-size: 13px; }

.welcome-box { color: var(--color-muted); }

/* ---------- Client card (view) ---------- */
.client-card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.client-title { display: flex; align-items: center; gap: 12px; }
.client-title h1 { font-size: 22px; margin: 0; }
.client-logo { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--color-border); }
.client-actions { display: flex; gap: 8px; }

.fields-view {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    max-width: 800px;
}
.field-row {
    display: flex;
    border-bottom: 1px solid var(--color-border);
}
.field-row:last-child { border-bottom: none; }
.field-label {
    width: 220px;
    flex-shrink: 0;
    padding: 12px 16px;
    background: #fafafa;
    color: var(--color-muted);
    font-size: 13px;
    border-right: 1px solid var(--color-border);
}
.field-value { padding: 12px 16px; flex: 1; display: flex; align-items: center; gap: 6px; word-break: break-word; }
.field-textarea { white-space: pre-wrap; }
.pw-mask { font-family: monospace; letter-spacing: 1px; }
.badge { padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-yes { background: var(--color-ok-bg); color: var(--color-ok-text); }
.badge-no { background: var(--color-danger-bg); color: var(--color-danger); }
.muted { color: var(--color-muted); }
.muted.small { font-size: 13px; margin-top: -8px; margin-bottom: 16px; }

/* ---------- Edit form ---------- */
.edit-form { max-width: 800px; }
.edit-top-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.edit-top-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--color-muted); }
.edit-top-row label.grow { flex: 1; min-width: 240px; }
.edit-top-row input[type="text"] {
    padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 14px;
}

.edit-form h2 { font-size: 16px; margin: 0 0 4px; }

.fields-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

.field-row-edit {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 8px 10px;
}
.drag-handle { cursor: grab; color: var(--color-muted); font-size: 16px; padding: 0 4px; user-select: none; }
.drag-ghost { opacity: 0.4; background: #eef2ff; }

.field-label-input {
    width: 200px; flex-shrink: 0;
    padding: 8px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 13px;
}
.field-type-select {
    width: 160px; flex-shrink: 0;
    padding: 8px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 13px;
}
.field-value-wrap { flex: 1; min-width: 160px; }
.field-value-input {
    width: 100%;
    padding: 8px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 13px;
    font-family: inherit;
}

.edit-toolbar { display: flex; gap: 10px; margin-bottom: 24px; }
.edit-submit-row { display: flex; gap: 10px; }

@media (max-width: 800px) {
    .layout { flex-direction: column; height: auto; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); }
    .field-row { flex-direction: column; }
    .field-label { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); }
    .field-row-edit { flex-wrap: wrap; }
    .field-label-input, .field-type-select { width: 100%; }
}
