:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #10b981;
    --input-bg: rgba(15, 23, 42, 0.6);
}

[data-theme="light"] {
    --bg-color: #f8fafc;
    --panel-bg: rgba(255, 255, 255, 0.7);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --input-bg: rgba(255, 255, 255, 0.8);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    padding-bottom: 300px; /* Force scrollability */
}

html {
    scroll-behavior: smooth;
}

.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
}

.screen {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

/* Login Screen */
#login-screen {
    text-align: center;
    padding-top: 50px; 
    padding-bottom: 200px;
}

.login-container {
    width: 100%;
    max-width: 350px;
    margin: 0 auto;
    text-align: center;
    padding: 30px 20px;
}

.logo {
    font-size: 48px;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.login-container h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 5px;
}

.login-container p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 30px;
}

.input-group {
    position: relative;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0 15px;
}

.input-group ion-icon {
    color: var(--text-secondary);
    font-size: 20px;
}

.input-group input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    padding: 15px 10px;
    outline: none;
    font-size: 16px;
}

.btn-primary {
    width: 100%;
    padding: 15px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.error-msg {
    color: var(--danger);
    font-size: 14px;
    margin-top: 15px;
}

/* App Header */
.glass-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    margin-bottom: 20px;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
}

/* Search Bar */
.search-bar {
    padding: 15px;
    margin-bottom: 20px;
}

.input-row {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0 10px;
    margin-bottom: 10px;
}

.input-row ion-icon {
    color: var(--text-secondary);
}

.input-row input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    padding: 12px 10px;
    outline: none;
}

.filter-row {
    display: flex;
    gap: 10px;
}

.filter-row select {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    outline: none;
}

.btn-secondary {
    padding: 12px 20px;
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
}

/* Firm List */
.firm-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 100px;
}

.firm-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
}

.firm-card h3 {
    font-size: 16px;
    margin-bottom: 5px;
}

.firm-card p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 3px;
}

.card-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

.action-btn.add-btn { color: var(--success); }
.action-btn.remove-btn { color: var(--danger); }

/* Floating Cart */
.floating-cart {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    max-width: 560px;
    margin: 0 auto;
    padding: 15px;
    z-index: 100;
}

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mt-2 { margin-top: 15px; }
.w-100 { width: 100%; }

.cart-items {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 15px;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}
.cart-item:last-child { border-bottom: none; }

/* Modal */
@keyframes overlay-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes modal-pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(8px) saturate(140%);
    -webkit-backdrop-filter: blur(8px) saturate(140%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    padding: 16px;
    animation: overlay-fade-in 0.2s ease-out;
}

.modal {
    width: 90%;
    max-width: 400px;
    padding: 20px;
    animation: modal-pop-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.glass-panel {
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.text-sm {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 10px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}
.modal-actions button { flex: 1; }

/* PC Desktop Center Fix for Login Screen */
@media (min-width: 768px) {
    #login-screen {
        display: flex;
        align-items: center;
        justify-content: center;
        padding-top: 0;
        padding-bottom: 0;
        min-height: 100vh;
    }
}

@keyframes crm-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.crm-modal.is-loading .crm-body {
    position: relative;
    pointer-events: none;
    opacity: 0.55;
}
.crm-modal.is-loading .crm-body::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(59,130,246,0.08) 45%,
        rgba(59,130,246,0.18) 50%,
        rgba(59,130,246,0.08) 55%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: crm-shimmer 1.4s linear infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
@keyframes accordion-reveal {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.crm-modal {
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    padding: 0;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(140% 100% at 0% 0%, rgba(59, 130, 246, 0.12), transparent 55%),
        radial-gradient(120% 100% at 100% 0%, rgba(16, 185, 129, 0.08), transparent 60%),
        var(--panel-bg);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.45),
        0 1px 0 rgba(255, 255, 255, 0.05) inset;
    overflow: hidden;
}

.crm-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}
.crm-modal-head::after {
    content: '';
    position: absolute;
    left: 22px; right: 22px; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59,130,246,0.45), transparent);
}

.crm-modal-head h3 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: linear-gradient(90deg, var(--text-primary), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.01em;
}

.crm-modal-head .btn-icon {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: background 0.15s ease, transform 0.15s ease;
    font-size: 22px;
}
.crm-modal-head .btn-icon:hover {
    background: rgba(255,255,255,0.08);
    transform: rotate(90deg);
}

.crm-tabs {
    display: flex;
    gap: 6px;
    padding: 14px 22px 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.crm-tabs::-webkit-scrollbar { display: none; }

.crm-tab {
    flex: 1 0 auto;
    min-width: 110px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    background: rgba(255,255,255,0.03);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.18s ease;
    white-space: nowrap;
}
.crm-tab:hover:not(.is-active) {
    color: var(--text-primary);
    border-color: rgba(59,130,246,0.4);
    background: rgba(59,130,246,0.08);
}
.crm-tab.is-active {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #fff;
    border-color: transparent;
    box-shadow:
        0 6px 16px rgba(59,130,246,0.35),
        0 1px 0 rgba(255,255,255,0.2) inset;
}
.crm-tab ion-icon { font-size: 16px; }

.crm-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 22px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148,163,184,0.3) transparent;
}
.crm-body::-webkit-scrollbar { width: 8px; }
.crm-body::-webkit-scrollbar-thumb {
    background: rgba(148,163,184,0.25);
    border-radius: 999px;
}
.crm-body::-webkit-scrollbar-thumb:hover { background: rgba(148,163,184,0.45); }

/* Contact accordion card */
.crm-contact {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    margin-bottom: 12px;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.crm-contact:hover { border-color: rgba(59,130,246,0.35); }
.crm-contact.is-open {
    border-color: rgba(59,130,246,0.55);
    box-shadow:
        0 10px 30px rgba(0,0,0,0.18),
        0 0 0 3px rgba(59,130,246,0.08);
}

.crm-contact-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}
.crm-contact-head:hover { background: rgba(255,255,255,0.025); }

.crm-contact-num {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(59,130,246,0.18), rgba(59,130,246,0.08));
    border: 1px solid rgba(59,130,246,0.25);
    color: var(--primary-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.crm-contact.is-open .crm-contact-num {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(59,130,246,0.45);
}
.crm-contact.is-filled:not(.is-open) .crm-contact-num {
    background: linear-gradient(135deg, rgba(16,185,129,0.18), rgba(16,185,129,0.08));
    border-color: rgba(16,185,129,0.3);
    color: var(--success);
}

.crm-contact-title {
    flex: 1;
    min-width: 0;
}
.crm-contact-title .label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 2px;
    font-weight: 500;
}
.crm-contact-title .name {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crm-contact-title .name.empty {
    color: var(--text-secondary);
    font-style: italic;
    font-weight: 400;
    opacity: 0.7;
}

.crm-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    opacity: 0.35;
    flex-shrink: 0;
    transition: background 0.2s ease, opacity 0.2s ease;
}
.crm-contact.is-filled .crm-status-dot {
    background: var(--success);
    opacity: 1;
    animation: pulse-dot 2.4s ease-out infinite;
}

.crm-contact-chevron {
    color: var(--text-secondary);
    font-size: 18px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease;
    flex-shrink: 0;
}
.crm-contact.is-open .crm-contact-chevron {
    transform: rotate(180deg);
    color: var(--primary-color);
}

.crm-contact-body {
    display: none;
    padding: 0 16px 16px;
    border-top: 1px solid var(--border-color);
    background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent);
}
.crm-contact.is-open .crm-contact-body {
    display: block;
    padding-top: 16px;
    animation: accordion-reveal 0.22s ease-out;
}

.crm-field-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 480px) {
    .crm-field-grid.cols-2 { grid-template-columns: 1fr 1fr; }
}

.crm-field { display: flex; flex-direction: column; gap: 6px; }
.crm-field > label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    padding-left: 4px;
    letter-spacing: 0.2px;
}

.crm-field-control {
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0 12px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.crm-field-control:hover { border-color: rgba(148,163,184,0.4); }
.crm-field-control:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.18);
    background: var(--input-bg);
}
.crm-field-control ion-icon {
    color: var(--text-secondary);
    font-size: 17px;
    flex-shrink: 0;
    transition: color 0.18s ease;
}
.crm-field-control:focus-within ion-icon { color: var(--primary-color); }

.crm-field-control input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    padding: 12px 10px;
    min-width: 0;
    font-weight: 500;
    letter-spacing: 0.1px;
}
.crm-field-control input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
    font-weight: 400;
}
.crm-field-control input[readonly] { cursor: default; }

.crm-field-quick {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
    text-decoration: none;
    flex-shrink: 0;
}
.crm-field-quick:hover {
    background: rgba(59,130,246,0.15);
    transform: scale(1.05);
}
.crm-field-quick ion-icon { color: var(--primary-color); font-size: 18px; }
.crm-modal.is-readonly .crm-field-quick.has-value { display: inline-flex; }

.crm-footer-inline {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px dashed var(--border-color);
}
.crm-footer-inline button {
    flex: 1;
    padding: 12px;
    font-size: 14px;
    border-radius: 10px;
    transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.crm-footer-inline .btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    box-shadow: 0 6px 16px rgba(59,130,246,0.3);
}
.crm-footer-inline .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(59,130,246,0.4); }
.crm-footer-inline .btn-secondary {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.crm-footer-inline .btn-secondary:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

[data-theme="light"] .crm-modal {
    background:
        radial-gradient(140% 100% at 0% 0%, rgba(59,130,246,0.08), transparent 55%),
        radial-gradient(120% 100% at 100% 0%, rgba(16,185,129,0.05), transparent 60%),
        var(--panel-bg);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}
[data-theme="light"] .crm-tab { background: rgba(0,0,0,0.02); }
[data-theme="light"] .crm-contact-head:hover { background: rgba(0,0,0,0.03); }
[data-theme="light"] .crm-modal-head .btn-icon:hover { background: rgba(0,0,0,0.05); }

@media (max-width: 480px) {
    .crm-modal {
        max-width: 100%;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    .crm-modal-head { padding: 14px 16px; }
    .crm-modal-head::after { left: 16px; right: 16px; }
    .crm-tabs { padding: 12px 16px 0; }
    .crm-body { padding: 16px 16px 12px; }
    .crm-tab { min-width: 96px; padding: 9px 12px; font-size: 12px; }
}
