:root {
    --ip-blue: #1971B1;
    --ip-blue-dark: #145a8c;
    --ip-blue-light: #E8F1F9;
    --ip-green: #16A085;
    --ip-red: #C0392B;
    --ip-grey: #6B7280;
    --ip-border: #E5E7EB;
    --ip-text: #1F2937;
    --ip-bg: #F7F9FB;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: var(--ip-bg);
    color: var(--ip-text);
}

a { color: var(--ip-blue); text-decoration: none; }

/* ---------------- Sidebar (fixed icon rail) ---------------- */
body.has-sidebar { padding-left: 76px; }
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 76px; z-index: 40;
    background: #122036; display: flex; flex-direction: column; align-items: center;
    padding: 16px 0 10px;
}
.sidebar-logo {
    width: 34px; height: 34px; border-radius: 8px; background: var(--ip-blue); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; margin-bottom: 14px;
}
.sidebar-nav { display: flex; flex-direction: column; align-items: center; width: 100%; gap: 2px; }
.sidebar-link {
    display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%;
    padding: 10px 2px; color: #9FB3CC; text-decoration: none; font-size: 10.5px; font-weight: 600;
    border-left: 3px solid transparent;
}
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-link-active { background: rgba(255,255,255,0.08); color: #fff; border-left-color: var(--ip-blue); }
.sidebar-icon { font-size: 18px; line-height: 1; }
.sidebar-fab {
    width: 38px; height: 38px; border-radius: 10px; background: var(--ip-green); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700;
    text-decoration: none; margin: 14px 0 10px;
}
.sidebar-fab:hover { background: #128f77; }
.sidebar-usage { margin-top: auto; }

.sidebar-item-group { position: relative; width: 100%; }
.sidebar-flyout {
    position: absolute; left: 100%; top: 0; min-width: 230px; background: #1B2942;
    border-radius: 0 10px 10px 0; padding: 14px 0; display: none; z-index: 60;
    box-shadow: 4px 4px 24px rgba(0,0,0,0.35);
}
.sidebar-item-group:hover .sidebar-flyout { display: block; }
.flyout-header { color: #fff; font-weight: 700; font-size: 14px; padding: 2px 20px 12px; }
.flyout-section-title { color: #fff; font-weight: 700; font-size: 12px; padding: 12px 20px 4px; }
.flyout-link {
    display: block; padding: 8px 20px; color: #AEBFD6; font-size: 13px; text-decoration: none; white-space: nowrap;
}
.flyout-link:hover { background: rgba(255,255,255,0.07); color: #fff; }

/* ---------------- Topbar (search / org / bell / user) ---------------- */
.topbar {
    display: flex; align-items: center; gap: 20px; background: #fff;
    border-bottom: 1px solid var(--ip-border); padding: 12px 24px;
}
.topbar-brand { font-size: 18px; font-weight: 700; color: var(--ip-text); flex-shrink: 0; }
.topbar-brand span { color: var(--ip-blue); }
.topbar-search {
    flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px;
    background: #F3F5F8; border-radius: 8px; padding: 8px 12px;
}
.topbar-search-icon { font-size: 13px; opacity: 0.6; }
.topbar-search input {
    border: none; background: transparent; outline: none; font-size: 13px; flex: 1; font-family: inherit;
}
.topbar-right { display: flex; align-items: center; gap: 18px; margin-left: auto; flex-shrink: 0; }
.topbar-org { font-size: 12.5px; color: var(--ip-grey); white-space: nowrap; }
.topbar-bell { font-size: 16px; color: var(--ip-grey); cursor: default; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-avatar { width: 30px; height: 30px; border-radius: 50%; }
.topbar-username { font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn-logout { color: var(--ip-grey); font-size: 13px; border: 1px solid var(--ip-border); padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
.btn-logout:hover { background: var(--ip-blue-light); }

/* ---------------- Layout ---------------- */
.main-container { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }
.main-narrow { max-width: 800px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 24px; margin: 0; }

/* ---------------- Buttons ---------------- */
.btn-primary {
    background: var(--ip-blue); color: #fff; border: none; padding: 10px 20px;
    border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; display: inline-block;
}
.btn-primary:hover { background: var(--ip-blue-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
    background: #fff; color: var(--ip-blue); border: 1px solid var(--ip-blue); padding: 9px 18px;
    border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; display: inline-block;
}
.btn-secondary:hover { background: var(--ip-blue-light); }
.btn-link { color: var(--ip-blue); font-weight: 600; font-size: 13px; }
.btn-block { width: 100%; text-align: center; }

/* ---------------- Auth page ---------------- */
.auth-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-card {
    background: #fff; border-radius: 16px; box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    padding: 48px 40px; width: 380px; text-align: center;
}
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.auth-logo-mark {
    width: 40px; height: 40px; border-radius: 10px; background: var(--ip-blue); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.auth-logo h1 { font-size: 22px; margin: 0; }
.auth-logo h1 span { color: var(--ip-blue); }
.auth-tagline { color: var(--ip-grey); margin-bottom: 28px; }
.btn-google {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    border: 1px solid var(--ip-border); border-radius: 8px; padding: 12px; font-weight: 600;
    color: var(--ip-text); background: #fff;
}
.btn-google:hover { background: #F9FAFB; }
.auth-footnote { font-size: 12px; color: var(--ip-grey); margin-top: 24px; }
.auth-error { background: #FDECEA; color: var(--ip-red); padding: 10px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }

/* ---------------- Tables / badges ---------------- */
.doc-table-wrap { background: #fff; border-radius: 10px; border: 1px solid var(--ip-border); overflow: hidden; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th, .doc-table td { padding: 12px 16px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--ip-border); }
.doc-table th { color: var(--ip-grey); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.doc-title-cell { font-weight: 600; }
.doc-icon { margin-right: 6px; }
.page-header .doc-actions { display: flex; gap: 10px; }
.badge { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-grey { background: #F3F4F6; color: var(--ip-grey); }
.badge-blue { background: var(--ip-blue-light); color: var(--ip-blue); }
.badge-green { background: #E8F8F3; color: var(--ip-green); }
.badge-red { background: #FDECEA; color: var(--ip-red); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--ip-grey); background: #fff; border-radius: 10px; border: 1px dashed var(--ip-border); }

/* ---------------- Upload ---------------- */
.form-label { display: block; font-weight: 600; font-size: 13px; margin: 16px 0 6px; }
.form-input { width: 100%; padding: 10px 12px; border: 1px solid var(--ip-border); border-radius: 8px; font-size: 14px; font-family: inherit; }
.upload-form { background: #fff; padding: 24px; border-radius: 10px; border: 1px solid var(--ip-border); }
.dropzone { border: 2px dashed var(--ip-border); border-radius: 10px; padding: 30px; text-align: center; cursor: pointer; margin-top: 4px; }
.dropzone-active { border-color: var(--ip-blue); background: var(--ip-blue-light); }
.dropzone input[type=file] { display: none; }
.dropzone-icon { font-size: 32px; }
.dropzone-hint { font-size: 12px; color: var(--ip-grey); }
.alert-error { background: #FDECEA; color: var(--ip-red); padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }

/* ---------------- Editor layout ---------------- */
.editor-body { overflow-x: hidden; }
.editor-layout { display: flex; height: calc(100vh - 61px); }
.editor-panel {
    width: 280px; background: #fff; border-right: 1px solid var(--ip-border);
    padding: 20px; overflow-y: auto; flex-shrink: 0;
}
.editor-panel h3 { margin: 0 0 6px; font-size: 15px; }
.panel-hint { font-size: 12px; color: var(--ip-grey); margin: 0 0 14px; }
.panel-empty { font-size: 13px; color: var(--ip-grey); text-align: center; padding: 20px; }

.recipient-list { margin-bottom: 12px; }
.recipient-row {
    display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer;
    border: 1px solid transparent; margin-bottom: 6px;
}
.recipient-row:hover { background: #F9FAFB; }
.recipient-row-active { border-color: var(--ip-blue); background: var(--ip-blue-light); }
.recipient-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.recipient-info { flex: 1; min-width: 0; }
.recipient-name { font-weight: 600; font-size: 13px; }
.recipient-email { font-size: 11px; color: var(--ip-grey); overflow: hidden; text-overflow: ellipsis; }
.recipient-remove { border: none; background: none; color: var(--ip-grey); font-size: 18px; cursor: pointer; line-height: 1; }
.recipient-remove:hover { color: var(--ip-red); }
.recipient-add-form { display: flex; flex-direction: column; gap: 8px; }
.recipient-add-form input { padding: 8px 10px; border: 1px solid var(--ip-border); border-radius: 6px; font-size: 13px; }

.field-palette { display: flex; flex-direction: column; gap: 8px; }
.field-chip {
    background: #F9FAFB; border: 1px solid var(--ip-border); border-radius: 8px; padding: 10px 12px;
    font-size: 13px; font-weight: 600; cursor: grab; user-select: none;
}
.field-chip:active { cursor: grabbing; }

hr { border: none; border-top: 1px solid var(--ip-border); margin: 20px 0; }

.editor-canvas-wrap { flex: 1; overflow-y: auto; background: #EFF2F5; }
.editor-toolbar {
    display: flex; align-items: center; justify-content: space-between; background: #fff;
    border-bottom: 1px solid var(--ip-border); padding: 12px 24px; position: sticky; top: 0; z-index: 10;
}
.editor-doc-title { font-weight: 600; }
.editor-toolbar-actions { display: flex; align-items: center; gap: 14px; }
.save-status { font-size: 12px; color: var(--ip-grey); }

.pdf-pages { padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.pdf-page-wrap { position: relative; box-shadow: 0 2px 10px rgba(0,0,0,0.12); background: #fff; }
.fields-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

.field-box {
    position: absolute; border: 2px solid; border-radius: 4px; box-sizing: border-box;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.field-box-label {
    position: absolute; top: -20px; left: -2px; color: #fff; font-size: 10px; font-weight: 600;
    padding: 2px 6px; border-radius: 4px 4px 0 0; white-space: nowrap;
}
.field-box-delete {
    position: absolute; top: -8px; right: -8px; width: 18px; height: 18px; border-radius: 50%;
    background: var(--ip-red); color: #fff; border: none; font-size: 13px; line-height: 1; cursor: pointer;
}
.field-box-resize {
    position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; cursor: nwse-resize;
    background: rgba(0,0,0,0.25); border-radius: 0 0 3px 0;
}
.field-box-mine { cursor: pointer; }
.field-box-readonly { opacity: 0.65; }
.field-box-value { font-size: 11px; text-align: center; width: 100%; padding: 2px; overflow: hidden; }
.field-box-filled { border-style: solid; }

/* ---------------- Modal ---------------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center;
    justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal-box { background: #fff; border-radius: 12px; padding: 24px; width: 420px; max-width: 90vw; }
.modal-box h3 { margin: 0 0 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------------- Toggle switch (notification prefs, etc.) ---------------- */
.notif-pref-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track { position: absolute; cursor: pointer; inset: 0; background: #D1D5DB; border-radius: 22px; transition: background 0.15s; }
.switch-track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--ip-blue); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }

/* ---------------- Status page ---------------- */
.status-card { background: #fff; border: 1px solid var(--ip-border); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.status-card h3 { margin-top: 0; }
.audit-list { list-style: none; padding: 0; margin: 0; }
.audit-list li { padding: 8px 0; border-bottom: 1px solid var(--ip-border); font-size: 13px; display: flex; gap: 16px; }
.audit-list li:last-child { border-bottom: none; }
.audit-time { color: var(--ip-grey); flex-shrink: 0; width: 160px; }
