@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap");

:root {
    --crm-slate-50: #f8fafc;
    --crm-slate-100: #f1f5f9;
    --crm-slate-200: #e2e8f0;
    --crm-slate-300: #cbd5e1;
    --crm-slate-400: #94a3b8;
    --crm-slate-500: #64748b;
    --crm-slate-600: #475569;
    --crm-slate-700: #334155;
    --crm-slate-800: #1e293b;
    --crm-slate-900: #0f172a;

    --crm-blue-50: #eff6ff;
    --crm-blue-100: #dbeafe;
    --crm-blue-200: #bfdbfe;
    --crm-blue-500: #3b82f6;
    --crm-blue-600: #2563eb;
    --crm-blue-700: #1d4ed8;

    --crm-rose-50: #fff1f2;
    --crm-rose-100: #ffe4e6;
    --crm-rose-200: #fecdd3;
    --crm-rose-600: #e11d48;
    --crm-rose-700: #be123c;

    --crm-radius-sm: 6px;
    --crm-radius-md: 8px;
    --crm-radius-lg: 12px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    background: var(--crm-slate-50);
    color: var(--crm-slate-800);
    font-family: "Inter", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--crm-blue-600);
}

button,
input,
select,
textarea {
    font-family: inherit;
}

button {
    border: 0;
    background: var(--crm-blue-600);
    color: #ffffff;
    padding: 8px 12px;
    border-radius: var(--crm-radius-sm);
    cursor: pointer;
}

button:hover {
    background: var(--crm-blue-700);
}

input,
select,
textarea {
    width: 100%;
    max-width: 420px;
    padding: 8px 10px;
    border: 1px solid var(--crm-slate-300);
    border-radius: var(--crm-radius-sm);
    background: #ffffff;
}

textarea {
    max-width: 700px;
}

form {
    margin: 0;
}

main {
    width: 100%;
    max-width: 1200px;
    margin: 24px auto;
    padding: 0 24px;
}

h2 {
    margin-top: 0;
    margin-bottom: 16px;
}

p {
    margin: 8px 0;
}

label {
    font-weight: 600;
}

details {
    background: #ffffff;
    border: 1px solid #dddddd;
    border-radius: var(--crm-radius-md);
    padding: 12px;
    margin: 12px 0;
}

summary {
    cursor: pointer;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
    border: 1px solid #dddddd;
    border-radius: var(--crm-radius-md);
    overflow: hidden;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid #eeeeee;
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--crm-slate-50);
    font-weight: 700;
}

tr:last-child td {
    border-bottom: 0;
}

td form {
    margin-bottom: 8px;
}

hr {
    border: 0;
    border-top: 1px solid #dddddd;
    margin: 20px 0;
}

/* Header */

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    min-height: 64px;
    padding: 0 24px;
    background: #ffffff;
    border-bottom: 1px solid var(--crm-slate-200);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    width: 100%;
    max-width: 1700px;
    min-height: 64px;
    margin: 0 auto;
}

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

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.app-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--crm-blue-600);
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.22);
}

.app-brand-name {
    color: var(--crm-slate-900);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 64px;
}

.app-nav a {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 64px;
    padding: 0 2px;
    color: var(--crm-slate-500);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: color 150ms ease;
}

.app-nav a:hover {
    color: var(--crm-slate-900);
}

.app-nav a.active {
    color: var(--crm-blue-600);
}

.app-nav a.active::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: -1px;
    left: 0;
    height: 2px;
    border-radius: 999px;
    background: var(--crm-blue-600);
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 0;
    border: 0;
}

.header-username {
    color: var(--crm-slate-700);
    font-size: 14px;
    font-weight: 600;
}

.profile-icon-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: var(--crm-slate-100);
    border: 1px solid var(--crm-slate-200);
    border-radius: 999px;
    color: var(--crm-slate-500);
    text-decoration: none;
    transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}

.profile-icon-link:hover {
    background: var(--crm-blue-50);
    color: var(--crm-blue-600);
    transform: scale(1.04);
}

.profile-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.app-header-logout {
    display: flex;
    margin: 0;
}

.app-logout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 40px;
    background: var(--crm-rose-50);
    color: var(--crm-rose-600);
    border: 1px solid var(--crm-rose-100);
    border-radius: var(--crm-radius-md);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.app-logout-button:hover {
    background: var(--crm-rose-100);
    color: var(--crm-rose-700);
    border-color: var(--crm-rose-200);
}

/* Shared form/error helpers */

.form-errors,
.form-error {
    display: block;
    margin-top: 4px;
    color: #b91c1c;
    font-size: 13px;
    font-weight: 600;
}

.form-field-error input,
.form-field-error select,
.form-field-error textarea {
    border-color: #b91c1c;
}

.token-box {
    margin: 12px 0;
    padding: 12px;
    border: 1px solid var(--crm-blue-200);
    background: var(--crm-blue-50);
    border-radius: var(--crm-radius-md);
}

.token-box input {
    width: 100%;
    max-width: 760px;
}

/* Older customer lookup helpers kept for compatibility. */

.customer-lookup-box {
    margin: 14px 0 18px;
    padding: 14px;
    border: 1px solid #dbe3ef;
    background: var(--crm-slate-50);
    border-radius: 10px;
}

.customer-lookup-box h3 {
    margin-top: 0;
}

.customer-lookup-grid {
    display: grid;
    grid-template-columns: minmax(220px, 320px) minmax(260px, 420px);
    gap: 14px;
    align-items: end;
}

.customer-vat-id-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.customer-vat-id-row input {
    flex: 1;
}

.customer-lookup-error {
    margin: 8px 0 0;
    color: #b91c1c;
    font-weight: 600;
}

/* Responsive */

@media (max-width: 760px) {
    .app-header {
        min-height: auto;
        padding: 0 16px;
    }

    .app-header-inner {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 12px 0;
    }

    .app-header-left,
    .app-header-right {
        width: 100%;
        justify-content: space-between;
    }

    .app-nav {
        gap: 14px;
        min-height: auto;
        overflow-x: auto;
    }

    .app-nav a {
        min-height: 34px;
        white-space: nowrap;
        font-size: 13px;
    }

    .app-nav a.active::after {
        bottom: 0;
    }

    .header-username {
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}





.security-bypass-alert {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    display: flex;
    gap: 14px;
    width: min(420px, calc(100vw - 48px));
    padding: 18px;
    border: 1px solid rgba(254, 202, 202, 0.9);
    border-radius: 20px;
    background: #ffffff;
    box-shadow: 0 20px 35px rgba(239, 68, 68, 0.18);
    animation: security-bypass-glow 2.2s ease-in-out infinite;
    transition: opacity 250ms ease, transform 250ms ease;
}

.security-bypass-alert.is-hidden {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
}

.security-bypass-icon-wrap {
    position: relative;
    flex: 0 0 auto;
}

.security-bypass-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 1px solid #fee2e2;
    border-radius: 14px;
    background: #fef2f2;
    color: #dc2626;
}

.security-bypass-icon svg {
    width: 25px;
    height: 25px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.security-bypass-dot {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    border-radius: 999px;
    background: #ef4444;
    animation: security-bypass-dot-pulse 1.2s ease-in-out infinite;
}

.security-bypass-content {
    min-width: 0;
    flex: 1;
}

.security-bypass-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.security-bypass-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border: 1px solid #fee2e2;
    border-radius: 999px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.security-bypass-timer {
    padding: 3px 7px;
    border-radius: 8px;
    background: #fef2f2;
    color: #dc2626;
    font-family: Consolas, monospace;
    font-size: 12px;
    font-weight: 900;
}

.security-bypass-alert h3 {
    margin: 10px 0 6px;
    color: #18181b;
    font-size: 15px;
    font-weight: 900;
}

.security-bypass-alert p {
    margin: 0;
    color: #71717a;
    font-size: 13px;
    line-height: 1.5;
}

.security-bypass-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}

.security-bypass-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid #e4e4e7;
    border-radius: 12px;
    background: #ffffff;
    color: #52525b;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.security-bypass-secondary:hover {
    background: #fafafa;
}

.security-bypass-toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid #27272a;
    border-radius: 14px;
    background: #18181b;
    color: #ffffff;
    box-shadow: 0 18px 30px rgba(15, 23, 42, 0.22);
}

.security-bypass-toast.hidden {
    display: none;
}

.security-bypass-toast span {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #f59e0b;
    animation: security-bypass-dot-pulse 1.2s ease-in-out infinite;
}

.security-bypass-toast p {
    margin: 0;
    color: #d4d4d8;
    font-size: 12px;
    font-weight: 600;
}

.security-bypass-toast strong {
    color: #ffffff;
}

@keyframes security-bypass-glow {
    0%,
    100% {
        box-shadow: 0 20px 35px rgba(239, 68, 68, 0.14), 0 0 0 rgba(239, 68, 68, 0);
    }

    50% {
        box-shadow: 0 24px 42px rgba(239, 68, 68, 0.28), 0 0 24px rgba(239, 68, 68, 0.22);
    }
}

@keyframes security-bypass-dot-pulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.35);
        opacity: 0.55;
    }
}
