/* Copyright 2024 The Chromium Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file. */

/* #css_wrapper_metadata_start
 * #type=style-lit
 * #import=//resources/cr_elements/cr_shared_vars.css.js
 * #import=//resources/cr_elements/cr_hidden_style_lit.css.js
 * #import=//resources/cr_elements/cr_icons_lit.css.js
 * #scheme=relative
 * #include=cr-hidden-style-lit cr-icons-lit
 * #css_wrapper_metadata_end */

:host {
  --cr-tooltip-icon-fill-color: var(--cr-fallback-color-on-surface-subtle);
  --icon-button-color-active: var(--google-grey-700);
  --icon-button-color: var(--google-grey-600);
  --icon-size: var(--most-visited-icon-size, 48px);
  --managed-tile-background-color: var(--cr-fallback-color-neutral-container);
  --tile-background-color: rgb(229, 231, 232);
  --tile-hover-color: rgba(var(--google-grey-900-rgb), .1);
  --tile-size: var(--most-visited-tile-size, 112px);
  --title-height: var(--most-visited-title-height, 32px);
}

@media (prefers-color-scheme: dark) {
  :host {
    --tile-background-color: var(--google-grey-100);
  }
}

:host([is-dark_]) {
  --icon-button-color-active: var(--google-grey-300);
  --icon-button-color: white;
  --tile-hover-color: rgba(255, 255, 255, .1);
}

#container {
  --content-width: calc(
      var(--column-count) * var(--tile-size) +
      max(0, var(--column-count) - 1) * var(--most-visited-gap, 0px)
      /* We add an extra pixel because rounding errors on different zooms can
       * make the width shorter than it should be. */
      + 1px);
  column-gap: var(--most-visited-gap, 0);
  display: flex;
  flex-wrap: wrap;
  height: calc(var(--row-count) * var(--tile-size));
  justify-content: center;
  margin-bottom: 8px;
  opacity: 0;
  overflow: hidden;
  padding: 2px;  /* Padding added so focus rings are not clipped. */
  transition: opacity 300ms ease-in-out;
  width: calc(var(--content-width) + 12px);
}

:host([visible_]) #container {
  opacity: 1;
}

#addShortcutIcon,
#showMoreIcon,
#showLessIcon,
.query-tile-icon {
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: 100%;
  height: 24px;
  width: 24px;
}

.tile-icon-container {
  background-color:
      var(--add-shortcut-background-color, var(--tile-background-color));
  margin-inline-start: auto;
  margin-inline-end: auto;
}

#addShortcutIcon {
  -webkit-mask-image: url(chrome://resources/images/add_old.svg);
  background-color:
      var(--add-shortcut-foreground-color, var(--google-grey-900));
}

#showMoreIcon {
  -webkit-mask-image: url(chrome://resources/cr_components/most_visited/expand_content_old.svg);
  background-color:
      var(--add-shortcut-foreground-color, var(--google-grey-900));
}

#showLessIcon {
  -webkit-mask-image: url(chrome://resources/cr_components/most_visited/collapse_content_old.svg);
  background-color:
      var(--add-shortcut-foreground-color, var(--google-grey-900));
}

.query-tile-icon {
  -webkit-mask-image: url(chrome://resources/images/icon_search.svg);
  background-color: var(--google-grey-700);
}

@media (forced-colors: active) {
  #addShortcutIcon,
  #showMoreIcon,
  #showLessIcon,
  .query-tile-icon {
    background-color: ButtonText;
  }
}

:host([use-white-tile-icon_]) #addShortcutIcon,
:host([use-white-tile-icon_]) #showMoreIcon,
:host([use-white-tile-icon_]) #showLessIcon {
  background-color: white;
}

:host([use-white-tile-icon_]) .query-tile-icon {
  background-color: var(--google-grey-400);
}

.tile,
#addShortcut,
#showMore,
#showLess {
  -webkit-tap-highlight-color: transparent;
  align-items: center;
  border-radius: 4px;
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  height: var(--tile-size);
  opacity: 1;
  outline: none;
  position: relative;
  text-decoration: none;
  transition-duration: 300ms;
  transition-property: left, top;
  transition-timing-function: ease-in-out;
  user-select: none;
  width: var(--tile-size);
}

.tile a {
  border-radius: 4px;
  display: inline-block;
  height: 100%;
  outline: none;
  position: absolute;
  touch-action: none;
  width: 100%;
}

:host-context(.focus-outline-visible) .tile a:focus,
:host-context(.focus-outline-visible) #addShortcut:focus,
:host-context(.focus-outline-visible) #showMore:focus,
:host-context(.focus-outline-visible) #showLess:focus {
  box-shadow: var(--most-visited-focus-shadow);
}

@media (forced-colors: active) {
  :host-context(.focus-outline-visible) .tile a:focus,
  :host-context(.focus-outline-visible) #addShortcut:focus,
  :host-context(.focus-outline-visible) #showMore:focus,
  :host-context(.focus-outline-visible) #showLess:focus {
    /* Use outline instead of box-shadow (which does not work) in Windows
        HCM. */
    outline: var(--cr-focus-outline-hcm);
  }
}

#addShortcut,
#showMore,
#showLess {
  --cr-hover-background-color: transparent;
  background-color: transparent;
  border: none;
  box-shadow: none;
  justify-content: unset;
  padding: 0;
}

:host(:not([reordering_])) .tile:hover,
:host(:not([reordering_])) #addShortcut:hover,
:host(:not([reordering_])) #showMore:hover,
:host(:not([reordering_])) #showLess:hover,
.force-hover {
  background-color: var(--tile-hover-color);
}

.tile-icon {
  align-items: center;
  background-color: var(--tile-background-color);
  border-radius: 50%;
  display: flex;
  flex-shrink: 0;
  height: var(--icon-size);
  justify-content: center;
  margin-top: var(--most-visited-icon-margin-top, 16px);
  width: var(--icon-size);
}

.tile-icon img {
  height: 24px;
  width: 24px;
}

.managed-tile-icon {
  align-items: center;
  background-color: var(--managed-tile-background-color);
  border-radius: 50%;
  display: flex;
  flex-shrink: 0;
  height: 24px;
  justify-content: center;
  left: 68px;
  position: absolute;
  top: 40px;
  width: 24px;
}

cr-policy-indicator {
  --cr-icon-size: 16px;
}

.tile-title {
  align-items: center;
  border-radius: calc(var(--title-height) / 2 + 2px);
  color: var(--most-visited-text-color);
  display: flex;
  height: var(--title-height);
  line-height: calc(var(--title-height) / 2);
  margin-top: 6px;
  padding: 2px 8px;
  max-width: calc(var(--tile-size) - 10px);
}

.tile-title span {
  font-weight: 400;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  text-shadow: var(--most-visited-text-shadow);
  white-space: nowrap;
  width: 100%;
}

.tile[query-tile] .tile-title span {
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  display: -webkit-box;
  white-space: initial;
}

.title-rtl {
  direction: rtl;
}

.title-ltr {
  direction: ltr;
}

:host([hide-title]) #container {
  margin-bottom: 0;
  padding: 0;
  width: var(--content-width);
}

:host([hide-title]) .tile-title {
  display: none;
}

:host([hide-title]) .tile,
:host([hide-title]) #addShortcut,
:host([hide-title]) #showMore,
:host([hide-title]) #showLess {
  justify-content: center;
}

:host([hide-title]) .tile-icon {
  margin: 0;
}

.tile.dragging {
  background-color: var(--tile-hover-color);
  transition-property: none;
  z-index: 2;
}

cr-icon-button {
  --cr-icon-button-fill-color: var(--icon-button-color);
  --cr-icon-button-size: 28px;
  --cr-icon-button-transition: none;
  margin: 4px 2px;
  opacity: 0;
  position: absolute;
  right: 0;
  top: 0;
  transition: opacity 100ms ease-in-out;
}

:host-context([dir=rtl]) cr-icon-button {
  left: 0;
  right: unset;
}

:host(:not([reordering_])) .tile:hover cr-icon-button,
.force-hover cr-icon-button {
  opacity: 1;
  transition-delay: 400ms;
}

:host(:not([reordering_])) cr-icon-button:active,
:host-context(.focus-outline-visible):host(:not([reordering_]))
    cr-icon-button:focus,
:host(:not([reordering_])) cr-icon-button:hover {
  --cr-icon-button-fill-color: var(--icon-button-color-active);
  opacity: 1;
  transition-delay: 0s;
}

#dialogContent {
  height: 160px;
}

/* When the policy subtitle is visible, the dialog content needs to be
 * taller to fit it. The extra 36px accounts for the subtitle's content
 * (~20px) and its bottom margin (16px). */
#dialogContent:has(#policySubtitleContainer:not([hidden])) {
  height: 196px;
}

#policySubtitleContainer {
  --iron-icon-height: 20px;
  --iron-icon-width: 20px;
  gap: 10px;
  display: flex;
  margin-bottom: 16px;
}

cr-toast-manager {
  --cr-toast-white-space: normal;
}

:host-context([webui-rounded-icons]) #addShortcutIcon {
  -webkit-mask-image: url(chrome://resources/images/add.svg);
}

:host-context([webui-rounded-icons]) #showMoreIcon {
  -webkit-mask-image: url(chrome://resources/cr_components/most_visited/expand_content.svg);
}

:host-context([webui-rounded-icons]) #showLessIcon {
  -webkit-mask-image: url(chrome://resources/cr_components/most_visited/collapse_content.svg);
}
