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

:root {
  --primary-color: #105b87;
  --secondary-color: #033f7f;
  --bg-color: #f4f7f6;
  --panel-bg: #ffffff;
  --text-dark: #333333;
  --text-light: #616161;
  --border-color: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 15px rgba(0,0,0,0.15);
  
  --topbar-height: 60px;
  --sidebar-w: 260px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-dark);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

/* ================== LOGIN PAGE ================== */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.login-card {
  background-color: var(--panel-bg);
  padding: 40px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  text-align: center;
  animation: slideUp 0.6s ease-out forwards;
}

.login-card h1 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--primary-color);
}

.login-card p {
  color: var(--text-light);
  margin-bottom: 24px;
  font-size: 13px;
}

.login-form input {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  transition: all 0.3s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(16, 91, 135, 0.1);
}

.login-btn {
  width: 100%;
  padding: 10px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.1s;
}

.login-btn:hover {
  background-color: var(--secondary-color);
}

.login-btn:active {
  transform: translateY(1px);
}

.error-msg {
  color: #dc3545;
  font-size: 12px;
  margin-bottom: 16px;
  font-weight: 500;
  background: #f8d7da;
  padding: 8px;
  border-radius: 6px;
}

/* ================== CRM APP LAYOUT ================== */

#app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--topbar-height));
}

/* --- Topbar --- */
#topbar {
  height: var(--topbar-height);
  background-color: var(--panel-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary-color);
  padding: 8px;
  border-radius: 8px;
  transition: background 0.3s;
}

.menu-toggle:hover {
  background-color: rgba(16, 91, 135, 0.05);
}

.logo-container {
    height: 36px;
}

.logo-container img {
  height: 100%;
  object-fit: contain;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.user-avatar {
  background-color: var(--primary-color);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
}

.user-name {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-dark);
}

/* --- Sidebar Left --- */
#sidebar-left {
  width: var(--sidebar-w);
  background-color: var(--panel-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 50;
  overflow-y: auto;
}

#sidebar-left.collapsed {
  transform: translateX(-100%);
  position: absolute;
  height: 100%;
}

.nav-menu {
  list-style: none;
  padding: 10px 0;
}

.nav-item {
  padding: 0 10px;
  margin-bottom: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--text-light);
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
  background-color: rgba(16, 91, 135, 0.08);
  color: var(--primary-color);
}

.nav-link svg, .nav-link img {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  object-fit: contain;
}

/* --- Tree View Support --- */
.has-submenu .submenu {
  display: none;
  overflow: hidden;
}
.has-submenu.open > .submenu {
  display: block;
}
.has-submenu.open > .folder-toggle .chevron {
  transform: rotate(180deg);
}

/* --- Central Content (IFrame) --- */
/* --- Resizer Handles --- */
.sidebar-resizer {
  width: 5px;
  background-color: transparent;
  cursor: col-resize;
  z-index: 100;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.sidebar-resizer:hover, .sidebar-resizer.dragging {
  background-color: var(--primary-color);
  width: 5px;
  box-shadow: 0 0 5px rgba(16, 91, 135, 0.3);
}

#main-content {
  flex: 1;
  background-color: var(--bg-color);
  position: relative;
  overflow: hidden;
  /* Rimuovo la transizione margin-left per evitare lag durante il resize */
  transition: none; 
}

#central-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* --- Sidebar Right --- */
#sidebar-right {
  width: 300px;
  background-color: var(--panel-bg);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
  box-shadow: -2px 0 10px rgba(0,0,0,0.02);
  overflow: hidden;
}

#sidebar-right.collapsed {
  width: 0;
  transform: translateX(100%);
  border: none;
}

.sidebar-right-header {
  padding: 15px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.utility-tabs {
  display: flex;
  background: var(--bg-color);
  padding: 4px;
  border-radius: 8px;
  gap: 4px;
}

.u-tab {
  flex: 1;
  padding: 6px;
  text-align: center;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.u-tab.active {
  background: white;
  color: var(--primary-color);
  box-shadow: var(--shadow-sm);
}

.sidebar-right-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.utility-section {
  display: none;
  flex: 1;
  flex-direction: column;
}

.utility-section.active {
  display: flex;
}

/* --- Notification System Styling --- */
.notification-list {
  display: flex;
  flex-direction: column;
}

.notification-card {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.2s;
  cursor: pointer;
}

.notification-card:hover {
  background-color: rgba(16, 91, 135, 0.02);
}

.notif-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.notif-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-dark);
}

.notif-time {
  font-size: 11px;
  color: var(--text-light);
}

.notif-body {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-light);
}

.notif-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    margin-right: 6px;
}
.notif-badge-call { background: #e3f2fd; color: #1e88e5; }
.notif-badge-alert { background: #ffebee; color: #e53935; }

/* --- Phone IFrame Container --- */
#phone-container {
  width: 100%;
  height: 100%;
  border: none;
}

/* Animations */
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Animations */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Socket Status Indicator */
.socket-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #dc3545;
  display: inline-block;
  margin-left: 8px;
}
.socket-indicator.connected {
  background-color: #28a745;
  box-shadow: 0 0 6px #28a745;
}

/* --- Multi-Tab Viewport System --- */
#viewport-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
}

.app-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  background: white;
}

.app-frame.active {
  display: block;
}

#empty-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

/* --- Apps Sidebar List --- */
.apps-sidebar-header {
  padding: 15px 20px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-light);
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border-color);
}

.apps-list {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.app-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.app-item:hover {
  background: rgba(16, 91, 135, 0.04);
}

.app-item.active {
  background: rgba(16, 91, 135, 0.08);
  border-left: 3px solid var(--primary-color);
}

.app-item-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.app-item-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-light);
  font-size: 18px;
  transition: all 0.2s;
}

.app-item-close:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}
